Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadened Windows precompile support to include strings #825

Merged
merged 3 commits into from
Aug 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Changelog
* Allow full expressions (incl. filters) in import and from tags. Thanks legutierr.
Merge of [#710](https://github.com/mozilla/nunjucks/pull/710).

* OS agnostic file paths in precompile. Merge of [#825](https://github.com/mozilla/nunjucks/pull/825).

2.4.2 (Apr 15 2016)
-------------------
Expand Down
4 changes: 2 additions & 2 deletions src/precompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ function precompile(input, opts) {
for(var i=0; i<templates.length; i++) {
var name = templates[i].replace(path.join(input, '/'), '');

name = name.replace(/\\/g, '/');

try {
precompiled.push( _precompile(
fs.readFileSync(templates[i], 'utf-8'),
Expand Down Expand Up @@ -119,6 +117,8 @@ function _precompile(str, name, env) {
var extensions = env.extensionsList;
var template;

name = name.replace(/\\/g, '/');

try {
template = compiler.compile(str,
asyncFilters,
Expand Down
16 changes: 15 additions & 1 deletion tests/precompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,21 @@
}
});

expect(fileName).to.not.contain('\\');
expect(fileName).to.equal('./tests/templates/item.njk');
});

it('should return *NIX path seperators, when name is passed as option', function() {
var fileName;

precompile('<span>test</span>', {
name: 'path\\to\\file.j2',
isString: true,
wrapper: function(templates) {
fileName = templates[0].name;
}
});

expect(fileName).to.equal('path/to/file.j2');
});
});
});
Expand Down