0.1.1 • Published 8 years ago
templicated v0.1.1
Templicated
Intro
A build step that manages Jade templates for use in JavaScript applications. Here's a demo of it being used.
Installation
via npm
npm i templicated --save
Example build step
var templicated = require('templicated'),
fs = require('fs');
fs.readFile('app.js', function(e, input) {
if (e !== null) {
throw e;
}
var code = (
new templicated.Templicated(input, {
views: './views/'
})
).code;
fs.writeFile('output.js', code);
});
becomes
var $templicated = (function() {
function Templicated(tpls) {
this.tpls = tpls;
}
Templicated.prototype['get'] = function(which) {
return this.tpls[which];
}
return new Templicated({"1997400446":"<h1>Hello World</h1>"});
})();
console.log($templicated.get('1997400446'));
Exmaple usuage with Vue
var vm = new Vue({
el: '#app',
template: '@tpl.Master'
});
becomes
var $templicated = (function() {
function Templicated(tpls) {
this.tpls = tpls;
}
Templicated.prototype['get'] = function(which) {
return this.tpls[which];
}
return new Templicated({"1997400446":"<h1>Hello World</h1>"});
})();
var vm = new Vue({
el: '#app',
template: $templicated.get('1997400446')
});
API
constructor(input: Buffer|string, options: Config)
input
is either a Buffer or a string of the source JavaScript
options
is an object containing 1 required property: views
which is the directory of where to start finding templates.
.compile(void): Buffer
Returns a Buffer of the new source with Jade templates.
.code: string
Returns a string of the new source with Jade templates.
Build
npm i tsc typings -g
npm i
typings i
npm run build
License
Copyright(c) 2016 Marais Rossouw