Skip to content
This repository has been archived by the owner on Jun 25, 2019. It is now read-only.

Commit

Permalink
fix(mson): Use id for data structures title
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Jan 24, 2017
1 parent 7d633d8 commit a12eff8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const env = nunjucks.configure(path.dirname(__dirname), {
autoescape: false,
});

env.addFilter('mson', mson);
env.addFilter('mson', mson.renderAttributes);
env.addFilter('dataStructure', mson.renderDataStructure);
env.addFilter('indent', indent);
env.addFilter('bodyOnly', bodyOnly);
env.addFilter('resourceShorthand', resourceShorthand);
Expand Down
28 changes: 19 additions & 9 deletions src/mson.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function handle(name, element, {parent = null, spaces = 4, marker = '+',
}

// Next, comes the optional example value
if (typeof element.content !== 'object') {
if (element.content && typeof element.content !== 'object') {
if (parent && parent.element !== 'array') {
str += ':';
}
Expand Down Expand Up @@ -202,13 +202,23 @@ function handle(name, element, {parent = null, spaces = 4, marker = '+',
/*
* Render out a piece of MSON from refract element instances.
*/
export default function render(mson) {
// Render *either* ### Title or + Attributes as the base element to support
// both a data structures section and resource / payload attributes.
const title = mson.title;

return handle(title || 'Attributes', mson, {
initialMarker: title ? '###' : '+',
initialIndent: title ? false : true,
export function renderDataStructure(dataStructure) {
const mson = dataStructure.content[0];
const title = mson.id;

return handle(title, mson, {
initialMarker: '###',
initialIndent: false,
});
}

export function renderAttributes(dataStructure) {
const mson = dataStructure.content[0];

return handle('Attributes', mson, {
initialMarker: '+',
initialIndent: true,
});
}

export default {renderDataStructure, renderAttributes};
4 changes: 2 additions & 2 deletions template.nunjucks
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ FORMAT: 1A
{{ renderParameters(resource.hrefVariables) }}
{% endif %}
{% if resource.dataStructure %}
{{ resource.dataStructure.content|mson }}
{{ resource.dataStructure|mson }}
{% endif %}
{% for transition in resource.transitions.content %}
{{ renderTransition(transition, href) }}
Expand All @@ -151,7 +151,7 @@ FORMAT: 1A
## Data Structures

{% for dataStructure in dataStructures.content %}
{{ dataStructure.content|mson }}
{{ dataStructure|dataStructure }}
{% endfor %}
{% endmacro %}

Expand Down

0 comments on commit a12eff8

Please sign in to comment.