diff --git a/lib/util/engines.js b/lib/util/engines.js
index 7857fbaa..6ccc61f6 100644
--- a/lib/util/engines.js
+++ b/lib/util/engines.js
@@ -19,10 +19,8 @@ var engines = module.exports;
// placeholder opening tag. This is often useful for templates including
// snippet of templates you don't want to be interpolated.
-var matcher = /<%%([^%]+)%>/g;
-var detecter = /<%%?[^%]+%>/;
engines.underscore = function underscore(source, data, options) {
- source = source.replace(matcher, function (m, content) {
+ source = source.replace(engines.underscore.options.matcher, function (m, content) {
// let's add some funny markers to replace back when templating is done,
// should be fancy enough to reduce frictions with files using markers like
// this already.
@@ -33,12 +31,19 @@ engines.underscore = function underscore(source, data, options) {
source = _.template(source, null, options)(data);
source = source
- .replace(/\(;>%%<;\)/g, '<%')
- .replace(/\(;>%<;\)/g, '%>');
+ .replace(/\(;>%%<;\)/g, engines.underscore.options.start)
+ .replace(/\(;>%<;\)/g, engines.underscore.options.end);
return source;
};
+engines.underscore.options = {
+ matcher: /<%%([^%]+)%>/g,
+ detecter: /<%%?[^%]+%>/,
+ start: '<%',
+ end: '%>'
+};
+
engines.underscore.detect = function detect(body) {
- return detecter.test(body);
+ return engines.underscore.options.detecter.test(body);
};
diff --git a/test/actions.js b/test/actions.js
index 4a756bf0..fceacfaf 100644
--- a/test/actions.js
+++ b/test/actions.js
@@ -267,6 +267,37 @@ describe('yeoman.generators.Base', function () {
assert.textEqual(body, 'bar <%= foo %>;\n');
});
});
+
+ describe('with custom tags', function () {
+ beforeEach(function (done) {
+ this.src = 'custom-template-setting.xml';
+ this.dest = 'write/to/custom-template-setting.xml';
+
+ var oldEngineOptions = this.dummy.options.engine.options;
+
+ this.dummy.options.engine.options = {
+ detecter: /\{\{?[^\}]+\}\}/,
+ matcher: /\{\{\{([^\}]+)\}\}/g,
+ start: '{{',
+ end: '}}'
+ };
+
+ this.dummy.template(this.src, this.dest, { foo: 'bar' }, {
+ evaluate: /\{\{([\s\S]+?)\}\}/g,
+ interpolate: /\{\{=([\s\S]+?)\}\}/g,
+ escape: /\{\{-([\s\S]+?)\}\}/g
+ });
+
+ this.dummy.conflicter.resolve(done);
+
+ this.dummy.options.engine.options = oldEngineOptions;
+ });
+
+ it('uses tags specified in option and engine', function () {
+ var body = fs.readFileSync(this.dest, 'utf8');
+ assert.textEqual(body, 'bar {{ foo }}\n');
+ });
+ });
});
describe('generator.directory(source, destination, process)', function () {
diff --git a/test/fixtures/custom-template-setting.xml b/test/fixtures/custom-template-setting.xml
new file mode 100644
index 00000000..7ebe1521
--- /dev/null
+++ b/test/fixtures/custom-template-setting.xml
@@ -0,0 +1 @@
+{{= foo }} {{{ foo }}