README
Templatefy
Templatefy is a html template manager with js injection, angular supported.
Table of contents
- Installation
- CLI Usage
- API Usage
- Live Examples
- Documentation
- Contributing
- Community
- Creators
- Copyright and license
Installation
Install with npm install templatefy --save
.
CLI (Command line interface)
You can use Templatefy as command line tool, installing as global library with npm i -g templatefy
and execute with the command templatefy
.
To show options type: templatefy --help
or with flag -h
.
Options
Usage: /usr/local/bin/node templatefy [options]
Options:
-i, --input Input html file or string raw template
-o, --output Output compiled JavaScript file template
-s, --scope Enable scope function to prevent collition declarations [false]
-e, --exports Exports the template using commonjs module exports [false]
-r, --var Store the template into a variable
-g, --global Store the template into a global property <global:property>
-a, --angular Enable Angular templateCache injection; for angular options use --angular-<option-name> [false]
-l, --linter Enable Linter validation; for linter options use --linter-<option-name> [false]
-m, --minify Enable HTML minification process; for log options use --minify-<option-name> [false]
-V, --log Enable log output; for minify options use --log-<option-name> [false]
-v, --version Print version and exit
Usage
This example shows how to pass through stdin a template obtaining the output to the stdout:
echo '<h1>Foo</h1>' | templatefy --var=example
# ouput
# var example = '<h1>Foo</h1>';
As you can see it's possible use any string passed into the templatefy stdin, another example using the command cat
:
cat index.html | templatefy --exports
# ouput
# module.exports = '<h1>Foo</h1>';
If want parse a html file using the command arguments, you can define the file path using --input
and --ouput
to define the output result
By default if you don't define --output
it be will print the result in the promt stdout.
echo '<h1>Foo</h1>' > template.html
cat template.html | templatefy --exports
# or
templatefy --input=./template.html --exports
# or
templatefy --input="<h1>Foo</h1>" --exports
# ouput
# module.exports = '<h1>Foo</h1>';
cat template.html | templatefy --exports --ouput=./ouput.js
# contents of ouput.js
# module.exports = '<h1>Foo</h1>';
Note: You can copy any pice of code from above and paste in your terminal. Try it!.
API (Application Programming Interface)
Options
scope
Type: Boolean
Default: false
Enable function clousure for prevent variable collisions.
exports
Type: Boolean
Default: false
Enable commonjs module.exports.
global
Type: String
Default: null
Global variable expose global:property
.
var
Type: String
Default: null
Local variable name.
angular
Type: Boolean
Object
Default: false
Enable angular templateCache injection.
angular.shim
Type: String
Default: angular
Angular variable name or factory.
angular.module.name
Type: String
Default: templatefy
Angular templatefy module name.
angular.module.var
Type: String
Default: templatefy
Angular templatefy module variable name.
angular.module.name
Type: String
Default: templatefy
Angular templatefy module name.
angular.module.deps
Type: Array
String
Default: null
Angular templatefy module dependencies.
angular.module.run.args
Type: Array
String
Default: null
Angular templatefy module run dependencies.
angular.template
Type: Array
String
Default: null
Angular templatefy template name.
Usage
To use, add the require
node module:
const Templatefy = require('templatefy');
Templatefy.parse('path/of/input-file.html', 'path/of/ouput-file.js');
path/of/input-file.html
)
Input ( <h1><h2><h3>
path/of/ouput-file.js
)
Output ( '<h1><h2><h3></h3></h2></h1>'
Live examples
Thanks to tonicdev.com you can test the bellow examples.
const Templatefy = require("templatefy")
Templatefy.parse({
angular: true
},'<h1>{{Title}}<h2>{{Subtitle}}', function(err, data){
console.log(data);
});
Documentation (WIP)
I'm working hard to develop the documentation a soon as possible, sorry for the inconvenience.
Contributing (WIP)
WIP
Community
Get updates on Templatefy's development and chat with the project maintainers and community members.
- Follow me on @rubeniskov on Twitter to get updates.
- Read and subscribe to The Official Templatefy Page (WIP).
- Join the official Slack room.
- Chat with fellow templatefiers in IRC. On the
rubeniskov.irc.slack.com
server, in the##templatefy
channel. - Developers should use the keyword
templatefy
on packages which modify or add to the functionality of Templatefy when distributing through npm or similar delivery mechanisms for maximum discoverability.
Creators
Rubén López Gómez me@rubeniskov.com
Copyright and license
Code copyright 2016 Rubeniskov released under the MIT license.