Skip to content

Commit

Permalink
Moving plugin stage.
Browse files Browse the repository at this point in the history
Moving `'render:post:page'` to be called after the page is rendered
to a string but before it's written to a file.

Also updating a broken test.
  • Loading branch information
doowb committed Nov 11, 2013
1 parent a105963 commit fa99cd2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
21 changes: 13 additions & 8 deletions tasks/assemble.js
Expand Up @@ -421,19 +421,24 @@ module.exports = function(grunt) {
function postprocess(src, fn) {return fn(src);}
var processFn = function(src) {return src;};

// Write the file.
file.write(page.dest, postprocess(result, assemble.options.postprocess || processFn));

grunt.verbose.writeln('Assembled ' + (page.dest).cyan +' OK'.green);
grunt.log.notverbose.ok();

// Run any plugins for the 'render:post:page' stage
assemble.plugins.runner('render:post:page', {
var params = {
grunt: grunt, // the `grunt` object
assemble: assemble, // the `assemble` object
page: page, // the raw page
content: result // the rendered page
})(done);
};

assemble.plugins.runner('render:post:page', params)(function() {
// Write the file.
file.write(page.dest, postprocess(params.content, assemble.options.postprocess || processFn));

grunt.verbose.writeln('Assembled ' + (page.dest).cyan +' OK'.green);
grunt.log.notverbose.ok();

done();
});

}); // build


Expand Down
11 changes: 7 additions & 4 deletions test/engine_test.js
Expand Up @@ -7,9 +7,12 @@
*/

var assembleEngine = require('../lib/engine');
var assembleHelpers = require('../lib/helpers');
var expect = require('chai').expect;

var pluginParams = {
grunt: require('grunt')
};



describe('Loading default handlebars engine', function() {
Expand Down Expand Up @@ -76,7 +79,7 @@ describe('Loading default handlebars engine', function() {
engine.init({
cwd: __dirname,
helpers: './helpers/helpers.js'
});
}, pluginParams);
runTest(engine, done);
});

Expand All @@ -85,13 +88,13 @@ describe('Loading default handlebars engine', function() {
engine.init({
cwd: __dirname,
helpers: './helpers/helpers/*.js'
});
}, pluginParams);
runTest(engine, done);
});

it('loads a custom helper without needing to set the cwd', function(done) {
var engine = assembleEngine.load('handlebars');
engine.init({helpers: './test/helpers/*.js'});
engine.init({helpers: './test/helpers/*.js'}, pluginParams);
var expected = '<!-- bar -->';
engine.compile("{{{foo 'bar'}}}", null, function(err, tmpl) {
if(err) {
Expand Down

0 comments on commit fa99cd2

Please sign in to comment.