Last active
March 17, 2016 13:33
Revisions
-
doowb revised this gist
Mar 17, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Using es2015 javascript generators in assemble tasks. Assemble is now able to directly take a generator function as a task function. This removes the need for a callback when running synchronous code inside tasks. **From** -
doowb created this gist
Mar 17, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ # Using es2015 javascript generators in assemble tasks. Assemble is now able to directly take a generator function as a task function. This removes the need for a callback when running syncronise code inside tasks. **From** ```js app.task('load', function(cb) { app.layouts(['src/layouts/**/*.hbs']); app.partials(['src/partials/**/*.hbs']); app.pages(['src/pages/**/*.hbs']); cb(); }); ``` **To** ```js app.task('load', function* () { app.layouts(['src/layouts/**/*.hbs']); app.partials(['src/partials/**/*.hbs']); app.pages(['src/pages/**/*.hbs']); }); ``` This also allows using generator features like `yield`. > assemblefile.js ```js 'use strict'; var assemble = require('assemble'); var thunk = require('thunkify'); var fs = require('fs'); var app = assemble(); var readFile = thunk(fs.readFile); app.task('read', function* () { var contents = yield readFile('./package.json', 'utf8'); console.log(contents); }); app.task('default', ['read']); module.exports = app; ``` > output  This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ 'use strict'; var assemble = require('assemble'); var thunk = require('thunkify'); var fs = require('fs'); var app = assemble(); var readFile = thunk(fs.readFile); app.task('read', function* () { var contents = yield readFile('./package.json', 'utf8'); console.log(contents); }); app.task('default', ['read']); module.exports = app; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ { "name": "assemble-es2015-generators", "description": "Use es2015 javascript generators as assemble tasks", "main": "assemblefile.js", "engines": { "node": ">=4.0" }, "private": true, "version": "0.1.0", "homepage": "https://github.com/assemble/assemble", "author": "Brian Woodward (https://github.com/doowb)", "repository": "assemble/assemble", "bugs": { "url": "https://github.com/assemble/assemble/issues" }, "license": "MIT", "files": [ "assemblefile.js", ], "dependencies": { "assemble": "^0.9.2", "thunkify": "^2.1.2" } }