Permalink
Browse files

Adding a test for processPartialName option

  • Loading branch information...
1 parent 8535ecb commit 2769b4270ff9e3d0b116e79a3d0ea9bbf71380f9 @pdokas pdokas committed Feb 21, 2013
Showing with 48 additions and 0 deletions.
  1. +10 −0 Gruntfile.js
  2. +27 −0 test/expected/process_partial_name.js
  3. +1 −0 test/fixtures/_weird_prefix_partial.hbs
  4. +10 −0 test/handlebars_test.js
View
@@ -131,6 +131,16 @@ module.exports = function(grunt) {
files: {
'tmp/processname.js': ['test/fixtures/basic.hbs']
}
+ },
+ process_partial_name: {
+ options: {
+ processPartialName: function(filepath) {
+ return filepath.replace('test/fixtures/_weird_prefix_', '').replace('.hbs', '');
+ }
+ },
+ files: {
+ 'tmp/process_partial_name.js': ['test/fixtures/_weird_prefix_partial.hbs', 'test/fixtures/one.hbs']
+ }
}
},
// Unit tests.
@@ -0,0 +1,27 @@
+this["JST"] = this["JST"] || {};
+
+Handlebars.registerPartial("partial", Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
+ this.compilerInfo = [2,'>= 1.0.0-rc.3'];
+helpers = helpers || Handlebars.helpers; data = data || {};
+
+
+
+ return "<span>Canada</span>";
+ }));
+
+this["JST"]["test/fixtures/one.hbs"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
+ this.compilerInfo = [2,'>= 1.0.0-rc.3'];
+helpers = helpers || Handlebars.helpers; partials = partials || Handlebars.partials; data = data || {};
+ var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
+
+
+ buffer += "<p>Hello, my name is ";
+ if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + ". I live in ";
+ stack1 = self.invokePartial(partials.partial, 'partial', depth0, helpers, partials, data);
+ if(stack1 || stack1 === 0) { buffer += stack1; }
+ buffer += "</p>";
+ return buffer;
+ });
@@ -0,0 +1 @@
+<span>Canada</span>
View
@@ -120,5 +120,15 @@ exports.handlebars = {
test.equal(actual, expected, 'should convert template name to upper case.');
test.done();
+ },
+ process_partial_name: function(test) {
+ 'use strict';
+ test.expect(1);
+
+ var actual = grunt.file.read('tmp/process_partial_name.js');
+ var expected = grunt.file.read('test/expected/process_partial_name.js');
+ test.equal(actual, expected, 'should support custom handling of partial naming conventions.');
+
+ test.done();
}
};

0 comments on commit 2769b42

Please sign in to comment.