Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Deconstruct & Reconstruct resource groups
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Feb 12, 2015
1 parent 00f3c43 commit 0f944f0
Show file tree
Hide file tree
Showing 3 changed files with 1,773 additions and 1,166 deletions.
24 changes: 24 additions & 0 deletions src/drafter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ class Drafter
rules = (require './rules/' + rule for rule in ruleList)

@dataStructures = {}
delete result.ast.resourceGroups

@expandNode result.ast, rules, 'blueprint'
@reconstructResourceGroups result.ast

callback error, result

# Expand a certain node with the given rules
Expand Down Expand Up @@ -95,5 +98,26 @@ class Drafter
if node.content and Array.isArray node.content
@expandNode element, rules for element in node.content

# Reconstruct deprecated resource groups key from elements
#
# @param ast [Object] Blueprint ast
reconstructResourceGroups: (ast) ->
ast.resourceGroups = []

for element in ast.content
if element.element is 'category'
resources = []

for subElement in element.content
resources.push subElement if subElement.element is 'resource'

if resources.length
description = element.content[0].content if element.content[0].element is 'copy'

ast.resourceGroups.push
name: element.attributes?.name || ''
description: description || ''
resources: resources

module.exports = Drafter
module.exports.options = options
1 change: 1 addition & 0 deletions test/fixtures/dataStructures.apib
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ FORMAT: 1A
Inspired by stripe API

# Group Coupons
Resource group description

## Coupon [/coupons/{id}]
A coupon contains information about a percent-off or amount-off discount you might want to apply to a customer.
Expand Down
Loading

0 comments on commit 0f944f0

Please sign in to comment.