JSPM

  • Created
  • Published
  • Downloads 51766
  • Score
    100M100P100Q178287F
  • License MIT

Load templates/views using globs, file paths, objects, arrays, or key-value pairs.

Package Exports

  • load-templates

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (load-templates) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

load-templates NPM version NPM downloads Build Status

Load templates/views using globs, file paths, objects, arrays, or key-value pairs.

Install

Install with npm:

$ npm install load-templates --save

Usage

In addition to what's shown in the below examples, if a glob pattern or valid filepath is passed, a stat object will be added to the file object as well.

var loader = require('load-templates');
// optionally pass an object to use for caching the views
var cache = {};
var views = loader(cache);

load views from objects

views({
  a: {path: 'a'},
  b: {path: 'b'},
  c: {path: 'c'}
});

from key-value pairs

views('d', {path: 'd'});
views('e', {path: 'e'});
views('f', {path: 'f'});

from globs or file paths

views(['views/*.js']); 

Results

All of the above examples combined result in:

{
  a: {path: 'a'},
  b: {path: 'b'},
  c: {path: 'c'},
  d: {path: 'd'},
  e: {path: 'e'},
  f: {path: 'f'},
  g: {path: 'g'},
  h: {path: 'h'},
  i: {path: 'i'},
  j: {path: 'j'}
}

Options

options.cwd

Special (leading) characters are expanded on options.cwd

  • ~ expands to user home. example: {cwd: '~/foo'}
  • @ expands to global npm modules. example: {cwd: '@/bar'}

options.renameKey

Rename the key of each file object.

Type: Function

Default: noop Full filepath or whatever key is passed.

glob options

All options are also passed to matched.

You might also be interested in these projects:

  • assemble: Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… more | homepage
  • templates: System for creating and managing template collections, and rendering templates with any node.js template engine.… more | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with [verb][]:

$ npm install verb && npm run docs

Or, if [verb][] is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v0.9.0, on May 07, 2016.