Skip to content

Commit

Permalink
rebase with master
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron J Roe committed Apr 13, 2016
2 parents e1c3517 + 2f7b125 commit 76af43c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
- [twig](https://github.com/justjohn/twig.js)
- [liquid](https://github.com/leizongmin/tinyliquid) [(website)](http://liquidmarkup.org/)
- [toffee](https://github.com/malgorithms/toffee)
- [underscore](https://github.com/documentcloud/underscore) [(website)](http://documentcloud.github.com/underscore/)
- [underscore](https://github.com/documentcloud/underscore) [(website)](http://underscorejs.org/#template)
- [vash](https://github.com/kirbysayshi/vash)
- [walrus](https://github.com/jeremyruppel/walrus) [(website)](http://documentup.com/jeremyruppel/walrus/)
- [whiskers](https://github.com/gsf/whiskers.js)
Expand Down
26 changes: 16 additions & 10 deletions lib/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,8 @@ exports.nunjucks.render = function(str, options, fn) {
return promisify(fn, function (fn) {
try {
var engine = requires.nunjucks || (requires.nunjucks = require('nunjucks'));
if (options.settings && options.settings.views) engine.configure(options.settings.views);

var loader = options.loader;
if (loader) {
var env = new engine.Environment(new loader(options));
Expand Down Expand Up @@ -1224,16 +1226,20 @@ function reactBaseTmpl(data, options){
* The main render parser for React bsaed templates
*/
function reactRenderer(type){

// Ensure JSX is transformed on require
if (!require.extensions['.jsx']) {
require.extensions['.jsx'] = requireReact;
}

// Supporting .react extension as well as test cases
// Using .react extension is not recommended.
if (!require.extensions['.react']) {
require.extensions['.react'] = requireReact;

if (require.extensions) {

// Ensure JSX is transformed on require
if (!require.extensions['.jsx']) {
require.extensions['.jsx'] = requireReact;
}

// Supporting .react extension as well as test cases
// Using .react extension is not recommended.
if (!require.extensions['.react']) {
require.extensions['.react'] = requireReact;
}

}

// Return rendering fx
Expand Down
1 change: 1 addition & 0 deletions test/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require('./shared').test('ractive');
require('./shared/partials').test('ractive');
require('./shared').test('nunjucks');
require('./shared/filters').test('nunjucks');
require('./shared/includes').test('nunjucks');
require('./shared').test('htmling');
require('./shared/react').test('react');
require('./shared').test('vash');
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/nunjucks/_base_layout.nunjucks
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<header></header>{%block content%}{%endblock%}<footer></footer>
1 change: 1 addition & 0 deletions test/fixtures/nunjucks/include.nunjucks
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include 'user.nunjucks' %}
3 changes: 3 additions & 0 deletions test/fixtures/nunjucks/layouts.nunjucks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends '_base_layout.nunjucks' %}

{% block content %}<p>{{user.name}}</p>{% endblock %}
24 changes: 21 additions & 3 deletions test/shared/includes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ var should = require('should');
exports.test = function(name) {
var user = { name: 'Tobi' };

describe(name, function(){
describe(name, function() {

it('should support includes', function(done) {
var str = fs.readFileSync('test/fixtures/' + name + '/include.' + name).toString();
var locals = { user: user, includeDir: 'test/fixtures/' + name };

cons[name].render(str, locals, function(err, html){
cons[name].render(str, locals, function(err, html) {
if (err) return done(err);
try{
if (name === 'liquid') {
Expand All @@ -26,5 +26,23 @@ exports.test = function(name) {
}
});
});

if (name == 'nunjucks') {
it('should support extending views', function (done) {
var str = fs.readFileSync('test/fixtures/' + name + '/layouts.' + name).toString();

var locals = {user: user, settings: {views: 'test/fixtures/' + name}};

cons[name].render(str, locals, function (err, html) {
if (err) return done(err);
try {
html.should.eql('<header></header><p>Tobi</p><footer></footer>');
return done();
} catch (e) {
return done(e);
}
});
});
}
});
};

0 comments on commit 76af43c

Please sign in to comment.