ember-cli-htmlbars
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -47,8 +47,11 @@ 'use strict'; | ||
registerTransforms: function(registry) { | ||
var eachTransform = require('./ext/plugins/transform-each-in-to-hash'); | ||
var withTransform = require('./ext/plugins/transform-with-as-to-hash'); | ||
var TransformEachInToHash = require('./ext/plugins/transform-each-in-to-hash'); | ||
var TransformWithAsToHash = require('./ext/plugins/transform-with-as-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: eachTransform | ||
plugin: TransformEachInToHash | ||
}); | ||
@@ -58,3 +61,3 @@ | ||
name: 'transform-with-as-to-hash', | ||
plugin: withTransform | ||
plugin: TransformWithAsToHash | ||
}); | ||
@@ -64,5 +67,5 @@ }, | ||
astPlugins: function() { | ||
var plugins = this.app.registry.load('htmlbars-ast-plugin'); | ||
var pluginFunctions = plugins.map(function(plugin) { | ||
return plugin.plugin; | ||
var pluginWrappers = this.app.registry.load('htmlbars-ast-plugin'); | ||
var plugins = pluginWrappers.map(function(wrapper) { | ||
return wrapper.plugin; | ||
}); | ||
@@ -69,0 +72,0 @@ |
@@ -1,30 +0,25 @@ | ||
var Walker = require('htmlbars').Walker; | ||
function TransformEachInToHash() { | ||
// set later within HTMLBars to the syntax package | ||
this.syntax = null; | ||
} | ||
module.exports = function(ast) { | ||
var walker = new Walker(); | ||
TransformEachInToHash.prototype.transform = function(ast) { | ||
var pluginContext = this; | ||
var walker = new pluginContext.syntax.Walker(); | ||
var b = pluginContext.syntax.builders; | ||
walker.visit(ast, function(node) { | ||
if (validate(node)) { | ||
if (pluginContext.validate(node)) { | ||
var removedParams = node.sexpr.params.splice(0, 2); | ||
var keyword = removedParams[0].original; | ||
var stringNode = { | ||
type: 'StringLiteral', | ||
value: keyword, | ||
original: keyword | ||
}; | ||
// TODO: This may not be necessary. | ||
if (!node.sexpr.hash) { | ||
node.sexpr.hash = { | ||
type: 'Hash', | ||
pairs: [] | ||
}; | ||
node.sexpr.hash = b.hash(); | ||
} | ||
var hashPair = { | ||
type: 'HashPair', | ||
key: 'keyword', | ||
value: stringNode | ||
}; | ||
node.sexpr.hash.pairs.push(hashPair); | ||
node.sexpr.hash.pairs.push(b.pair( | ||
'keyword', | ||
b.string(keyword) | ||
)); | ||
} | ||
@@ -34,5 +29,5 @@ }); | ||
return ast; | ||
} | ||
}; | ||
function validate(node) { | ||
TransformEachInToHash.prototype.validate = function TransformEachInToHash_validate(node) { | ||
return (node.type === 'BlockStatement' || node.type === 'MustacheStatement') && | ||
@@ -43,2 +38,4 @@ node.sexpr.path.original === 'each' && | ||
node.sexpr.params[1].original === 'in'; | ||
} | ||
}; | ||
module.exports = TransformEachInToHash; |
@@ -1,30 +0,25 @@ | ||
var Walker = require('htmlbars').Walker; | ||
function TransformWithAsToHash() { | ||
// set later within HTMLBars to the syntax package | ||
this.syntax = null; | ||
} | ||
module.exports = function(ast) { | ||
var walker = new Walker(); | ||
TransformWithAsToHash.prototype.transform = function TransformWithAsToHash_transform(ast) { | ||
var pluginContext = this; | ||
var walker = new pluginContext.syntax.Walker(); | ||
var b = pluginContext.syntax.builders; | ||
walker.visit(ast, function(node) { | ||
if (validate(node)) { | ||
if (pluginContext.validate(node)) { | ||
var removedParams = node.sexpr.params.splice(1, 2); | ||
var keyword = removedParams[1].original; | ||
var stringNode = { | ||
type: 'StringLiteral', | ||
value: keyword, | ||
original: keyword | ||
}; | ||
// TODO: This may not be necessary. | ||
if (!node.sexpr.hash) { | ||
node.sexpr.hash = { | ||
type: 'Hash', | ||
pairs: [] | ||
}; | ||
node.sexpr.hash = b.hash(); | ||
} | ||
var hashPair = { | ||
type: 'HashPair', | ||
key: 'keywordName', | ||
value: stringNode | ||
}; | ||
node.sexpr.hash.pairs.push(hashPair); | ||
node.sexpr.hash.pairs.push(b.pair( | ||
'keywordName', | ||
b.string(keyword) | ||
)); | ||
} | ||
@@ -34,5 +29,5 @@ }); | ||
return ast; | ||
} | ||
}; | ||
function validate(node) { | ||
TransformWithAsToHash.prototype.validate = function TransformWithAsToHash_validate(node) { | ||
return node.type === 'BlockStatement' && | ||
@@ -43,2 +38,4 @@ node.sexpr.path.original === 'with' && | ||
node.sexpr.params[1].original === 'as'; | ||
} | ||
}; | ||
module.exports = TransformWithAsToHash; |
{ | ||
"name": "ember-cli-htmlbars", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "A library for adding htmlbars to ember CLI", | ||
@@ -34,4 +34,4 @@ "main": "index.js", | ||
"ember-template-compiler": "^1.9.0-alpha", | ||
"htmlbars": "^0.4.0" | ||
"htmlbars": "^0.5.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10653
235
+ Addedhtmlbars@0.5.0(transitive)
- Removedhtmlbars@0.4.2(transitive)
Updatedhtmlbars@^0.5.0