Skip to content

Commit

Permalink
Merge pull request #305 from jaysonpotter/compile-underscore-partials
Browse files Browse the repository at this point in the history
Partials Underscore Compile
  • Loading branch information
doowb authored Mar 19, 2018
2 parents 4e05c88 + f9a1790 commit 5480139
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,9 @@ exports.underscore.render = function(str, options, fn) {
return promisify(fn, function(fn) {
var engine = requires.underscore || (requires.underscore = require('underscore'));
try {
for (var partial in options.partials) {
options.partials[partial] = engine.template(options.partials[partial]);
}
var tmpl = cache(options) || cache(options, engine.template(str, null, options));
fn(null, tmpl(options).replace(/\n$/, ''));
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions test/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require('./shared').test('handlebars');
require('./shared/partials').test('handlebars');
require('./shared/helpers').test('handlebars');
require('./shared').test('underscore');
require('./shared/partials').test('underscore');
require('./shared').test('lodash');
require('./shared').test('qejs');
require('./shared').test('walrus');
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/underscore/partials.underscore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p><%- user.name %></p><%= partials.partial(user) %>
1 change: 1 addition & 0 deletions test/fixtures/underscore/user_partial.underscore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p><%- name %> from user_partial!</p>
18 changes: 16 additions & 2 deletions test/shared/partials.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,22 @@ exports.test = function(name) {
done();
});
});
}
else {
} else if (name == 'underscore') {
it('should support partials', function(done){
var path = 'test/fixtures/' + name + '/partials.' + name;
var locals = {
user: user,
partials: {
partial: 'user_partial'
}
};
cons[name](path, locals, function(err, html){
if (err) return done(err);
html.should.equal('<p>Tobi</p><p>Tobi from user_partial!</p>');
done();
});
});
} else {
it('should support rendering a partial', function(done){
var str = fs.readFileSync('test/fixtures/' + name + '/user_partial.' + name).toString();
var locals = {
Expand Down

0 comments on commit 5480139

Please sign in to comment.