Skip to content

Commit c1686d0

Browse files
author
Shuwen Qian
committed
Examples working
1 parent 23e7f63 commit c1686d0

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

Gulpfile.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,32 @@ gulp.task('docs:templates', function() {
230230
}
231231

232232
// Ad-hoc plugin for injecting everything else
233-
function injectModuleMeta(pkg, moduleMap, articleList, articleMap) {
233+
function injectModuleData(pkg, moduleMap, articleList, articleMap) {
234234
return through.obj(function(file, enc, cb) {
235235
var moduleDoc = JSON.parse(file.contents);
236+
var examplePath = path.join(SRC, moduleDoc.name, 'example.html');
237+
var example;
238+
try {
239+
example = fs.readFileSync(examplePath).toString('utf8');
240+
} catch(e) {
241+
console.log('Missing example.html for '+moduleDoc.name);
242+
console.log(e);
243+
}
236244

237245
// Inject metadata
238246
moduleDoc.revision = pkg.version;
239247
moduleDoc.modules = moduleMap;
240248
moduleDoc.articleList = articleList;
241249
moduleDoc.articleMap = articleMap;
250+
if(example) moduleDoc.example = example;
242251

243252
file.contents = new Buffer(JSON.stringify(moduleDoc), enc);
244253
this.push(file);
245254
cb();
246255
});
247256
}
248257

249-
function injectArticleMeta(pkg, moduleMap, articleList, articleMap) {
258+
function injectArticleData(pkg, moduleMap, articleList, articleMap) {
250259
console.log(articleList);
251260
console.log(articleMap);
252261
return through.obj(function(file, enc, cb) {
@@ -336,10 +345,9 @@ gulp.task('docs:templates', function() {
336345

337346
var moduleStream = gulp.src(SRC+'mm-*/doc.json')
338347
.pipe(injectBehaviorDocs(behaviorsMap))
339-
.pipe(injectModuleMeta(pkg, moduleMap, articleList, articleMap))
348+
.pipe(injectModuleData(pkg, moduleMap, articleList, articleMap))
340349
// .pipe(debug())
341350
.pipe(through.obj(function(file, enc, cb) {
342-
// TODO: Put this in a closure
343351
var moduleDoc = JSON.parse(file.contents);
344352
var templatePath = path.join(__dirname,'docs/component_template.html');
345353
var templateString = fs.readFileSync(templatePath).toString('utf8');
@@ -360,7 +368,7 @@ gulp.task('docs:templates', function() {
360368
var articleStream = gulp.src('./docs/articles/*.md')
361369
// .pipe(debug())
362370
.pipe(marked().on('error',console.log))
363-
.pipe(injectArticleMeta(pkg, moduleMap, articleList, articleMap))
371+
.pipe(injectArticleData(pkg, moduleMap, articleList, articleMap))
364372
.pipe(rename({prefix: 'article_'}))
365373
.pipe(gulp.dest(BUILD_DOCS));
366374

0 commit comments

Comments
 (0)