Skip to content
No description, website, or topics provided.
JavaScript HTML
Branch: master
Clone or download

Latest commit

dependabot-preview [Security] Bump acorn from 7.1.0 to 7.1.1
Bumps [acorn](https://github.com/acornjs/acorn) from 7.1.0 to 7.1.1. **This update includes a security fix.**
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](acornjs/acorn@7.1.0...7.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Latest commit be3c14d Mar 13, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Remove manual `yarn` installation Dec 4, 2019
config Reproduce inline precompilation failures when using ember-cli-htmlbar… Oct 1, 2019
lib fix: Standardize the option name for dependency invalidation. Feb 21, 2020
node-tests fix: Standardize the option name for dependency invalidation. Feb 21, 2020
public [fixes #113] Make an actual add-on so it can do comprehensive tests o… Jul 31, 2018
tests Remove usage of legacy `checker.forEmber` API. Feb 23, 2020
vendor [fixes #113] Make an actual add-on so it can do comprehensive tests o… Jul 31, 2018
.editorconfig [fixes #113] Make an actual add-on so it can do comprehensive tests o… Jul 31, 2018
.ember-cli [fixes #113] Make an actual add-on so it can do comprehensive tests o… Jul 31, 2018
.eslintignore Add prettier. Sep 8, 2019
.eslintrc.js Add test using native classes + decorators. Oct 19, 2019
.gitignore Add prettier. Sep 8, 2019
.jshintignore Add mocha-jshint for npm test. Feb 14, 2015
.jshintrc Add comma for parentRegistry, add .jshintrc file from ember-cli, and … Feb 13, 2015
.npmignore Update to ember-cli@3.5.0-beta.2 blueprint. Oct 11, 2018
.prettierrc.js Add prettier. Sep 8, 2019
.template-lintrc.js yarn lint:js --fix Sep 8, 2019
.watchmanconfig [fixes #113] Make an actual add-on so it can do comprehensive tests o… Jul 31, 2018
CHANGELOG.md Release 4.2.3 Feb 24, 2020
CODE_OF_CONDUCT.md Fix code of conduct markdown formatting Jul 21, 2015
LICENSE.md Add LICENSE.md. Apr 16, 2016
README.md Update Readme with syntax for usage with tagged templates Nov 11, 2019
RELEASE.md Add automated release setup. Sep 24, 2019
ember-cli-build.js Add test for colocation with AST plugins. Sep 30, 2019
package.json Bump @babel/core from 7.8.4 to 7.8.7 Mar 10, 2020
testem.js Increase browser start timeout. Dec 4, 2019
yarn.lock [Security] Bump acorn from 7.1.0 to 7.1.1 Mar 13, 2020

README.md

Ember CLI HTMLBars

Build Status

Registering a Plugin

var SomeTransform = require('./some-path/transform');

module.exports = {
  name: 'my-addon-name',

  included: function() {
    // we have to wrap these in an object so the ember-cli
    // registry doesn't try to call `new` on them (new is actually
    // called within htmlbars when compiling a given template).
    this.app.registry.add('htmlbars-ast-plugin', {
      name: 'some-transform',
      plugin: SomeTransform
    });
  }
};

Options for registering a htmlbars-ast-plugin

  • name - String. The name of the AST transform for debugging purposes.
  • plugin - A function of type ASTPluginBuilder.
  • dependencyInvalidation - Boolean. A flag that indicates the AST Plugin may, on a per-template basis, depend on other files that affect its output.
  • cacheKey - function that returns any JSON-compatible value - The value returned is used to invalidate the persistent cache across restarts, usually in the case of a dependency or configuration change.
  • baseDir - () => string. A function that returns the directory on disk of the npm module for the plugin. If provided, a basic cache invalidation is performed if any of the dependencies change (e.g. due to a npm install/upgrade).

Implementing Dependency Invalidation in an AST Plugin

Plugins that set the dependencyInvalidation option to true can provide function for the plugin of type ASTDependencyPlugin as given below.

Note: the plugin function is invoked without a value for this in context.

import {ASTPluginBuilder, ASTPlugin} from "@glimmer/syntax/dist/types/lib/parser/tokenizer-event-handlers";

export type ASTDependencyPlugin = ASTPluginWithDepsBuilder | ASTPluginBuilderWithDeps;

export interface ASTPluginWithDepsBuilder {
  (env: ASTPluginEnvironment): ASTPluginWithDeps;
}

export interface ASTPluginBuilderWithDeps extends ASTPluginBuilder {
  /**
   * @see {ASTPluginWithDeps.dependencies} below.
   **/
  dependencies(relativePath): string[];
}

export interface ASTPluginWithDeps extends ASTPlugin {
  /**
   * If this method exists, it is called with the relative path to the current
   * file just before processing starts. Use this method to reset the
   * dependency tracking state associated with the file.
   */
  resetDependencies?(relativePath: string): void;
  /**
   * This method is called just as the template finishes being processed.
   *
   * @param relativePath {string} A relative path to the file that may have dependencies.
   * @return {string[]} paths to files that are a dependency for the given
   * file. Any relative paths returned by this method are taken to be relative
   * to the file that was processed.
   */
  dependencies(relativePath: string): string[];
}

Precompile HTMLBars template strings within other addons

module.exports = {
  name: 'my-addon-name',

  setupPreprocessorRegistry: function(type, registry) {
    var htmlbarsPlugin = registry.load('template').find(function(plugin) {
      return plugin.name === 'ember-cli-htmlbars';
    });

    // precompile any htmlbars template string via the precompile method on the
    // ember-cli-htmlbars plugin wrapper; `precompiled` will be a string of the
    // form:
    //
    //   Ember.HTMLBars.template(function() {...})
    //
    var precompiled = htmlbarsPlugin.precompile("{{my-component}}");
  }
};

Tagged Template Usage / Migrating from htmlbars-inline-precompile

Starting with version 4.0, this addon now includes the testing helper from ember-cli-htmlbars-inline-precompile

This will require an update to the imports of the hbs helper in your tests:

Prior syntax:

import hbs from 'htmlbars-inline-precompile';

...

await render(hbs`
  <MyComponent />
`);

New syntax:

import { hbs } from 'ember-cli-htmlbars';

...

await render(hbs`
  <MyComponent />
`);

There is a codemod available to automate this change.

Handlebars 2.0 Support (Ember < 1.10)

Handlebars 2.0 support has been removed. If you are using ember-cli-htmlbars with a 1.9.x project please continue to use ember-cli-htmlbars@0.6.x.

Using as a Broccoli Plugin

var HtmlbarsCompiler = require('ember-cli-htmlbars');

var templateTree = new HtmlbarsCompiler('app/templates', {
  isHTMLBars: true,

  // provide the templateCompiler that is paired with your Ember version
  templateCompiler: require('./bower_components/ember/ember-template-compiler')
});
You can’t perform that action at this time.