line generated templates with Ember?

I'm using precompiled templates for several reasons:

  • Performance (no need to re-compile at runtime)
  • Code separation (cleaner than embedding <script> tags and hardcoding in JS)
  • Content security policy (this is for an extension).
  • Basically, I'm generating templates.js via the handlebars command line utility, based on several template.handlebars files. Next I try to bring these templates into Ember with the following loop:

    for (var name in Handlebars.templates) {
      var template = Handlebars.templates[name];
      Ember.TEMPLATES[name] = template;
    }
    

    The result is weird: text seems to be loaded, but many template features (eg. {{outlet}} ) don't work. I suspect that this is because Handlebars and Ember-Handlebars are not the same thing.

    I guess there are two options (and questions):

  • Precompile Ember-friendly templates (how can I do this via a command line?)
  • Properly import Handlebars templates into Ember (how?)
  • UPDATE : As per the answer, Ember.Handlebars is not the same as Handlebars, so the precompilation is different. Wrote a simple script to precompile for Ember: https://gist.github.com/3723927


    Yes, the plain Handlebars compiler compiles to different JavaScript than Ember.Handlebars, so you cannot consume its output with Ember.

    I don't know of a way to run Ember.Handlebars through the command line, though it should be possible in principle to write something.

    To find out how to precompile with Ember.Handlebars, take a look at the source code of ember-rails - it supports precompilation.

    链接地址: http://www.djcxy.com/p/73454.html

    上一篇: EmberJS:无法找到属性“操作”

    下一篇: 线生成的模板与Ember?