Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

component-render

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

component-render

Render html files from template files for component

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

component-render

Build Status

Render html file from template file for component

Installation

With Component previously installed:

    $ npm install -g component-render

Usage


  Usage: component-render [options] <template>

  Options:

    -V, --version              
    -h, --help                 output usage information
    -l, --local <json>         local <json> file
    -o, --out <path>           output html file <path>
    -u, --use <name>           use the given render <name> plugin

Example

    # redner html file from template file
    $ component render simple.jade

    # render html file from template file with local json file
    $ component render -l user.json user.jade

    # render html file to output path
    $ component render -o ./static/html/simple.html simple.jade

    # render html file with plugin
    $ component render -u component-render-hogan -l user.json user.mustache

Template engine

Use Jade template engine. Hogan, EJS, and other template engine, you can support with plugin.

How to create plugin

You need to implement below function.

  • 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


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

MIT license.

See the LICENSE.

Keywords

FAQs

Package last updated on 17 Aug 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc