component-render
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,2 +1,12 @@ | ||
0.2.0 / 2013-08-16 | ||
================== | ||
* Support plugin | ||
0.1.1 / 2013-08-15 | ||
================== | ||
* Fixed dependency module | ||
* Fixed render html default file path | ||
0.1.0 / 2013-08-15 | ||
@@ -3,0 +13,0 @@ ================== |
@@ -7,2 +7,4 @@ 'use strict'; | ||
var jade = require('jade'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var debug = require('debug')('component-render'); | ||
@@ -17,3 +19,4 @@ | ||
if (program.local) { | ||
local = require(program.local); | ||
var resolve_path = path.resolve(program.local); | ||
local = fs.existsSync(resolve_path) ? require(resolve_path) : require(resolve_path + 'json'); | ||
} | ||
@@ -20,0 +23,0 @@ debug('local', local); |
{ | ||
"name": "component-render", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Render html files from template files for component", | ||
@@ -21,6 +21,6 @@ "keywords": [ | ||
"commander": "~1.1.1", | ||
"jade": "~0.31.0" | ||
"jade": "~0.31.0", | ||
"debug": "~0.7.2" | ||
}, | ||
"devDependencies": { | ||
"debug": "~0.7.2", | ||
"mocha": "*", | ||
@@ -27,0 +27,0 @@ "expect.js": "*" |
# component-render | ||
Render html files from template files for component | ||
[![Build Status](https://travis-ci.org/Frapwings/component-render.png?branch=master)](https://travis-ci.org/Frapwings/component-render) | ||
Render html file from template file for component | ||
## Installation | ||
With [Component](http://github.com/component/component) previously installed: | ||
With [Component](http://github.com/component/component) previously installed: | ||
@@ -28,2 +30,3 @@ ``` | ||
-o, --out <dir> output the compiled html to <dir> | ||
-u, --use <name> use the given render <name> plugin | ||
@@ -45,13 +48,43 @@ ``` | ||
# render html file with plugin | ||
$ component render -u component-render-hogan -l user.json user.mustache | ||
``` | ||
## template engine | ||
## Template engine | ||
Support `Jade` template engine. `Hogan`, `EJS`, and other template engine, you can support with plugin. | ||
## TODO | ||
## How to create plugin | ||
You need to implement below function. | ||
- `-u`, `--use` option | ||
- Function have `template`, `program` and `fn` arugments. | ||
- `template`: a template file path. | ||
- `program`: `commander` object. | ||
- `fn`: a callback function. specify `error`, `html` to arguments. | ||
### Plugin example | ||
```javascript | ||
var hogan = require('hogan.js'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
module.exports = function (template, program, fn) { | ||
var local = {}; | ||
if (program.local) { | ||
var resolve_path = path.resolve(program.local); | ||
local = fs.existsSync(resolve_path) ? require(resolve_path) : require(resolve_path + '.json'); | ||
} | ||
fs.readFile(template, { encoding: 'utf8' }, function (err, data) { | ||
if (err) { return fn(err); } | ||
var renderer = hogan.compile(data); | ||
var html = renderer.render(local); | ||
fn(null, html); | ||
}); | ||
}; | ||
``` | ||
## License | ||
@@ -58,0 +91,0 @@ |
@@ -13,3 +13,3 @@ 'use strict'; | ||
var TEMPLATE_FIXTURES_PATH = __dirname + '/fixtures/templates/user.jade'; | ||
var GENERATE_HTML_PATH = 'bin/user.html'; | ||
var GENERATE_HTML_PATH = 'user.html'; | ||
var LOCAL_PATH = __dirname + '/fixtures/user.json'; | ||
@@ -16,0 +16,0 @@ |
@@ -14,4 +14,4 @@ 'use strict'; | ||
var TEMPLATE_FIXTURES_PATH = __dirname + '/fixtures/templates/simple.jade'; | ||
var GENERATE_DIR = __dirname + '/fixtures/templates'; | ||
var GENERATE_HTML_PATH = __dirname + '/fixtures/templates/simple.html'; | ||
var GENERATE_DIR = __dirname + '/fixtures'; | ||
var GENERATE_HTML_PATH = __dirname + '/fixtures/simple.html'; | ||
@@ -18,0 +18,0 @@ |
@@ -79,4 +79,4 @@ 'use strict'; | ||
format('bin/component-render %s', path.join(TEMPLATE_FIXTURES_DIR, 'simple.jade')), | ||
commonDescribes('bin/simple.html', '<p>hello world</p>'), | ||
cleanup('bin/simple.html') | ||
commonDescribes('simple.html', '<p>hello world</p>'), | ||
cleanup('simple.html') | ||
); | ||
@@ -86,6 +86,6 @@ testTemplate( | ||
format('bin/component-render %s', path.join(TEMPLATE_FIXTURES_DIR, 'include.jade')), | ||
commonDescribes('bin/include.html', '<p>hello world</p>'), | ||
cleanup('bin/include.html') | ||
commonDescribes('include.html', '<p>hello world</p>'), | ||
cleanup('include.html') | ||
); | ||
}); // end of 'component-render' |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
19482
2
22
413
93
3
11
6
+ Addeddebug@~0.7.2
+ Addeddebug@0.7.4(transitive)