mattacular / grunt-handlebars-compiler

Grunt.js task to precompile Handlebars.js templates with the same options as the CLI utility
MIT License
12 stars 12 forks source link

no option for the --min flag? #2

Closed atuttle closed 10 years ago

atuttle commented 10 years ago

I know grunt offers other ways to minify js files, but since this project aims to offer the same options as the handlebars CLI, I figured it was worth mentioning that it's missing --min to trigger minification. If it was there, I'd use it. Thanks for a useful project!

mattacular commented 10 years ago

Glad you find it useful and thanks for the heads up! Ill get that added as soon as i have a chance, otherwise feel free to submit a pull request if youre feeling adventurous

Matt

On Wednesday, November 20, 2013, Adam Tuttle wrote:

I know grunt offers other ways to minify js files, but since this project aims to offer the same options as the handlebars CLI, I figured it was worth mentioning that it's missing --min to trigger minification. If it was there, I'd use it. Thanks for a useful project!

— Reply to this email directly or view it on GitHubhttps://github.com/mattacular/grunt-handlebars-compiler/issues/2 .

atuttle commented 10 years ago

Looks like the handlebars CLI relies on uglify and simply checks for the min flag and minifies the output after all else is said and done:

if (argv.min) {
  output = uglify.minify(output, {fromString: true}).code;
}

I guess the best thing for the grunt task to do, then, would be to do the same thing. I'll see if I can put together a pull request.

atuttle commented 10 years ago

I don't know if it's a handlebars version or something, but when I run the tests without any modifications to the source at all, I get 6/6 failed. :-\

atuttle commented 10 years ago
$ grunt test
Running "clean:tests" (clean) task
Cleaning "tmp"...OK

Running "handlebars:vanilla" (handlebars) task
File "tmp/out.compiled.js" created.

Running "handlebars:namespace" (handlebars) task
File "tmp/out-namespace.compiled.js" created.

Running "handlebars:templateRoot" (handlebars) task
Found templateRoot and stripped it from the template name: "World.handlebars"
File "tmp/out-templateRoot.compiled.js" created.

Running "handlebars:exportAMD" (handlebars) task
Compiling as AMD/RequireJS module(s).
File "tmp/out-exportAMD.compiled.js" created.

Running "handlebars:exportCommonJS" (handlebars) task
Compiling as Common JS module(s).
File "tmp/out-exportCommonJS.compiled.js" created.

Running "handlebars:knownHelpers" (handlebars) task
Compiling with known helpers:
>> if, each
File "tmp/out-knownHelpers.compiled.js" created.

