Skip to content

jonschlinkert/view-cache2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

template NPM version

Templates.

Install

Install with npm:

npm i template --save-dev

Usage

var Template = require('template');
var template = new Template();

API

Create a new instance of Template, optionally passing the default context and options to use.

  • context {Object}: Context object to start with.
  • options {Object}: Options to use.

Example:*

var Template = require('template');
var template = new Template();

Cache delimiters by name with the given options for later use.

  • name {String}: The name to use for the stored delimiters.
  • delims {Array}: Array of delimiter strings. See delims for details.
  • opts {Object}: Options to pass to delims. You can also use the options to override any of the generated delimiters.

Example:*

template.addDelims('curly', ['']);
template.addDelims('angle', ['<%', '%>']);
template.addDelims('es6', ['#{', '}'], {
// override the generated regex
interpolate: /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g
});

Specify by ext the delimiters to make active.

  • ext {String}
template.useDelims('curly');
template.useDelims('angle');
  • ext {String}: The parser stack to get.
  • returns {Object} Template: to enable chaining.

Get the parser stack for the given ext.

Register the given parser callback fn as ext. If ext is not given, the parser fn will be pushed into the default parser stack.

  • ext {String}
  • fn {Function|Object}: or options
  • returns {Object} parsers: to enable chaining.
// Push the parser into the default stack
template.registerParser(require('parser-front-matter'));

// Or push the parser into the `foo` stack
template.registerParser('foo', require('parser-front-matter'));

Define an async parser.

  • ext {String}
  • fn {Function|Object}: or options
  • fn {Function}: Callback function.
  • returns {Object} Template: to enable chaining.
// Default stack
template.parser(require('parser-front-matter'));

// Associated with `.hbs` file extension
template.parser('hbs', require('parser-front-matter'));

See parser-cache for the full range of options and documentation.

Register the given parser callback fn as ext. If ext is not given, the parser fn will be pushed into the default parser stack.

Define a synchronous parser.

  • ext {String}
  • fn {Function|Object}: or options
  • fn {Function}: Callback function.
  • returns {Object} Template: to enable chaining.
// Default stack
template.parser(require('parser-front-matter'));

// Associated with `.hbs` file extension
template.parser('hbs', require('parser-front-matter'));

See parser-cache for the full range of options and documentation.

Register the given parser callback fn as ext. If ext is not given, the parser fn will be pushed into the default parser stack.

Run a stack of sync or async parsers.

  • template {Object|String}: Either a string or an object.
  • stack {Array}: Optionally pass an array of functions to use as parsers.
  • options {Object}
  • returns {Object}: Normalize template object.

Examples:

var str = fs.readFileSync('a/b/c.md', 'utf8');
template.parse({path: 'a/b/c.md', content: str}, function (err, file) {
  if (err) console.log(err);
  console.log(file);
});

Optionally pass an array of parser functions as a section argument.

template.parse({path: 'a/b/c.md', content: str}, [a, b, c], function (err, file) {
  if (err) console.log(err);
  console.log(file);
});

See parser-cache for the full range of options and documentation.

Run a stack of parsers against the given template. If template is an object with a path property, then the extname is used to get the parser stack. If a stack isn't found on the cache the default noop parser will be used.

  • ext {String}
  • fn {Function|Object}: or options
  • options {Object}
  • returns {Object} Template: to enable chaining

Example:

var consolidate = require('consolidate')
template.engine('hbs', consolidate.handlebars);
template.engines('hbs');
// => {render: [function], renderFile: [function]}

See engine-cache for details and documentation.

Register the given view engine callback fn as ext. If only ext is passed, the engine registered for ext is returned. If no ext is passed, the entire cache is returned.

Get the engine registered for the given ext. If no ext is passed, the entire cache is returned.

  • ext {String}: The engine to get.
  • returns {Object}: Object of methods for the specified engine.

Example:

var consolidate = require('consolidate')
template.engine('hbs', consolidate.handlebars);
template.getEngine('hbs');
// => {render: [function], renderFile: [function]}
engine.getEngine('.html');

Assign mixin fn to name or return the value of name if no other arguments are passed.

  • name {String}: The name of the mixin to add.
  • fn {Function}: The actual mixin function.

This method sets mixins on the cache, which will later be passed to a template engine that uses mixins, such as Lo-Dash or Underscore.

Register a helper for the given ext (engine).

  • ext {String}: The engine to register helpers with.
  • returns {Object}: Object of helpers for the specified engine.
engine.addHelper('lower', function(str) {
return str.toLowerCase();
});

Register helpers for the given ext (engine).

  • ext {String}: The engine to register helpers with.
  • returns {Object}: Object of helpers for the specified engine.
engine.helpers(require('handlebars-helpers'));
  • name {String}: The helper to cache or get.
  • fn {Function}: The helper function.
  • thisArg {Object}: Context to bind to the helper.
  • returns {Object}: Object of helpers for the specified engine.

Get and set generic helpers on the cache. Helpers registered using this method will be passed to every engine, so be sure to use generic javascript functions - unless you want to see Lo-Dash blow up from Handlebars.SafeString.

  • name {String}: The helper to cache or get.
  • fn {Function}: The helper function.
  • thisArg {Object}: Context to bind to the helper.
  • returns {Object}: Object of helpers for the specified engine.

Async version of .addHelper().

  • type {String}: Singular name of the type to create, e.g. page.

  • plural {String}: Plural name of the template type, e.g. pages.

  • options {Object}: Options for the template type.

    • isRenderable {Boolean}: Is the template a partial view?
    • layout {Boolean}: Can the template be used as a layout?
    • partial {Boolean}: Can the template be used as a partial?
  • returns {Object} Template: to enable chaining.

Add a new template type, along with associated get/set methods. You must specify both the singular and plural names for the type.

  • file {Object|String}: String or normalized template object.
  • options {Object}: Options to pass to registered view engines.
  • returns: {String}

Preprocess str with the given options and callback.

  • file {Object|String}: String or normalized template object.
  • options {Object}: Options to pass to registered view engines.
  • returns: {String}

Render content with the given options and callback.

  • file {Object|String}: String or normalized template object.
  • options {Object}: Options to pass to registered view engines.
  • returns: {String}

Render content with the given options and callback.

Related

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on September 28, 2014.

About

this is a temporary repo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published