summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/handlebars/compiler/printer.js6
-rw-r--r--lib/handlebars/runtime.js7
-rw-r--r--spec/precompiler.js19
-rw-r--r--spec/runtime.js20
4 files changed, 43 insertions, 9 deletions
diff --git a/lib/handlebars/compiler/printer.js b/lib/handlebars/compiler/printer.js
index be66d73..7654245 100644
--- a/lib/handlebars/compiler/printer.js
+++ b/lib/handlebars/compiler/printer.js
@@ -10,16 +10,14 @@ export function PrintVisitor() {
PrintVisitor.prototype = new Visitor();
-PrintVisitor.prototype.pad = function(string, newline) {
+PrintVisitor.prototype.pad = function(string) {
var out = "";
for(var i=0,l=this.padding; i<l; i++) {
out = out + " ";
}
- out = out + string;
-
- if(newline !== false) { out = out + "\n"; }
+ out = out + string + "\n";
return out;
};
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index 0780fbf..eb942d5 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -150,12 +150,11 @@ export function template(templateSpec, env) {
};
ret._child = function(i) {
- if (templateSpec.depth) {
- throw new Exception('_child can not be used with depthed methods');
+ if (templateSpec.useDepths) {
+ throw new Exception('_child can not be used with depthed templates');
}
- // TODO : Fix this
- return container.programWithDepth(i);
+ return program(container, i, templateSpec[i]);
};
return ret;
}
diff --git a/spec/precompiler.js b/spec/precompiler.js
index 3b66353..0310681 100644
--- a/spec/precompiler.js
+++ b/spec/precompiler.js
@@ -1,5 +1,7 @@
/*global shouldThrow */
+var uglify = require('uglify-js');
+
describe('precompiler', function() {
// NOP Under non-node environments
if (typeof process === 'undefined') {
@@ -12,10 +14,13 @@ describe('precompiler', function() {
var log,
logFunction,
- precompile;
+ precompile,
+ minify;
beforeEach(function() {
precompile = Handlebars.precompile;
+ minify = uglify.minify;
+
logFunction = console.log;
log = '';
console.log = function() {
@@ -24,6 +29,7 @@ describe('precompiler', function() {
});
afterEach(function() {
Handlebars.precompile = precompile;
+ uglify.minify = minify;
console.log = logFunction;
});
@@ -65,6 +71,10 @@ describe('precompiler', function() {
equal(/'empty'/.test(log), true);
equal(/'example_1'/.test(log), true);
});
+ it('should protect from regexp patterns', function() {
+ Precompiler.cli({templates: [__dirname + '/artifacts'], extension: 'hb(s'});
+ // Success is not throwing
+ });
it('should output simple templates', function() {
Handlebars.precompile = function() { return 'simple'; };
Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], simple: true, extension: 'handlebars'});
@@ -110,4 +120,11 @@ describe('precompiler', function() {
Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], simple: true, extension: 'handlebars', known: 'foo'});
equal(log, 'simple\n');
});
+
+ it('should output minimized templates', function() {
+ Handlebars.precompile = function() { return 'amd'; };
+ uglify.minify = function() { return {code: 'min'}; };
+ Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], min: true, extension: 'handlebars'});
+ equal(log, 'min');
+ });
});
diff --git a/spec/runtime.js b/spec/runtime.js
index 4431a68..dc6e512 100644
--- a/spec/runtime.js
+++ b/spec/runtime.js
@@ -33,4 +33,24 @@ describe('runtime', function() {
}, Error, /Template was precompiled with an older version of Handlebars than the current runtime/);
});
});
+
+ describe('#child', function() {
+ if (!Handlebars.compile) {
+ return;
+ }
+
+ it('should throw for depthed methods', function() {
+ shouldThrow(function() {
+ var template = Handlebars.compile('{{#foo}}{{../bar}}{{/foo}}');
+ template._setup({});
+ template._setup({});
+ template._child(1);
+ }, Error, '_child can not be used with depthed templates');
+ });
+ it('should expose child template', function() {
+ var template = Handlebars.compile('{{#foo}}bar{{/foo}}');
+ equal(template._child(1)(), 'bar');
+ equal(template._child(1)(), 'bar');
+ });
+ });
});