Running "nodeunit:tests" (nodeunit) task
Testing handlebars_test.jsF
>> handlebars
>> Message: The vanilla (no options) compiled output should match the clean (prepped) build
>> Error: '(function() {\nvar template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'helloWorld\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [4,\'>= 1.0.0\'];\nhelpers = this.merge(helpers, Handlebars.helpers); data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;\n\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.doctype); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.message); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t</body>\\n</html>";\n  return buffer;\n  });\n}());' == '(function() {\nvar template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'helloWorld\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [2,\'>= 1.0.0-rc.3\'];\nhelpers = helpers || Handlebars.helpers; data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;\n\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.doctype; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.message; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t</body>\\n</html>";\n  return buffer;\n  });\n}());'
>> at Object.exports.handlebars (test/handlebars_test.js:51:8)

>> handlebars
>> Message: The namespace compiled output should match the clean (prepped) build
>> Error: '(function() {\nvar template = Handlebars.template, templates = myApp.templates = myApp.templates || {};\ntemplates[\'helloWorld\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [4,\'>= 1.0.0\'];\nhelpers = this.merge(helpers, Handlebars.helpers); data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;\n\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.doctype); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.message); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t</body>\\n</html>";\n  return buffer;\n  });\n}());' == '(function() {\nvar template = Handlebars.template, templates = myApp.templates = myApp.templates || {};\ntemplates[\'helloWorld\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [2,\'>= 1.0.0-rc.3\'];\nhelpers = helpers || Handlebars.helpers; data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;\n\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.doctype; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.message; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t</body>\\n</html>";\n  return buffer;\n  });\n}());'
>> at Object.exports.handlebars (test/handlebars_test.js:51:8)

>> handlebars
>> Message: The output compiled as a AMD module should match the clean (prepped) build
>> Error: 'define([\'handlebars\'], function (Handlebars) {\nvar template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'helloWorld\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [4,\'>= 1.0.0\'];\nhelpers = this.merge(helpers, Handlebars.helpers); data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;\n\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.doctype); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.message); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t</body>\\n</html>";\n  return buffer;\n  });\n});' == 'define([\'handlebars\'], function (Handlebars) {\nvar template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'helloWorld\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [2,\'>= 1.0.0-rc.3\'];\nhelpers = helpers || Handlebars.helpers; data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;\n\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.doctype; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.message; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t</body>\\n</html>";\n  return buffer;\n  });\n});'
>> at Object.exports.handlebars (test/handlebars_test.js:51:8)

>> handlebars
>> Message: The output compiled as a Common JS module should match the clean (prepped) build
>> Error: 'var Handlebars = require(\'handlebars\');\nvar template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'helloWorld\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [4,\'>= 1.0.0\'];\nhelpers = this.merge(helpers, Handlebars.helpers); data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;\n\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.doctype); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.message); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t</body>\\n</html>";\n  return buffer;\n  });\n' == 'var Handlebars = require(\'handlebars\');\nvar template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'helloWorld\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [2,\'>= 1.0.0-rc.3\'];\nhelpers = helpers || Handlebars.helpers; data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;\n\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.doctype; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.message; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t</body>\\n</html>";\n  return buffer;\n  });\n'
>> at Object.exports.handlebars (test/handlebars_test.js:51:8)

>> handlebars
>> Message: The templateRoot should have been stripped to match the clean (prepped) build
>> Error: '(function() {\nvar template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'World\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [4,\'>= 1.0.0\'];\nhelpers = this.merge(helpers, Handlebars.helpers); data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;\n\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.doctype); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.message); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t</body>\\n</html>";\n  return buffer;\n  });\n}());' == '(function() {\nvar template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'World\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [2,\'>= 1.0.0-rc.3\'];\nhelpers = helpers || Handlebars.helpers; data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;\n\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.doctype; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.message; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t</body>\\n</html>";\n  return buffer;\n  });\n}());'
>> at Object.exports.handlebars (test/handlebars_test.js:51:8)

>> handlebars
>> Message: The output compiled with known helpers should match the clean (prepped) build
>> Error: '(function() {\nvar template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'helloWorld-helpers\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [4,\'>= 1.0.0\'];\nhelpers = this.merge(helpers, Handlebars.helpers); data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;\n\nfunction program1(depth0,data) {\n  \n  var buffer = "", stack1;\n  buffer += "\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.message); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t\t";\n  return buffer;\n  }\n\nfunction program3(depth0,data) {\n  \n  var buffer = "";\n  buffer += "\\n\t\t<p>"\n    + escapeExpression((typeof depth0 === functionType ? depth0.apply(depth0) : depth0))\n    + "</p>\\n\t\t";\n  return buffer;\n  }\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = (depth0 && depth0.doctype); stack1 = typeof stack1 === functionType ? stack1.call(depth0, {hash:{},data:data}) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t";\n  stack1 = helpers[\'if\'].call(depth0, (depth0 && depth0.message), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});\n  if(stack1 || stack1 === 0) { buffer += stack1; }\n  buffer += "\\n\\n\t\t";\n  stack1 = helpers.each.call(depth0, (depth0 && depth0.messages), {hash:{},inverse:self.noop,fn:self.program(3, program3, data),data:data});\n  if(stack1 || stack1 === 0) { buffer += stack1; }\n  buffer += "\\n\t</body>\\n</html>";\n  return buffer;\n  });\n}());' == '(function() {\nvar template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'helloWorld-helpers\'] = template(function (Handlebars,depth0,helpers,partials,data) {\n  this.compilerInfo = [2,\'>= 1.0.0-rc.3\'];\nhelpers = helpers || Handlebars.helpers; data = data || {};\n  var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;\n\nfunction program1(depth0,data) {\n  \n  var buffer = "", stack1;\n  buffer += "\\n\t\t<div>Hello world! ";\n  if (stack1 = helpers.message) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.message; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + "</div>\\n\t\t";\n  return buffer;\n  }\n\nfunction program3(depth0,data) {\n  \n  var buffer = "";\n  buffer += "\\n\t\t<p>"\n    + escapeExpression((typeof depth0 === functionType ? depth0.apply(depth0) : depth0))\n    + "</p>\\n\t\t";\n  return buffer;\n  }\n\n  buffer += "<!doctype ";\n  if (stack1 = helpers.doctype) { stack1 = stack1.call(depth0, {hash:{},data:data}); }\n  else { stack1 = depth0.doctype; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }\n  buffer += escapeExpression(stack1)\n    + ">\\n<html>\\n\t<body>\\n\t\t";\n  stack1 = helpers[\'if\'].call(depth0, depth0.message, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});\n  if(stack1 || stack1 === 0) { buffer += stack1; }\n  buffer += "\\n\\n\t\t";\n  stack1 = helpers.each.call(depth0, depth0.messages, {hash:{},inverse:self.noop,fn:self.program(3, program3, data),data:data});\n  if(stack1 || stack1 === 0) { buffer += stack1; }\n  buffer += "\\n\t</body>\\n</html>";\n  return buffer;\n  });\n}());'
>> at Object.exports.handlebars (test/handlebars_test.js:51:8)

Warning: 6/6 assertions failed (94ms) Use --force to continue.

Aborted due to warnings.
mattacular commented 10 years ago

It is also possible that i broke the tests. Ive been slammed at work but ill check it out as soon as time permits. Will you submit an issue on github so i dont forget?

Thx, Matt

On Wednesday, November 20, 2013, Adam Tuttle wrote:

I don't know if it's a handlebars version or something, but when I run the tests without any modifications to the source at all, I get 6/6 failed. :-\

— Reply to this email directly or view it on GitHubhttps://github.com/mattacular/grunt-handlebars-compiler/issues/2#issuecomment-28892866 .

atuttle commented 10 years ago

Submitted #3

mattacular commented 10 years ago

Added min option in 0.0.8

atuttle commented 10 years ago

Thanks for the fix. You should tag releases so they show up on GitHub, too. :)