UNPKG

1.8 kBMarkdownView Raw
1# Ember CLI HTMLBars
2
3[![Build Status](https://travis-ci.org/ember-cli/ember-cli-htmlbars.svg?branch=master)](https://travis-ci.org/ember-cli/ember-cli-htmlbars)
4
5### Handlebars 2.0 Support
6
7Handlebars 2.0 support has been removed. If you are using ember-cli-htmlbars with a 1.9.x project please continue
8to use ember-cli-htmlbars@0.6.x.
9
10### Using as a Broccoli Plugin
11
12```javascript
13var HtmlbarsCompiler = require('ember-cli-htmlbars');
14
15var templateTree = new HtmlbarsCompiler('app/templates', {
16 isHTMLBars: true,
17
18 // provide the templateCompiler that is paired with your Ember version
19 templateCompiler: require('./bower_components/ember/ember-template-compiler')
20});
21```
22
23### Registering a Plugin
24
25```javascript
26var SomeTransform = require('./some-path/transform');
27
28module.exports = {
29 name: 'my-addon-name',
30
31 included: function() {
32 // we have to wrap these in an object so the ember-cli
33 // registry doesn't try to call `new` on them (new is actually
34 // called within htmlbars when compiling a given template).
35 this.app.registry.add('htmlbars-ast-plugin', {
36 name: 'some-transform',
37 plugin: SomeTransform
38 });
39 }
40};
41```
42
43### Precompile HTMLBars template strings within other addons
44
45```javascript
46module.exports = {
47 name: 'my-addon-name',
48
49 setupPreprocessorRegistry: function(type, registry) {
50 var htmlbarsPlugin = registry.load('template').find(function(plugin) {
51 return plugin.name === 'ember-cli-htmlbars';
52 });
53
54 // precompile any htmlbars template string via the precompile method on the
55 // ember-cli-htmlbars plugin wrapper; `precompiled` will be a string of the
56 // form:
57 //
58 // Ember.HTMLBars.template(function() {...})
59 //
60 var precompiled = htmlbarsPlugin.precompile("{{my-component}}");
61 }
62};
63```