Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding a test for partialRegex option

  • Loading branch information...
commit c54fc831ef52549fe973f9b5f723053e6fd8d334 1 parent 2769b42
@pdokas pdokas authored
View
11 Gruntfile.js
@@ -141,6 +141,17 @@ module.exports = function(grunt) {
files: {
'tmp/process_partial_name.js': ['test/fixtures/_weird_prefix_partial.hbs', 'test/fixtures/one.hbs']
}
+ },
+ partial_regex: {
+ options: {
+ partialRegex: /^par_/,
+ processPartialName: function(filepath) {
+ return filepath.replace('test/fixtures/par_', '').replace('.hbs', '');
+ }
+ },
+ files: {
+ 'tmp/partial_regex.js': ['test/fixtures/par_partial.hbs', 'test/fixtures/one.hbs']
+ }
}
},
// Unit tests.
View
27 test/expected/partial_regex.js
@@ -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;
+ });
View
1  test/fixtures/par_partial.hbs
@@ -0,0 +1 @@
+<span>Canada</span>
View
10 test/handlebars_test.js
@@ -130,5 +130,15 @@ exports.handlebars = {
test.equal(actual, expected, 'should support custom handling of partial naming conventions.');
test.done();
+ },
+ partial_regex: function(test) {
+ 'use strict';
+ test.expect(1);
+
+ var actual = grunt.file.read('tmp/partial_regex.js');
+ var expected = grunt.file.read('test/expected/partial_regex.js');
+ test.equal(actual, expected, 'should support custom file name identifiers for partials.');
+
+ test.done();
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.