Skip to content
Babel plugin to replace tagged template strings with precompiled HTMLBars templates
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib address PR feedback Aug 23, 2018
tests address PR feedback Aug 23, 2018
.eslintrc.js
.gitignore
.travis.yml TravisCI: Remove deprecated `sudo: false` option Dec 1, 2018
CHANGELOG.md
README.md
index.js Merge pull request #40 from ember-cli/nit Aug 24, 2018
jest-eslint.config.js
jest-test.config.js Use Jest to run ESLint checks Mar 23, 2018
package.json
yarn.lock [Security] Bump handlebars from 4.0.11 to 4.1.0 Feb 14, 2019

README.md

babel-plugin-htmlbars-inline-precompile Build Status

Babel plugin to replace ES6 tagged template strings with the HTMLBars.precompiled version of it:

import hbs from 'htmlbars-inline-precompile';

module("my view");

test("inline templates ftw", function(assert) {
  var view = Ember.View.create({
    greeting: "inline template world",
    template: hbs`
      <span>hello {{view.greeting}}</span>
    `
  });

  view.appendTo('#testing');

  assert.equal(view.$().html().trim(), "<span>hello inline template world</span>");
});

results in

module("my view");

test("inline templates ftw", function(assert) {
  var view = Ember.View.create({
    greeting: "inline template world",
    template: Ember.HTMLBars.template(function() {
      /* crazy HTMLBars template function stuff */
    })
  });

  view.appendTo('#testing');

  assert.equal(view.$().html().trim(), "<span>hello inline template world</span>");
});

If the template is compact, a normal string can be passed as argument as well:

import hbs from 'htmlbars-inline-precompile';

module("my view");

test("inline templates ftw", function(assert) {
  var view = Ember.View.create({
    greeting: "inline template world",
    template: hbs('<h1>{{view.greeting}}</h1>')
  });

  view.appendTo('#testing');

  assert.equal(view.$().html().trim(), "<h1>inline template world</h1>");
});

Usage

var HTMLBarsCompiler = require('./bower_components/ember/ember-template-compiler');
var HTMLBarsInlinePrecompile = require('babel-plugin-htmlbars-inline-precompile');

require('babel').transform("code", {
  plugins: [
    [HTMLBarsInlinePrecompile, {precompile: HTMLBarsCompiler.precompile}],
  ],
});
You can’t perform that action at this time.