Skip to content
This repository was archived by the owner on Apr 11, 2018. It is now read-only.

Commit 2089af6

Browse files
committed
Fix not being able to set method-name in swig cli
1 parent 2c5e564 commit 2089af6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

bin/swig.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var swig = require('../index'),
1010
uglify = require('uglify-js');
1111

1212
var command,
13+
wrapstart = 'var tpl = ',
1314
argv = optimist
1415
.usage('\n Usage:\n' +
1516
' $0 compile [files] [options]\n' +
@@ -37,7 +38,7 @@ var command,
3738
.alias('j', 'json')
3839
.alias('c', 'context')
3940
.alias('m', 'minify')
40-
.default('wrap-start', 'var tpl = ')
41+
.default('wrap-start', wrapstart)
4142
.default('wrap-end', ';')
4243
.default('method-name', 'tpl')
4344
.check(function (argv) {
@@ -54,7 +55,7 @@ var command,
5455
throw new Error('Unrecognized command "' + command + '". Use -h for help.');
5556
}
5657

57-
if (argv['method-name'] !== 'tpl' && argv['wrap-start'] !== 'var tpl =') {
58+
if (argv['method-name'] !== 'tpl' && argv['wrap-start'] !== wrapstart) {
5859
throw new Error('Cannot use arguments "--method-name" and "--wrap-start" together.');
5960
}
6061

tests/bin/bin.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ describe('bin/swig compile -m', function () {
9595
});
9696
});
9797

98+
describe('bin/swig compile --method-name="foo"', function () {
99+
it('sets the method name to "foo"', function (done) {
100+
var p = fixPath(casedir + '/extends_1.test.html');
101+
exec('node ' + bin + ' compile ' + p + ' --method-name="foo"', function (err, stdout, stderr) {
102+
expect(stdout).to.equal('var foo = function (_swig,_ctx,_filters,_utils,_fn) {\n var _ext = _swig.extensions,\n _output = "";\n_output += "Hi,\\n\\n";\n_output += "This is the body.";\n_output += "\\n\\nSincerely,\\nMe\\n";\n\n return _output;\n\n};\n');
103+
done();
104+
});
105+
});
106+
});
107+
98108
describe('bin/swig compile & run from swig', function () {
99109
it('can be run', function (done) {
100110
var expectation = fs.readFileSync(casedir + '/extends_1.expectation.html', 'utf8'),

0 commit comments

Comments
 (0)