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

Use file ext from stream by default #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = function(options) {
'use strict';

var opts = options ? clone(options) : {};
opts.ext = opts.ext || ".html";

if (opts.defaults) {
swig.setDefaults(opts.defaults);
Expand Down Expand Up @@ -65,7 +64,7 @@ module.exports = function(options) {
var tpl = _swig.compile(String(file.contents), {filename: file.path});
var compiled = tpl(data);

file.path = ext(file.path, opts.ext);
file.path = opts.ext ? ext(file.path, opts.ext) : file.path;
file.contents = new Buffer(compiled);

callback(null, file);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body { color: white; }
27 changes: 27 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ describe('gulp-swig compilation', function() {
var filename_without_json = path.join(__dirname, './fixtures/test4.html');
var filename_with_markdown = path.join(__dirname, './fixtures/test3.html');
var filename_with_varControls = path.join(__dirname, './fixtures/test5.html');
var filename_different_ext = path.join(__dirname, './fixtures/test.css');

function expectStream(done, options) {
options = options || {};
return es.map(function(file) {
var result = String(file.contents);
var expected = options.expected;
expect(result).to.equal(expected);
if (options.expectedExt) {
var expectedExt = options.expectedExt;
expect(path.extname(file.path)).to.equal(expectedExt);
}
done();
});
}
Expand Down Expand Up @@ -138,6 +143,28 @@ describe('gulp-swig compilation', function() {
.pipe(expectStream(done, opts));
});

it('should use the file extension from the stream by default', function(done) {
var opts = {
load_json: true,
expected: 'body { color: white; }\n',
expectedExt: '.css'
};
gulp.src(filename_different_ext)
.pipe(task(opts))
.pipe(expectStream(done, opts));
});

it('should use the file extension from opts.ext instead of the stream', function(done) {
var opts = {
ext: '.less',
load_json: true,
expected: 'body { color: white; }\n',
expectedExt: '.less'
};
gulp.src(filename_different_ext)
.pipe(task(opts))
.pipe(expectStream(done, opts));
});
});

});