diff --git a/Gruntfile.js b/Gruntfile.js
index 849a6c4..d29fe93 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -31,12 +31,20 @@ module.exports = function(grunt) {
// Configuration to be run (and then tested).
jst: {
compile: {
+ options: {
+ templateSettings: {
+ variable: 'obj'
+ }
+ },
files: {
"tmp/jst.js": ["test/fixtures/template.html"]
}
},
pretty_amd: {
options: {
+ templateSettings: {
+ variable: 'obj'
+ },
prettify: true,
amdWrapper: true
},
@@ -46,6 +54,9 @@ module.exports = function(grunt) {
},
prettify: {
options: {
+ templateSettings: {
+ variable: 'obj'
+ },
prettify: true
},
files: {
@@ -54,6 +65,9 @@ module.exports = function(grunt) {
},
amd_wrapper: {
options: {
+ templateSettings: {
+ variable: 'obj'
+ },
amdWrapper:true
},
files: {
@@ -61,12 +75,20 @@ module.exports = function(grunt) {
}
},
uglyfile: {
+ options: {
+ templateSettings: {
+ variable: 'obj'
+ },
+ },
files: {
"tmp/uglyfile.js": ["test/fixtures/*bad-filename*"]
}
},
ns_nested: {
options: {
+ templateSettings: {
+ variable: 'obj'
+ },
namespace: "MyApp.JST.Main"
},
files: {
@@ -75,6 +97,9 @@ module.exports = function(grunt) {
},
ns_nested_this: {
options: {
+ templateSettings: {
+ variable: 'obj'
+ },
namespace: "this.MyApp.JST.Main"
},
files: {
@@ -83,6 +108,9 @@ module.exports = function(grunt) {
},
process_content: {
options: {
+ templateSettings: {
+ variable: 'obj'
+ },
processContent: function (src) {
return src.replace(/(^\s+|\s+$)/gm, '');
}
@@ -90,6 +118,11 @@ module.exports = function(grunt) {
files: {
"tmp/process_content.js": ["test/fixtures/indent_template.html"]
}
+ },
+ local_scope: {
+ files: {
+ "tmp/local_scope.js": ["test/fixtures/template_local_scope.html"]
+ }
}
},
diff --git a/test/expected/amd_wrapper.js b/test/expected/amd_wrapper.js
index 9f47f23..c8902d6 100644
--- a/test/expected/amd_wrapper.js
+++ b/test/expected/amd_wrapper.js
@@ -3,8 +3,7 @@ define(function(){
this["JST"] = this["JST"] || {};
this["JST"]["test/fixtures/template.html"] = function(obj) {
-obj || (obj = {});
-var __t, __p = '', __e = _.escape, __d = obj.obj || obj;
+var __t, __p = '', __e = _.escape;
__p += '
' +
((__t = ( obj.title )) == null ? '' : __t) +
'';
diff --git a/test/expected/jst.js b/test/expected/jst.js
index a15d3ca..7fc675c 100644
--- a/test/expected/jst.js
+++ b/test/expected/jst.js
@@ -1,8 +1,7 @@
this["JST"] = this["JST"] || {};
this["JST"]["test/fixtures/template.html"] = function(obj) {
-obj || (obj = {});
-var __t, __p = '', __e = _.escape, __d = obj.obj || obj;
+var __t, __p = '', __e = _.escape;
__p += '' +
((__t = ( obj.title )) == null ? '' : __t) +
'';
diff --git a/test/expected/local_scope.js b/test/expected/local_scope.js
new file mode 100644
index 0000000..ef5d807
--- /dev/null
+++ b/test/expected/local_scope.js
@@ -0,0 +1,13 @@
+this["JST"] = this["JST"] || {};
+
+this["JST"]["test/fixtures/template_local_scope.html"] = function(obj) {
+obj || (obj = {});
+var __t, __p = '', __e = _.escape, __d = obj.obj || obj;
+with (obj) {
+__p += '' +
+((__t = ( title )) == null ? '' : __t) +
+'';
+
+}
+return __p
+};
\ No newline at end of file
diff --git a/test/expected/ns_nested.js b/test/expected/ns_nested.js
index f51c8f4..649540a 100644
--- a/test/expected/ns_nested.js
+++ b/test/expected/ns_nested.js
@@ -3,8 +3,7 @@ this["MyApp"]["JST"] = this["MyApp"]["JST"] || {};
this["MyApp"]["JST"]["Main"] = this["MyApp"]["JST"]["Main"] || {};
this["MyApp"]["JST"]["Main"]["test/fixtures/template.html"] = function(obj) {
-obj || (obj = {});
-var __t, __p = '', __e = _.escape, __d = obj.obj || obj;
+var __t, __p = '', __e = _.escape;
__p += '' +
((__t = ( obj.title )) == null ? '' : __t) +
'';
diff --git a/test/expected/pretty.js b/test/expected/pretty.js
index a165cda..cef388c 100644
--- a/test/expected/pretty.js
+++ b/test/expected/pretty.js
@@ -1,3 +1,3 @@
this["JST"] = this["JST"] || {};
-this["JST"]["test/fixtures/template.html"] = function(obj) {obj || (obj = {});var __t, __p = '', __e = _.escape, __d = obj.obj || obj;__p += '' +((__t = ( obj.title )) == null ? '' : __t) +'';return __p};
\ No newline at end of file
+this["JST"]["test/fixtures/template.html"] = function(obj) {var __t, __p = '', __e = _.escape;__p += '' +((__t = ( obj.title )) == null ? '' : __t) +'';return __p};
\ No newline at end of file
diff --git a/test/expected/pretty_amd.js b/test/expected/pretty_amd.js
index 7d4b494..760ed87 100644
--- a/test/expected/pretty_amd.js
+++ b/test/expected/pretty_amd.js
@@ -2,7 +2,7 @@ define(function(){
this["JST"] = this["JST"] || {};
- this["JST"]["test/fixtures/template.html"] = function(obj) {obj || (obj = {});var __t, __p = '', __e = _.escape, __d = obj.obj || obj;__p += '' +((__t = ( obj.title )) == null ? '' : __t) +'';return __p};
+ this["JST"]["test/fixtures/template.html"] = function(obj) {var __t, __p = '', __e = _.escape;__p += '' +((__t = ( obj.title )) == null ? '' : __t) +'';return __p};
return this["JST"];
});
\ No newline at end of file
diff --git a/test/expected/process_content.js b/test/expected/process_content.js
index 941e0ce..fda2b11 100644
--- a/test/expected/process_content.js
+++ b/test/expected/process_content.js
@@ -1,8 +1,7 @@
this["JST"] = this["JST"] || {};
this["JST"]["test/fixtures/indent_template.html"] = function(obj) {
-obj || (obj = {});
-var __t, __p = '', __e = _.escape, __d = obj.obj || obj;
+var __t, __p = '', __e = _.escape;
__p += '\n
\n
\n' +
((__t = ( obj.name )) == null ? '' : __t) +
'\n
\n
\n
';
diff --git a/test/expected/uglyfile.js b/test/expected/uglyfile.js
index 1b4bb1c..fe0313b 100644
--- a/test/expected/uglyfile.js
+++ b/test/expected/uglyfile.js
@@ -1,8 +1,7 @@
this["JST"] = this["JST"] || {};
this["JST"]["test/fixtures/it's-a-bad-filename.html"] = function(obj) {
-obj || (obj = {});
-var __t, __p = '', __e = _.escape, __d = obj.obj || obj;
+var __t, __p = '', __e = _.escape;
__p += 'never name your file like this.';
return __p
};
\ No newline at end of file
diff --git a/test/fixtures/indent_template.html b/test/fixtures/indent_template.html
index f7167be..8ec203f 100644
--- a/test/fixtures/indent_template.html
+++ b/test/fixtures/indent_template.html
@@ -1,7 +1,7 @@
- <%= name %>
+ <%= obj.name %>
diff --git a/test/fixtures/template.html b/test/fixtures/template.html
index d7a184a..b2b5ffe 100644
--- a/test/fixtures/template.html
+++ b/test/fixtures/template.html
@@ -1 +1 @@
-<%= title %>
\ No newline at end of file
+<%= obj.title %>
\ No newline at end of file
diff --git a/test/fixtures/template_local_scope.html b/test/fixtures/template_local_scope.html
new file mode 100644
index 0000000..d7a184a
--- /dev/null
+++ b/test/fixtures/template_local_scope.html
@@ -0,0 +1 @@
+<%= title %>
\ No newline at end of file
diff --git a/test/jst_test.js b/test/jst_test.js
index 7cd66be..a0323c9 100644
--- a/test/jst_test.js
+++ b/test/jst_test.js
@@ -6,7 +6,7 @@ exports['jst'] = {
var expect, result;
- test.expect(8);
+ test.expect(9);
expect = grunt.file.read("test/expected/jst.js");
result = grunt.file.read("tmp/jst.js");
@@ -40,6 +40,10 @@ exports['jst'] = {
result = grunt.file.read("tmp/process_content.js");
test.equal(expect, result, "should convert file content");
+ expect = grunt.file.read("test/expected/local_scope.js");
+ result = grunt.file.read("tmp/local_scope.js");
+ test.equal(expect, result, "should add `with` block when templateSettings.variable is undefined");
+
test.done();
}
};