Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
examples | ||
node_modules | ||
node_modules | ||
test |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ number | square }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{% extends './parent.nunj' %} | ||
{% block content %} | ||
Child says: hello {{ name | default('world') }} | ||
{% endblock %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="content"> | ||
{% block content %}{% endblock %} | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ number | double }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<script src="/bundle.js" type="text/javascript" charset="utf-8"></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = function(env) { | ||
|
||
env.addFilter('double', function(input) { | ||
return input * 2; | ||
}); | ||
|
||
env.addFilter('square', function(input, done) { | ||
var result = input * input; | ||
setTimeout(function() { | ||
done(null, result); | ||
}, 10); | ||
}, true) | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
var chai = require('chai'); | ||
var should = chai.should(); | ||
|
||
describe('path resolution', function() { | ||
|
||
it('should resolve paths using webpack resolve', function() { | ||
var tpl1 = require('./fixtures/templates/child.nunj'); | ||
var tpl2 = require('child.nunj'); | ||
|
||
tpl1.render.should.be.a.Function; | ||
tpl2.render.should.be.a.Function; | ||
tpl1.render().should.equal(tpl2.render()); | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('template inheritance', function() { | ||
|
||
beforeEach(function() { | ||
this.tpl = require('child.nunj'); | ||
}); | ||
|
||
it('should inherit from parent template', function() { | ||
this.tpl.render.should.be.a.Function; | ||
}); | ||
|
||
it('should render a default argument', function() { | ||
var result = this.tpl.render(); | ||
result.should.be.a.String | ||
result.should.contain('hello world'); | ||
result.should.contain('<div class="content">') | ||
}); | ||
|
||
it('should render using the data context', function() { | ||
var context = { name: 'everyone'}; | ||
var result = this.tpl.render(context); | ||
result.should.be.a.String | ||
result.should.contain('hello ' + context.name); | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('environment config', function() { | ||
|
||
describe('filters', function() { | ||
|
||
before(function() { | ||
this.tpl = require('standard-filter.nunj'); | ||
}); | ||
|
||
it('should register "double" filter', function() { | ||
this.tpl.render.should.be.a.Function; | ||
}); | ||
|
||
it('should render (a)sync', function(done) { | ||
this.tpl.render({number: 2}).should.equal('4'); | ||
this.tpl.render({number: 20}, function(err, result) { | ||
should.not.exist(err); | ||
result.should.equal('40'); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('filters [async]', function() { | ||
|
||
before(function() { | ||
this.tpl = require('async-filter.nunj'); | ||
}); | ||
|
||
it('should add "square" async filter', function() { | ||
this.tpl.render.should.be.a.Function; | ||
}); | ||
|
||
it('should render async only', function(done) { | ||
should.not.exist(this.tpl.render()); | ||
this.tpl.render({ number: 2 }, function(err, result) { | ||
should.not.exist(err); | ||
result.should.be.a.Number; | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
|
||
context: __dirname, | ||
|
||
entry: 'mocha!./web.js', | ||
|
||
output: { | ||
path: __dirname, | ||
filename: 'bundle.js' | ||
}, | ||
|
||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.(nunj|nunjucks)$/, | ||
loader: 'index', | ||
query: { | ||
config: __dirname + '/nunjucks.config.js' | ||
} | ||
} | ||
] | ||
}, | ||
|
||
resolve: { | ||
root: [ | ||
__dirname, | ||
__dirname + '/fixtures/templates' | ||
] | ||
}, | ||
|
||
resolveLoader: { | ||
modulesDirectories: ['web_loaders', 'web_modules', 'node_loaders', 'node_modules', '../'] | ||
} | ||
|
||
}; |