Skip to content

Instantly share code, notes, and snippets.

@jamiebuilds
Created August 5, 2014 20:20
Show Gist options
  • Save jamiebuilds/4505100604a86fc8dbbd to your computer and use it in GitHub Desktop.
Save jamiebuilds/4505100604a86fc8dbbd to your computer and use it in GitHub Desktop.
var Handlebars = require('handlebars');
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
yaml: {
docs: {
files: [{
expand: true,
cwd: 'src',
src: ['**/*.yml'],
dest: 'tmp'
}]
}
},
jsonTemplates: {
docs: {
options: {
template: './template.hbs'
},
files: [{
expand: true,
cwd: 'tmp',
src: ['**/*.json'],
dest: 'dist',
ext: '.html'
}]
}
},
clean: ['tmp', 'dist']
});
grunt.registerMultiTask('jsonTemplates', function() {
var options = this.options();
var files = this.files;
var template = Handlebars.compile(grunt.file.read(options.template));
this.files.forEach(function(f) {
f.src.filter(function(filepath) {
return grunt.file.exists(filepath) && !grunt.file.isDir(filepath);
}).map(function(filepath) {
var json = grunt.file.readJSON(filepath);
grunt.file.write(f.dest, template(json));
});
});
});
grunt.registerTask('default', ['clean', 'yaml', 'jsonTemplates']);
};
{
"name": "test",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-yaml": "^0.4.1",
"handlebars": "^2.0.0-alpha.4",
"load-grunt-tasks": "^0.6.0",
"underscore": "^1.6.0"
}
}
<h1>Marionette.Region</h1>
<h4>Extends</h4>
<p>Marionette.Controller</p>
<h2>Methods</h2>
<h3>foo<small>public</small></h3>
<p>Here is the description of this method</p>
<h4>Params</h4>
<table>
<tbody>
<tr>
<th>bar</th>
<td>String</td>
</tr>
<tr>
<th>baz</th>
<td>Object,Function</td>
</tr>
</tbody>
</table>
<h4>Emits</h4>
<table>
<tbody>
<tr>
<th>foo</th>
<td>Here is the description of this event</td>
<td>foo,bar,baz</td>
</tr>
</tbody>
</table>
<ul>
<li>This Error when something is wrong</li>
</ul>
<h4>Returns</h4>
<p>Marionette.Region</p>
<pre>region.show(new View())
region.show(new View())
</pre>
{
"name": "Region",
"namespace": "Marionette",
"extend": "Marionette.Controller",
"methods": {
"foo": {
"api": "public",
"params": {
"bar": {
"types": [
"String"
]
},
"baz": {
"types": [
"Object",
"Function"
]
}
},
"throws": [
"This Error when something is wrong"
],
"emits": [
{
"name": "show",
"description": "Here is the description of this event",
"arguments": [
"foo",
"bar",
"baz"
]
}
],
"returns": "Marionette.Region",
"description": "Here is the description of this method",
"example": "region.show(new View())\nregion.show(new View())\n"
}
},
"properties": {
"foo": {
"description": "Here is the description of this property"
}
}
}
name: Region
namespace: Marionette
extend: Marionette.Controller
methods:
foo:
api: public
params:
bar:
types:
- String
baz:
types:
- Object
- Function
throws:
- This Error when something is wrong
emits:
-
name: show
description: Here is the description of this event
arguments:
- foo
- bar
- baz
returns: Marionette.Region
description: Here is the description of this method
example: |
region.show(new View())
region.show(new View())
properties:
foo:
description: Here is the description of this property
<h1>{{namespace}}.{{name}}</h1>
{{#if extend}}
<h4>Extends</h4>
<p>{{extend}}</p>
{{/if}}
{{#if methods}}
<h2>Methods</h2>
{{#each methods}}
<h3>{{@key}}<small>{{api}}</small></h3>
<p>{{description}}</p>
{{#if params}}
<h4>Params</h4>
<table>
<tbody>
{{#each params}}
<tr>
<th>{{@key}}</th>
<td>{{types}}</td>
</tr>
{{/each}}
</tbody>
</table>
{{/if}}
{{#if emits}}
<h4>Emits</h4>
<table>
<tbody>
{{#each emits}}
<tr>
<th>{{@key}}</th>
<td>{{description}}</td>
<td>{{arguments}}</td>
</tr>
{{/each}}
</tbody>
</table>
{{/if}}
{{#if throws}}
<ul>
{{#each throws}}
<li>{{.}}</li>
{{/each}}
</ul>
{{/if}}
{{#if returns}}
<h4>Returns</h4>
<p>{{returns}}</p>
{{/if}}
{{#if example}}
<pre>{{example}}</pre>
{{/if}}
{{/each}}
{{/if}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment