Skip to content

Commit

Permalink
Add task for compiling docs to json and then to html.
Browse files Browse the repository at this point in the history
  • Loading branch information
timrwood committed Jun 6, 2014
1 parent b8f0565 commit edbfbf3
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 169 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Expand Up @@ -7,5 +7,5 @@ module.exports = function(grunt) {


grunt.config('clean.default', 'build/*'); grunt.config('clean.default', 'build/*');


grunt.registerTask('default', ['clean', 'img', 'assemble', 'js', 'css']); grunt.registerTask('default', ['clean', 'img', 'html', 'js', 'css']);
}; };
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -7,6 +7,7 @@
"author": "Tim Wood <washwithcare@gmail.com> (http://timwoodcreates.com/)", "author": "Tim Wood <washwithcare@gmail.com> (http://timwoodcreates.com/)",
"devDependencies": { "devDependencies": {
"assemble": "^0.4.37", "assemble": "^0.4.37",
"assemble-yaml": "^0.2.1",
"async": "0.2.5", "async": "0.2.5",
"grunt": "^0.4.5", "grunt": "^0.4.5",
"grunt-autoprefixer": "^0.7.3", "grunt-autoprefixer": "^0.7.3",
Expand Down
41 changes: 40 additions & 1 deletion pages/moment/docs.hbs
Expand Up @@ -2,4 +2,43 @@
title : Docs title : Docs
layout : moment-base.hbs layout : moment-base.hbs
intro : Documentation intro : Documentation
--- ---

<nav class="subnav">
{{#each docs}}
<div class="section">
<a href='#/{{ slug }}/'>{{ title }}</a>
<div class="dropdown">
{{#each items }}
<a href="#/{{ slug }}/">{{ title }}</a>
{{/each}}
</div>
</div>
{{/each}}
</nav>

<div class="docs">
{{#each docs}}
<article class="section">
<a class="target" name="/{{ slug }}/"></a>
<h2><a href='#/{{ slug }}/'><span class="hash">#</span>{{ title }}</a></h2>
</article>
{{#each items }}
<article class="method">
<a class="target" name="/{{ slug }}/"></a>
<h3>
<a href='#/{{ slug }}/'><span class="hash">#</span>{{ title }}</a>
<span>{{ version }}</span>
</h3>
<div class="prose">
{{#if signature}}
<pre>{{ signature }}</pre>
{{/if}}
{{#markdown}}
{{{body}}}
{{/markdown}}
</div>
</article>
{{/each}}
{{/each}}
</div>
71 changes: 0 additions & 71 deletions source/data/docs.js

This file was deleted.

56 changes: 56 additions & 0 deletions tasks/docs.js
@@ -0,0 +1,56 @@
var path = require('path'),
yfm = require('assemble-yaml');

module.exports = function (grunt) {
grunt.registerTask('docs', function (root) {
if (root !== 'moment' && root !== 'moment-timezone') {
throw new Error("Missing project name.\n\nUse `grunt docs:moment` or `grunt docs:moment-timezone`");
}

var files = grunt.file.expand(path.join('docs', root, '**/*.md')),
groups = [],
cache = {};

files.forEach(function (file) {
var data = yfm.extract(file),
groupPath = path.basename(path.dirname(file)),
itemPath = path.basename(file, '.md'),
groupSlug = groupPath.replace(/^\d\d-/, ''),
itemSlug = itemPath.replace(/^\d\d-/, ''),
group = cache[groupSlug],
item = data.context;

if (!group) {
group = cache[groupSlug] = {
slug : groupSlug,
items : []
};
groups.push(group);
}

if (itemPath === '00-intro') {
group.title = item.title;
}

group.items.push(item);

item.body = data.content;
item.slug = groupSlug + '/' + itemSlug;
item.edit = 'https://github.com/moment/momentjs.com/blob/master/docs/' + groupPath + '/' + itemPath + '.md';
});

grunt.file.write('.temp/docs/' + root + '.json', JSON.stringify(groups, null, 4));
});



grunt.config('watch.docs-moment', {
files: ['docs/moment/**/*.md'],
tasks: ['docs:moment']
});

grunt.config('watch.docs-moment-timezone', {
files: ['docs/moment-timezone/**/*.md'],
tasks: ['docs:moment-timezone']
});
};
128 changes: 32 additions & 96 deletions tasks/html.js
@@ -1,93 +1,3 @@
// var fs = require('fs'),
// library = require('../source/data/library'),
// langs = require('../source/data/lang'),
// docs = require('../source/data/docs'),
// zones = require('../source/data/zones'),
// swig = require('swig'),
// moment = require("moment");
//
// swig.init({
// allowErrors: true,
// autoescape: true,
// cache: false,
// encoding: 'utf8',
// filters: {},
// root: filename(['source', 'templates']),
// tags: {},
// extensions: {},
// tzOffset: 0
// });
//
//
// function filename(fn) {
// fn.unshift(process.cwd());
// var output = fn.join('/');
// return output;
// }
//
// function main(grunt, cb) {
// var data = {
// library : library,
// core_docs : docs.core(),
// timezone_docs : docs.timezone(),
// zones : zones,
// langs : langs,
// cachebust : moment().format(),
// global : 'global',
// localhost : grunt.option('localhost') && process.cwd() || '',
// nav : function (path) {
// if (grunt.option('localhost')) {
// return process.cwd() + path + "/index.html";
// } else {
// return path + "/";
// }
// }
// };
// library.ready(function(){
// render(data, cb, grunt);
// });
// }
//
// function renderSingle(src, dst, data, cb, grunt) {
// var template = swig.compileFile(src),
// html = template.render(data);
//
// grunt.file.write(filename([dst]), html);
// console.log('Wrote', dst);
// cb();
// }
//
// function render(data, cb, grunt) {
// renderSingle('core-home.html', 'build/index.html', data, function(){
// renderSingle('core-test.html', 'build/test/index.html', data, function(){
// renderSingle('core-docs.html', 'build/docs/index.html', data, function(){
// renderSingle('timezone-home.html', 'build/timezone/index.html', data, function(){
// renderSingle('timezone-test.html', 'build/timezone/test/index.html', data, function(){
// renderSingle('timezone-data.html', 'build/timezone/data/index.html', data, function(){
// renderSingle('timezone-docs.html', 'build/timezone/docs/index.html', data, cb, grunt);
// }, grunt);
// }, grunt);
// }, grunt);
// }, grunt);
// }, grunt);
// }, grunt);
// }
//
// module.exports = function(grunt) {
// grunt.registerTask('html', 'Build HTML', function() {
// main(grunt, this.async());
// });
//
// grunt.config('watch.html', {
// files: [
// "source/**/*.md",
// "source/**/*.html",
// "source/**/*.json"
// ],
// tasks: ["html"]
// });
// };

var path = require('path'); var path = require('path');


function rename (dest, src) { function rename (dest, src) {
Expand All @@ -102,12 +12,15 @@ function rename (dest, src) {


module.exports = function(grunt) { module.exports = function(grunt) {
grunt.config('assemble', { grunt.config('assemble', {
options: { 'options' : {
layoutdir : 'pages/layout', layoutdir : 'pages/layout',
helpers : ['pages/helpers/**/*.js' ], helpers : ['pages/helpers/**/*.js' ],
marked : { sanitize: false } marked : { sanitize: false }
}, },
moment : { 'moment' : {
options : {
docs : grunt.file.readJSON('.temp/docs/moment.json')
},
files: [{ files: [{
expand : true, expand : true,
rename : rename, rename : rename,
Expand All @@ -116,7 +29,7 @@ module.exports = function(grunt) {
src : '**/*.{hbs,md}' src : '**/*.{hbs,md}'
}] }]
}, },
momentTimezone : { 'moment-timezone' : {
files: [{ files: [{
expand : true, expand : true,
rename : rename, rename : rename,
Expand All @@ -126,4 +39,27 @@ module.exports = function(grunt) {
}] }]
} }
}); });

grunt.registerTask('html', [
'docs:moment',
'docs:moment-timezone',
'assemble:moment',
'assemble:moment-timezone'
]);

grunt.config('watch.html-moment', {
files: [
'.temp/docs/moment.json',
'pages/**/*.{hbs,json,md}'
],
tasks: ['assemble:moment']
});

grunt.config('watch.html-moment-timezone', {
files: [
'.temp/docs/moment-timezone.json',
'pages/**/*.{hbs,json,md}'
],
tasks: ['assemble:moment-timezone']
});
}; };

0 comments on commit edbfbf3

Please sign in to comment.