Created
June 26, 2016 13:24
-
-
Save DanielaValero/856852eb325e1b8898ace4ddde7fc5cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import assemble from 'assemble'; | |
import assembleConfig from '../config/assemble-config.js'; | |
import markdownHelper from 'helper-markdown'; | |
import helpers from 'handlebars-helpers'; | |
import hbs from 'engine-handlebars'; | |
import gutil from 'gulp-util'; | |
import platformConfig from '../config/platform-config.js'; | |
import yaml from 'js-yaml'; | |
import fs from 'fs'; | |
import collections from 'assemble-collections'; | |
const paths = platformConfig.paths; | |
const app = assemble(); | |
// Reads the data in the concatenated file and parses it as object | |
function parseData(options) { | |
const dataFile = `${options.data.dest}/${options.data.fileName}`; | |
const data = yaml.load(fs.readFileSync(dataFile) | |
.toString()); | |
return data; | |
} | |
function loadCommon() { | |
app.engine('hbs', hbs); | |
app.helper('markdown', markdownHelper); | |
app.helpers(helpers()); | |
app.use(collections()); | |
app.on('error', (err) => { | |
gutil.log(err); | |
}); | |
app.helper('log', (context) => { | |
gutil.log(context); | |
}); | |
} | |
function load(options) { | |
loadCommon(); | |
app.option('layout', assembleConfig.defaultLayout); | |
app.layouts(options.layouts); | |
app.partials(options.partials); | |
// This creates a collection in assemble | |
// it will be available for us to call as a function | |
// which argument's list is an object | |
app.create(options.collectionName); | |
app[options.collectionName](options.pages); | |
app.data('data', parseData(options)); | |
} | |
function craft($, options) { | |
return app.toStream(options.collectionName) | |
.on('error', (err) => { | |
gutil.log(err); | |
}) | |
.pipe($.newer(`${paths.tmp}/${options.collectionName}`)) | |
.pipe($.plumber()) | |
.pipe(app.renderFile()) | |
.pipe($.extname()) | |
.on('error', (err) => { | |
gutil.log(err); | |
}) | |
.pipe($.size({ | |
title: `html: ${options.collectionName}`, | |
})) | |
.pipe(app.dest(options.dest)); | |
} | |
function loadDocumentation(cb) { | |
load(assembleConfig.documentation); | |
cb(); | |
} | |
function craftDocumentation($) { | |
return craft($, assembleConfig.documentation); | |
} | |
export default { | |
craftDocumentation, | |
loadDocumentation, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment