ember-cli-htmlbars
Advanced tools
Comparing version 1.3.2 to 2.0.0
'use strict'; | ||
var path = require('path'); | ||
var VersionChecker = require('ember-cli-version-checker'); | ||
var utils = require('./utils'); | ||
var hashForDep = require('hash-for-dep'); | ||
const path = require('path'); | ||
const utils = require('./utils'); | ||
const hashForDep = require('hash-for-dep'); | ||
@@ -11,17 +10,5 @@ module.exports = { | ||
init: function() { | ||
if (this._super.init) { this._super.init.apply(this, arguments); } | ||
let checker = new VersionChecker(this); | ||
let dep = this.emberCLIDep = checker.for('ember-cli', 'npm'); | ||
dep.assertAbove('0.1.2'); | ||
}, | ||
parentRegistry: null, | ||
shouldSetupRegistryInIncluded: function() { | ||
return !this.emberCLIDep.isAbove('0.2.0'); | ||
}, | ||
setupPreprocessorRegistry: function(type, registry) { | ||
setupPreprocessorRegistry(type, registry) { | ||
// ensure that broccoli-ember-hbs-template-compiler is not processing hbs files | ||
@@ -34,10 +21,10 @@ registry.remove('template', 'broccoli-ember-hbs-template-compiler'); | ||
_addon: this, | ||
toTree: function(tree) { | ||
var htmlbarsOptions = this._addon.htmlbarsOptions(); | ||
toTree(tree) { | ||
let htmlbarsOptions = this._addon.htmlbarsOptions(); | ||
return require('./index')(tree, htmlbarsOptions); | ||
}, | ||
precompile: function(string) { | ||
var htmlbarsOptions = this._addon.htmlbarsOptions(); | ||
var templateCompiler = htmlbarsOptions.templateCompiler; | ||
precompile(string) { | ||
let htmlbarsOptions = this._addon.htmlbarsOptions(); | ||
let templateCompiler = htmlbarsOptions.templateCompiler; | ||
return utils.template(templateCompiler, string); | ||
@@ -52,19 +39,11 @@ } | ||
included: function (app) { | ||
this._super.included.apply(this, arguments); | ||
if (this.shouldSetupRegistryInIncluded()) { | ||
this.setupPreprocessorRegistry('parent', app.registry); | ||
} | ||
}, | ||
projectConfig: function () { | ||
projectConfig() { | ||
return this.project.config(process.env.EMBER_ENV); | ||
}, | ||
templateCompilerPath: function() { | ||
var config = this.projectConfig(); | ||
var templateCompilerPath = config['ember-cli-htmlbars'] && config['ember-cli-htmlbars'].templateCompilerPath; | ||
templateCompilerPath() { | ||
let config = this.projectConfig(); | ||
let templateCompilerPath = config['ember-cli-htmlbars'] && config['ember-cli-htmlbars'].templateCompilerPath; | ||
var ember = this.project.findAddonByName('ember-source'); | ||
let ember = this.project.findAddonByName('ember-source'); | ||
if (ember) { | ||
@@ -76,3 +55,3 @@ return ember.absolutePaths.templateCompiler; | ||
var absolutePath = path.resolve(this.project.root, templateCompilerPath); | ||
let absolutePath = path.resolve(this.project.root, templateCompilerPath); | ||
@@ -86,6 +65,6 @@ if (path.extname(absolutePath) === '') { | ||
htmlbarsOptions: function() { | ||
var projectConfig = this.projectConfig() || {}; | ||
var EmberENV = projectConfig.EmberENV || {}; | ||
var templateCompilerPath = this.templateCompilerPath(); | ||
htmlbarsOptions() { | ||
let projectConfig = this.projectConfig() || {}; | ||
let EmberENV = projectConfig.EmberENV || {}; | ||
let templateCompilerPath = this.templateCompilerPath(); | ||
@@ -102,5 +81,5 @@ // ensure we get a fresh templateCompilerModuleInstance per ember-addon | ||
global.EmberENV = EmberENV; // Needed for eval time feature flag checks | ||
var pluginInfo = this.astPlugins(); | ||
let pluginInfo = this.astPlugins(); | ||
var htmlbarsOptions = { | ||
let htmlbarsOptions = { | ||
isHTMLBars: true, | ||
@@ -125,18 +104,18 @@ EmberENV: EmberENV, | ||
astPlugins: function() { | ||
var pluginWrappers = this.parentRegistry.load('htmlbars-ast-plugin'); | ||
var plugins = []; | ||
var cacheKeys = []; | ||
astPlugins() { | ||
let pluginWrappers = this.parentRegistry.load('htmlbars-ast-plugin'); | ||
let plugins = []; | ||
let cacheKeys = []; | ||
for (var i = 0; i < pluginWrappers.length; i++) { | ||
var wrapper = pluginWrappers[i]; | ||
for (let i = 0; i < pluginWrappers.length; i++) { | ||
let wrapper = pluginWrappers[i]; | ||
plugins.push(wrapper.plugin); | ||
var providesBaseDir = typeof wrapper.baseDir === 'function'; | ||
var augmentsCacheKey = typeof wrapper.cacheKey === 'function'; | ||
let providesBaseDir = typeof wrapper.baseDir === 'function'; | ||
let augmentsCacheKey = typeof wrapper.cacheKey === 'function'; | ||
if (providesBaseDir || augmentsCacheKey) { | ||
if (providesBaseDir) { | ||
var pluginHashForDep = hashForDep(wrapper.baseDir()); | ||
let pluginHashForDep = hashForDep(wrapper.baseDir()); | ||
cacheKeys.push(pluginHashForDep); | ||
@@ -149,5 +128,3 @@ } | ||
// support for ember-cli < 2.2.0 | ||
var log = this.ui.writeDeprecateLine || this.ui.writeLine; | ||
log.call(this.ui, 'ember-cli-htmlbars is opting out of caching due to an AST plugin that does not provide a caching strategy: `' + wrapper.name + '`.'); | ||
this.ui.writeDeprecateLine('ember-cli-htmlbars is opting out of caching due to an AST plugin that does not provide a caching strategy: `' + wrapper.name + '`.'); | ||
cacheKeys.push((new Date()).getTime() + '|' + Math.random()); | ||
@@ -154,0 +131,0 @@ } |
153
index.js
'use strict'; | ||
var fs = require('fs'); | ||
var utils = require('./utils'); | ||
var Filter = require('broccoli-persistent-filter'); | ||
var crypto = require('crypto'); | ||
var stringify = require('json-stable-stringify'); | ||
var stripBom = require('strip-bom'); | ||
const fs = require('fs'); | ||
const utils = require('./utils'); | ||
const Filter = require('broccoli-persistent-filter'); | ||
const crypto = require('crypto'); | ||
const stringify = require('json-stable-stringify'); | ||
const stripBom = require('strip-bom'); | ||
function TemplateCompiler (inputTree, _options) { | ||
if (!(this instanceof TemplateCompiler)) { | ||
return new TemplateCompiler(inputTree, _options); | ||
} | ||
class TemplateCompiler extends Filter { | ||
constructor(inputTree, _options) { | ||
let options = _options || {}; | ||
var options = _options || {}; | ||
if (!options.hasOwnProperty('persist')) { | ||
options.persist = true; | ||
} | ||
if (!Object.hasOwnProperty(options, 'persist')) { | ||
options.persist = true; | ||
} | ||
Filter.call(this, inputTree, options); // this._super() | ||
super(inputTree, options); | ||
this.options = options || {}; | ||
this.inputTree = inputTree; | ||
this.options = options; | ||
this.inputTree = inputTree; | ||
this.precompile = this.options.templateCompiler.precompile; | ||
this.registerPlugin = this.options.templateCompiler.registerPlugin; | ||
this.precompile = this.options.templateCompiler.precompile; | ||
this.registerPlugin = this.options.templateCompiler.registerPlugin; | ||
this.registerPlugins(); | ||
this.initializeFeatures(); | ||
} | ||
this.registerPlugins(); | ||
this.initializeFeatures(); | ||
} | ||
TemplateCompiler.prototype = Object.create(Filter.prototype); | ||
TemplateCompiler.prototype.constructor = TemplateCompiler; | ||
TemplateCompiler.prototype.extensions = ['hbs', 'handlebars']; | ||
TemplateCompiler.prototype.targetExtension = 'js'; | ||
baseDir() { | ||
return __dirname; | ||
} | ||
TemplateCompiler.prototype.baseDir = function() { | ||
return __dirname; | ||
}; | ||
registerPlugins() { | ||
let plugins = this.options.plugins; | ||
TemplateCompiler.prototype.registerPlugins = function registerPlugins() { | ||
var plugins = this.options.plugins; | ||
if (plugins) { | ||
for (var type in plugins) { | ||
for (var i = 0, l = plugins[type].length; i < l; i++) { | ||
this.registerPlugin(type, plugins[type][i]); | ||
if (plugins) { | ||
for (let type in plugins) { | ||
for (let i = 0, l = plugins[type].length; i < l; i++) { | ||
this.registerPlugin(type, plugins[type][i]); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
TemplateCompiler.prototype.initializeFeatures = function initializeFeatures() { | ||
var EmberENV = this.options.EmberENV; | ||
var FEATURES = this.options.FEATURES; | ||
var templateCompiler = this.options.templateCompiler; | ||
initializeFeatures() { | ||
let EmberENV = this.options.EmberENV; | ||
let FEATURES = this.options.FEATURES; | ||
let templateCompiler = this.options.templateCompiler; | ||
if (FEATURES) { | ||
console.warn('Using `options.FEATURES` with ember-cli-htmlbars is deprecated. Please provide the full EmberENV as options.EmberENV instead.'); | ||
EmberENV = EmberENV || {}; | ||
EmberENV.FEATURES = FEATURES; | ||
if (FEATURES) { | ||
console.warn('Using `options.FEATURES` with ember-cli-htmlbars is deprecated. Please provide the full EmberENV as options.EmberENV instead.'); | ||
EmberENV = EmberENV || {}; | ||
EmberENV.FEATURES = FEATURES; | ||
} | ||
utils.initializeEmberENV(templateCompiler, EmberENV); | ||
} | ||
utils.initializeEmberENV(templateCompiler, EmberENV); | ||
}; | ||
processString(string, relativePath) { | ||
return 'export default ' + utils.template(this.options.templateCompiler, stripBom(string), { | ||
contents: string, | ||
moduleName: relativePath | ||
}) + ';'; | ||
} | ||
TemplateCompiler.prototype.processString = function (string, relativePath) { | ||
return 'export default ' + utils.template(this.options.templateCompiler, stripBom(string), { | ||
contents: string, | ||
moduleName: relativePath | ||
}) + ';'; | ||
}; | ||
_buildOptionsForHash() { | ||
let strippedOptions = {}; | ||
TemplateCompiler.prototype._buildOptionsForHash = function() { | ||
var strippedOptions = {}; | ||
for (let key in this.options) { | ||
if (key !== 'templateCompiler') { | ||
strippedOptions[key] = this.options[key]; | ||
} | ||
} | ||
for (var key in this.options) { | ||
if (key !== 'templateCompiler') { | ||
strippedOptions[key] = this.options[key]; | ||
return strippedOptions; | ||
} | ||
_templateCompilerContents() { | ||
if (this.options.templateCompilerPath) { | ||
return fs.readFileSync(this.options.templateCompilerPath, { encoding: 'utf8' }); | ||
} else { | ||
return ''; | ||
} | ||
} | ||
return strippedOptions; | ||
}; | ||
optionsHash() { | ||
if (!this._optionsHash) { | ||
this._optionsHash = crypto.createHash('md5') | ||
.update(stringify(this._buildOptionsForHash()), 'utf8') | ||
.update(stringify(this._templateCompilerContents()), 'utf8') | ||
.digest('hex'); | ||
} | ||
TemplateCompiler.prototype._templateCompilerContents = function() { | ||
if (this.options.templateCompilerPath) { | ||
return fs.readFileSync(this.options.templateCompilerPath, { encoding: 'utf8' }); | ||
} else { | ||
return ''; | ||
return this._optionsHash; | ||
} | ||
}; | ||
TemplateCompiler.prototype.optionsHash = function() { | ||
if (!this._optionsHash) { | ||
this._optionsHash = crypto.createHash('md5') | ||
.update(stringify(this._buildOptionsForHash()), 'utf8') | ||
.update(stringify(this._templateCompilerContents()), 'utf8') | ||
.digest('hex'); | ||
cacheKeyProcessString(string, relativePath) { | ||
return this.optionsHash() + Filter.prototype.cacheKeyProcessString.call(this, string, relativePath); | ||
} | ||
} | ||
return this._optionsHash; | ||
}; | ||
TemplateCompiler.prototype.extensions = ['hbs', 'handlebars']; | ||
TemplateCompiler.prototype.targetExtension = 'js'; | ||
TemplateCompiler.prototype.cacheKeyProcessString = function(string, relativePath) { | ||
return this.optionsHash() + Filter.prototype.cacheKeyProcessString.call(this, string, relativePath); | ||
}; | ||
module.exports = TemplateCompiler; |
{ | ||
"name": "ember-cli-htmlbars", | ||
"version": "1.3.2", | ||
"version": "2.0.0", | ||
"description": "A library for adding htmlbars to ember CLI", | ||
@@ -11,2 +11,5 @@ "main": "index.js", | ||
], | ||
"engines": { | ||
"node": ">= 4.0.0" | ||
}, | ||
"scripts": { | ||
@@ -37,13 +40,13 @@ "prepublish": "bower install", | ||
"broccoli": "^0.16.7", | ||
"broccoli-concat": "2.3.6", | ||
"broccoli-concat": "^3.2.2", | ||
"co": "^4.6.0", | ||
"mocha": "^3.0.2", | ||
"mocha-jshint": "^0.0.9" | ||
"mocha-jshint": "^2.3.1" | ||
}, | ||
"dependencies": { | ||
"broccoli-persistent-filter": "^1.0.3", | ||
"ember-cli-version-checker": "^1.0.2", | ||
"hash-for-dep": "^1.0.2", | ||
"json-stable-stringify": "^1.0.0", | ||
"strip-bom": "^2.0.0" | ||
"strip-bom": "^3.0.0" | ||
} | ||
} |
# Ember CLI HTMLBars | ||
[![Build Status](https://travis-ci.org/ember-cli/ember-cli-htmlbars.svg?branch=master)](https://travis-ci.org/ember-cli/ember-cli-htmlbars) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/b5njc8lsjce76mv6/branch/master?svg=true)](https://ci.appveyor.com/project/embercli/ember-cli-htmlbars/branch/master) | ||
@@ -5,0 +6,0 @@ ### Handlebars 2.0 Support |
12
utils.js
'use strict'; | ||
module.exports = { | ||
initializeEmberENV: function(templateCompiler, EmberENV) { | ||
initializeEmberENV(templateCompiler, EmberENV) { | ||
if (!templateCompiler || !EmberENV) { return; } | ||
var props; | ||
let props; | ||
@@ -12,3 +12,3 @@ if (EmberENV.FEATURES) { | ||
props.forEach(function(prop) { | ||
props.forEach(prop => { | ||
templateCompiler._Ember.FEATURES[prop] = EmberENV.FEATURES[prop]; | ||
@@ -21,3 +21,3 @@ }); | ||
props.forEach(function(prop) { | ||
props.forEach(prop => { | ||
if (prop === 'FEATURES') { return; } | ||
@@ -30,6 +30,6 @@ | ||
template: function(templateCompiler, string, options) { | ||
var precompiled = templateCompiler.precompile(string, options); | ||
template(templateCompiler, string, options) { | ||
let precompiled = templateCompiler.precompile(string, options); | ||
return 'Ember.HTMLBars.template(' + precompiled + ')'; | ||
} | ||
}; |
4
65
11652
6
211
+ Addedstrip-bom@3.0.0(transitive)
- Removedember-cli-version-checker@^1.0.2
- Removedember-cli-version-checker@1.3.1(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedsemver@5.7.2(transitive)
- Removedstrip-bom@2.0.0(transitive)
Updatedstrip-bom@^3.0.0