Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-cli-htmlbars

Package Overview
Dependencies
Maintainers
2
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cli-htmlbars - npm Package Compare versions

Comparing version 0.5.4 to 0.6.0

bower.json

36

ember-addon-main.js
'use strict';
var path = require('path');
var htmlbarsCompile = require('./index');

@@ -22,3 +23,3 @@

return htmlbarsCompile(tree, { htmlbarsOptions: self.htmlbarsOptions() });
return htmlbarsCompile(tree, self.htmlbarsOptions());
}

@@ -28,7 +29,10 @@ })

emberPath: function() {
return path.join(this.project.root, this.app.bowerDirectory, 'ember');
},
htmlbarsOptions: function() {
var emberVersion = require(this.project.root + '/' + this.app.bowerDirectory + '/ember/bower.json').version;
var emberVersion = require(this.emberPath() + '/bower.json').version;
var projectConfig = this.app.project.config(this.app.env);
var htmlbarsEnabled = !/^1\.[0-9]\./.test(emberVersion);
var htmlbarsComponentGeneration = projectConfig.EmberENV.FEATURES['ember-htmlbars-component-generation'];

@@ -38,3 +42,5 @@ var htmlbarsOptions;

htmlbarsOptions = {
disableComponentGeneration: htmlbarsComponentGeneration !== true,
isHTMLBars: true,
FEATURES: projectConfig.EmberENV.FEATURES,
templateCompiler: require(path.join(this.emberPath(), 'ember-template-compiler')),

@@ -51,17 +57,11 @@ plugins: {

registerTransforms: function(registry) {
var TransformEachInToHash = require('./ext/plugins/transform-each-in-to-hash');
var TransformWithAsToHash = require('./ext/plugins/transform-with-as-to-hash');
//var TransformEachInToHash = require('./ext/plugins/transform-each-in-to-hash');
// 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).
registry.add('htmlbars-ast-plugin', {
name: 'transform-each-in-to-hash',
plugin: TransformEachInToHash
});
registry.add('htmlbars-ast-plugin', {
name: 'transform-with-as-to-hash',
plugin: TransformWithAsToHash
});
//// 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).
//registry.add('htmlbars-ast-plugin', {
// name: 'transform-each-in-to-hash',
// plugin: TransformEachInToHash
//});
},

@@ -68,0 +68,0 @@

var Filter = require('broccoli-filter');
var compile = require('./compile');
var handlbarsTemplateCompiler = require('ember-template-compiler');

@@ -12,5 +12,15 @@ function TemplateCompiler (inputTree, options) {

this.options = options || {};
this.htmlbarsOptions= this.options.htmlbarsOptions;
this.inputTree = inputTree;
if (this.options.isHTMLBars) {
this.precompile = this.options.templateCompiler.precompile;
this.templateWrapper = "export default Ember.HTMLBars.template(";
} else {
this.precompile = handlbarsTemplateCompiler.precompile;
this.templateWrapper = "export default Ember.Handlebars.template(";
}
this.registerPlugins();
this.initializeFeatures();
}

@@ -22,6 +32,32 @@

TemplateCompiler.prototype.targetExtension = 'js';
TemplateCompiler.prototype.registerPlugins = function registerPlugins() {
var plugins = this.options.plugins;
var templateCompiler = this.options.templateCompiler;
if (plugins && templateCompiler) {
for (var type in plugins) {
for (var i = 0, l = plugins[type].length; i < l; i++) {
templateCompiler.registerPlugin(type, plugins[type][i]);
}
}
}
};
TemplateCompiler.prototype.initializeFeatures = function initializeFeatures() {
var FEATURES = this.options.FEATURES;
var templateCompiler = this.options.templateCompiler;
if (FEATURES && templateCompiler) {
for (var feature in FEATURES) {
templateCompiler._Ember.FEATURES[feature] = FEATURES[feature];
}
}
};
TemplateCompiler.prototype.processString = function (string, relativePath) {
return compile(string, this.htmlbarsOptions);
return this.templateWrapper + this.precompile(string, false) + ');';
}
module.exports = TemplateCompiler;
{
"name": "ember-cli-htmlbars",
"version": "0.5.4",
"version": "0.6.0",
"description": "A library for adding htmlbars to ember CLI",
"main": "index.js",
"scripts": {
"prepublish": "bower install",
"test": "mocha test/*.js"

@@ -27,2 +28,3 @@ },

"devDependencies": {
"bower": "^1.3.12",
"broccoli": "^0.12.3",

@@ -34,5 +36,4 @@ "broccoli-concat": "0.0.11",

"broccoli-filter": "^0.1.6",
"ember-template-compiler": "^1.9.0-alpha",
"htmlbars": "^0.5.0"
"ember-template-compiler": "^1.9.0-alpha"
}
}
# Ember CLI HTMLBars
[![Build Status](https://travis-ci.org/rondale-sc/ember-cli-htmlbars.svg?branch=master)](https://travis-ci.org/rondale-sc/ember-cli-htmlbars)
### Using as a Broccoli Plugin
```javascript
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)
});
```
### Registering a Plugin
```javascript
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
});
}
};
```

@@ -7,3 +7,2 @@ 'use strict';

var templateCompilerFilter = require('../index');
var htmlbarsCompiler = require('htmlbars').compileSpec;
var handlbarsTemplateCompiler = require('ember-template-compiler');

@@ -23,12 +22,19 @@

describe('HTMLBars', function() {
var htmlbarsOptions;
var htmlbarsOptions, htmlbarsPrecompile;
beforeEach(function() {
htmlbarsOptions = {
disableComponentGeneration: true
isHTMLBars: true,
templateCompiler: require('../bower_components/ember/ember-template-compiler')
};
htmlbarsPrecompile = htmlbarsOptions.templateCompiler.precompile;
});
afterEach(function() {
});
it('precompiles templates into htmlbars', function(){
var tree = templateCompilerFilter(sourcePath, { htmlbarsOptions: htmlbarsOptions });
var tree = templateCompilerFilter(sourcePath, htmlbarsOptions);

@@ -39,3 +45,3 @@ builder = new broccoli.Builder(tree);

var source = fs.readFileSync(sourcePath + '/template.hbs', { encoding: 'utf8' });
var expected = "export default Ember.HTMLBars.template(" + htmlbarsCompiler(source) + ");";
var expected = "export default Ember.HTMLBars.template(" + htmlbarsPrecompile(source) + ");";

@@ -46,5 +52,9 @@ assert.equal(actual,expected,'They dont match!')

it('passes provided options to htmlbars', function(){
var tree = templateCompilerFilter(sourcePath, { htmlbarsOptions: htmlbarsOptions });
it('passes FEATURES to compiler', function(){
htmlbarsOptions.FEATURES = {
'ember-htmlbars-component-generation': true
};
var tree = templateCompilerFilter(sourcePath, htmlbarsOptions);
builder = new broccoli.Builder(tree);

@@ -54,3 +64,3 @@ return builder.build().then(function(results) {

var source = fs.readFileSync(sourcePath + '/web-component-template.hbs', { encoding: 'utf8' });
var expected = "export default Ember.HTMLBars.template(" + htmlbarsCompiler(source, htmlbarsOptions) + ");";
var expected = "export default Ember.HTMLBars.template(" + htmlbarsPrecompile(source) + ");";

@@ -70,3 +80,3 @@ assert.equal(actual,expected,'They dont match!')

var source = fs.readFileSync(sourcePath + '/non-standard-extension.handlebars', { encoding: 'utf8' });
var expected = 'export default Ember.Handlebars.template(' + handlbarsTemplateCompiler.precompile(source, false) + ')';
var expected = 'export default Ember.Handlebars.template(' + handlbarsTemplateCompiler.precompile(source, false) + ');';

@@ -80,3 +90,3 @@ assert.equal(actual,expected,'They dont match!')

var source = fs.readFileSync(sourcePath + '/template.hbs', { encoding: 'utf8' });
var expected = 'export default Ember.Handlebars.template(' + handlbarsTemplateCompiler.precompile(source, false) + ')';
var expected = 'export default Ember.Handlebars.template(' + handlbarsTemplateCompiler.precompile(source, false) + ');';

@@ -83,0 +93,0 @@ assert.equal(actual,expected,'They dont match!')

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc