cortex-handlebars-compiler
Advanced tools
Comparing version 0.1.0 to 0.1.1
72
index.js
@@ -6,2 +6,4 @@ 'use strict'; | ||
var handlebars = require('handlebars'); | ||
var hashmaps = require('neuron-hashmaps'); | ||
var node_path = require('path'); | ||
@@ -12,8 +14,21 @@ function compiler (options) { | ||
// @param {Object} options | ||
// - shrinkWrap {Object} | ||
// - pkg {Object} | ||
// - root {path} root directory of packages | ||
function Compiler (options) { | ||
this.facade_counter = 0; | ||
this.neuron_hashmaps = hashmaps(options.shrinkWrap); | ||
this.pkg = options.pkg; | ||
this.root = options.root; | ||
this.ext = options.ext || '.js'; | ||
this.register('facade', function (title, helper_options) { | ||
return this._facade_handler(title, helper_options); | ||
}.bind(this)); | ||
} | ||
// Register a custom helper | ||
// @param {String} helper | ||
@@ -25,5 +40,7 @@ // @param {function(title, options)} handler | ||
handlebars.registerHelper(helper, handler); | ||
return this; | ||
}; | ||
// Comple the template | ||
Compiler.prototype.compile = function(template) { | ||
@@ -34,4 +51,51 @@ return handlebars.compile(template); | ||
Compiler.prototype.method_name = function(first_argument) { | ||
}; | ||
Compiler.prototype._facade_handler = function(title, options) { | ||
var output = ''; | ||
if (this.facade_counter ++ === 0) { | ||
output += this._neuron_framework(); | ||
} | ||
output += [ | ||
'<script>', | ||
'facade({', | ||
"mod:'" + title + "'", | ||
'});', | ||
'</script>' | ||
].join(''); | ||
return output; | ||
}; | ||
Compiler.prototype._neuron_framework = function() { | ||
return this._output_engines() + this._neuron_config(); | ||
}; | ||
Compiler.prototype._output_engines = function() { | ||
var self = this; | ||
return this.neuron_hashmaps | ||
.engines(this.pkg.name, this.pkg.version) | ||
.map(function (engine) { | ||
var src = self._normalize(engine.name, engine.version); | ||
return '<script src="' + src + '"></script>'; | ||
}) | ||
.join(''); | ||
}; | ||
Compiler.prototype._neuron_config = function() { | ||
return '' + [ | ||
'<script>', | ||
'neuron.config({', | ||
'ranges:' + JSON.stringify(this.neuron_hashmaps.ranges) + ',', | ||
'depTree:' + JSON.stringify(this.neuron_hashmaps.depTree) + ',', | ||
'});', | ||
'</script>' | ||
].join(''); | ||
}; | ||
Compiler.prototype._normalize = function(name, version) { | ||
return node_path.join(this.root, name, version, name + this.ext); | ||
}; |
{ | ||
"name": "cortex-handlebars-compiler", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Handlebar helpers for cortex template.", | ||
@@ -30,8 +30,10 @@ "main": "index.js", | ||
"mocha": "*", | ||
"chai": "*" | ||
"chai": "*", | ||
"jsonfile": "~1.1.1" | ||
}, | ||
"dependencies": { | ||
"handlebars": "~2.0.0-alpha.4", | ||
"shrinked": "~0.1.2" | ||
"handlebars": "^2.0.0-alpha.4", | ||
"shrinked": "^0.1.2", | ||
"neuron-hashmaps": "^1.0.0" | ||
} | ||
} |
'use strict'; | ||
var expect = require('chai').expect; | ||
var cortex_handlebars_compiler = require('../'); | ||
var compiler = require('../'); | ||
var fs = require('fs'); | ||
var jf = require('jsonfile'); | ||
var node_path = require('path'); | ||
var template = '<html><head></head><body>{{{facade "cortex-hybrid-sample"}}}</body></html>'; | ||
var fixtures = node_path.join(__dirname, 'fixtures'); | ||
var cortex_json = node_path.join(fixtures, 'cortex.json'); | ||
var shrinkwrap_json = node_path.join(fixtures, 'cortex-shrinkwrap.json'); | ||
var expected_html = node_path.join(fixtures, 'expected.html'); | ||
var pkg = jf.readFileSync(cortex_json); | ||
var shrinkwrap = jf.readFileSync(shrinkwrap_json); | ||
var expected = fs.readFileSync(expected_html).toString(); | ||
var c = compiler({ | ||
pkg: pkg, | ||
shrinkWrap: shrinkwrap, | ||
root: '../../../', | ||
ext: '.min.js' | ||
}); | ||
describe("compiler()", function(){ | ||
it(".compile(template)()", function(){ | ||
var fn = c.compile(template); | ||
expect(fn()).to.equal(expected); | ||
}); | ||
}); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
7691
11
153
3
3
1
+ Addedneuron-hashmaps@^1.0.0
+ Addedneuron-hashmaps@1.1.1(transitive)
Updatedhandlebars@^2.0.0-alpha.4
Updatedshrinked@^0.1.2