New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sync-views

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sync-views

Synchronous template rendering for node.js

latest
Source
npmnpm
Version
0.3.1
Version published
Weekly downloads
7
600%
Maintainers
1
Weekly downloads
 
Created
Source

sync-views

Build Status Coverage Status

Template rendering consolidation library. This module is a fork of co-views. You probably should use co-views except you have to render templates synchronously.

Notes

  • To use React, both react and react-dom need to be installed. Also react component needs to be transpiled beforehand.

Supported template engines

Installation

$ npm install sync-views

And install whichever engine(s) you use:

$ npm install react react-dom jade

Options

  • map an object mapping extension names to engine names [{}]. If not provided, default to [{ jade: 'jade', js: 'react' }]
  • default default extension name to use when missing [html]
  • cache cached compiled functions [NODE_ENV != 'development']

map

For example if you wanted to use "react" for .js files you would simply pass:

{ map: { js: 'react' } }

default

Set the default template extension when none is passed to the render function. This defaults to "jade". For example if you mostly use Jade, then you'd likely want to assign this to:

{ default: 'jade' }

Allowing you to invoke render('user') instead of render('user.jade').

cache

When true compiled template functions will be cached in-memory, this prevents subsequent disk i/o, as well as the additional compilation step that most template engines perform. By default this is enabled when the NODE_ENV environment variable is anything but "development", such as "stage" or "production".

Example

Render several users with different template engines in parallel. View lookup is performed relative to the ./examples directory passed, and the "react" engine is mapped to ".js" files.

var views = require('sync-views');

var render = views('examples', {
  map: { js: 'react' }
});

var html = render('user', { user: tobi });
console.log(html);

App-wide views

Dependending on your choice of application structure, you may wish to share these same settings between all of your application, instead of constantly initializing sync-views. To do this simply create a views.js module and export the render function returned:

var views = require('sync-views');

module.exports = views('views', {
  map: {
    js: 'react',
  }
});

FAQs

Package last updated on 22 Feb 2017

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