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 
Load templates from file paths, globs or objects, and cache them as normalized objects.
This is a template loader, pure and simple, no rendering or caching.
Currently any of the following input configurations will return a normalized template object with the same root properties:
loader.load(['abc/*.hbs']);
loader.load('abc/*.md');
loader.load({'abc/def.md': {content: 'ghi.', lmn: 'xyz'});
loader.load({'abc/def.md': {content: 'ghi.'}}, {lmn: 'xyz'});
loader.load({path: 'abc/def.md', content: 'ghi.'}, {lmn: 'xyz'});
loader.load({path: 'abc/def.md', content: 'ghi.', lmn: 'xyz'});
loader.load('abc.md', 'def <%= name %>.');
loader.load('abc.md', 'def <%= name %>.', {name: 'Jon Schlinkert'});
Root properties
path
: file path or key to use for the template.data
: data from the parsed template, e.g. front-matter.locals
: locals pass on one of the loader methods. (keeping locals and data seperate allows you to merge however you need to.)content
: the parsed content of the templateorig
: the original content of the template, if parsed
Properties that are not on this list will be moved/copied to the data
object and retained on orig
.
Install
Install with npm:
npm i load-templates --save-dev
Run tests
npm test
API
loader
options
{Object}: Options to initializeloader
with
var loader = require('load-templates');
.load
Expand glob patterns, load, read, parse and normalize files from file paths, strings, objects, or arrays of these types.
key
{String|Object|Array}: Array, object, string or file paths.value
{String|Object}: String of content,file
object withcontent
property, orlocals
if the first arg is a file path.options
{Object}: Options orlocals
.returns
{Object}: Normalized file object.
Examples:
Filepaths or arrays of glob patterns.
var temlates = loader.load(['pages/*.hbs']);
var posts = loader.load('posts/*.md');
As strings or objects:
// loader.load(key, value, locals);
var docs = loader.load({'foo/bar.md': {content: 'this is content.'}}, {foo: 'bar'});
// loader.load(key, value, locals);
var post = loader.load('abc.md', 'My name is <%= name %>.', {name: 'Jon Schlinkert'});
.string
key
{String}: Glob patterns or file paths.value
{String|Object}: String of content,file
object withcontent
property, orlocals
if the first arg is a file path.options
{Object}: Options orlocals
.returns
{Object}: Normalized file object.
Expand glob patterns, load, read, parse and normalize files from file paths or strings.
.array
patterns
{Object}: Glob patterns or array of filepaths.options
{Object}: Options orlocals
returns
{Array}: Array of normalized file objects.
Normalize an array of patterns.
.object
file
{Object}: The object to normalize.options
{Object}: Options orlocals
Normalize a template object.
._cwd
filepath
{String}
The current working directory to use. Default is process.cwd()
.
.rename
filepath
{String}
Rename the key
of each template loaded using whatever rename function
is defined on the options. path.basename
is the default.
.parse
filepath
{String}: The path of the file to read/parse.Options
{Object}: Options orlocals
.
Parse the content of each template loaded using whatever parsing function
is defined on the options. fs.readFileSync
is used by default.
.normalize
file
{Object}: The template object to normalize.Options
{Object}: Options orlocals
.
Normalize a template using whatever normalize function is defined on the options.
Author
Jon Schlinkert
License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on September 04, 2014.