javascript - grunt-contrib-handlebars 输出不同于 handlebars npm 任务

标签 javascript compilation handlebars.js npm gruntjs

我的问题与 grunt-contrib-handlebars - Output is different than when I run the handlebars npm task 非常相似,但没有人回答这个问题,所以我想我会开始自己的。

我正在尝试将 Handlebars 模板文件预编译为 js 文件。我最初使用 handlebars npm 任务手动编译它,并且该网站可以正常使用 npm 生成的输出。我运行以下命令:

handlebars *.handlebars -f template.js 

生成以下内容:

    (function() {
  var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['address-book-contact-form'] = 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, stack2, options, functionType="function", escapeExpression=this.escapeExpression, self=this, helperMissing=helpers.helperMissing;


  buffer += "<form class=\"dark-bg\">\n  <input type=\"hidden\" id=\"propertyId-input\" name=\"propertyId\" value=\"";
  if (stack1 = helpers.propertyId) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
  else { stack1 = depth0.propertyId; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
  buffer += escapeExpression(stack1)
    + "\"/>\n\n  ";
  stack1 = self.invokePartial(partials['partial-overlay-nav'], 'partial-overlay-nav', depth0, helpers, partials, data);
  if(stack1 || stack1 === 0) { buffer += stack1; }
  buffer += "\n  \n <div class=\"property-fields-wrapper\">\n  <fieldset>\n    <div class=\"address-book-form row\"> \n      \n      <div class=\"span3\">\n        <h4>Info</h4>\n        ";
  options = {hash:{},data:data};
  stack2 = ((stack1 = helpers.inputField),stack1 ? stack1.call(depth0, "name", "Business Name", depth0.name, true, options) : helperMissing.call(depth0, "inputField", "name", "Business Name", depth0.name, true, options));
  if(stack2 || stack2 === 0) { buffer += stack2; }
  buffer += "\n        ";
  if (stack2 = helpers.addressBookContactTypeDropdown) { stack2 = stack2.call(depth0, {hash:{},data:data}); }
  else { stack2 = depth0.addressBookContactTypeDropdown; stack2 = typeof stack2 === functionType ? stack2.apply(depth0) : stack2; }
  if(stack2 || stack2 === 0) { buffer += stack2; }
  buffer += "\n        ";
  ...

现在我正在尝试使用带有 grunt-contrib-handlebars 的 grunt 来编译我的模板文件。我得到以下输出:

Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
  this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
  var stack1, functionType="function";


  if (stack1 = helpers.addressBookContactFormPropertyItem) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
  else { stack1 = depth0.addressBookContactFormPropertyItem; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
  if(stack1 || stack1 === 0) { return stack1; }
  else { return ''; }
  })

Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
  this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};



  return "<div class=\"address-book-property-selection-wrapper\">\n <div class=\"dk_container dk_theme_default\" id=\"dk_container_address-book-properties-input\" style=\"display: block;\">\n     <a class=\"dk_toggle\"><span class=\"dk_label\">Property</span></a>\n   </div>\n    <div class=\"address-book-properties-container\">\n     <div class=\"address-book-properties-search-container\">\n          <input type=\"text\" class=\"span3\" id=\"address-book-properties-search-input\" placeholder=\"\" />\n      </div>\n        <ul class=\"collection\"></ul>\n    </div>\n</div>";
  })

Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
  this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); partials = this.merge(partials, Handlebars.partials); data = data || {};
  var buffer = "", stack1, stack2, options, functionType="function", escapeExpression=this.escapeExpression, self=this, helperMissing=helpers.helperMissing;


  buffer += "<form class=\"dark-bg\">\n  <input type=\"hidden\" id=\"propertyId-input\" name=\"propertyId\" value=\"";
  if (stack1 = helpers.propertyId) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
  else { stack1 = depth0.propertyId; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
  buffer += escapeExpression(stack1)
    + "\"/>\n\n  ";
  ...

有人可以就这种情况提出一些建议吗?我无法弄清楚为什么输出不同以及如何使我的 grunt 输出与手动 npm handlebars 编译相同。

最佳答案

输出不同是因为你的编译器版本不同。

关于javascript - grunt-contrib-handlebars 输出不同于 handlebars npm 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17711775/

相关文章:

javascript - 当我有多个元素时,多选 Lookup onChange 事件不会触发

javascript - 如何设置多个元素的 z-index 并使用模态内的 javascript 动态更新它们?

build - 如何以编程方式构建 Visual Studio 解决方案?

c - 为什么在转换 const 双索引参数时会收到 -Wincompatible-pointer-types 警告但是

node.js - 我的 node.js Web 应用无法识别我的 manifest.json

javascript - Angular 中使用模态窗口进行 Ng 重复和自动完成选择

javascript - 我怎样才能从 Angular 打开子窗口?

compilation - gfortran:非法预处理器指令和无效字符/非数字字符编译错误

javascript - 如何从模板中提取 Handlebars 列表?

handlebars.js - 如何在 mustache 模板中添加评论?