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

load-templates

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

load-templates

Load templates from file paths, globs or objects, and cache them as normalized objects.

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
54K
increased by16.93%
Maintainers
1
Weekly downloads
 
Created
Source

load-templates NPM version

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 template
  • orig: 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 initialize loader 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 with content property, or locals if the first arg is a file path.
  • options {Object}: Options or locals.
  • 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 with content property, or locals if the first arg is a file path.
  • options {Object}: Options or locals.
  • 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 or locals
  • returns {Array}: Array of normalized file objects.

Normalize an array of patterns.

.object

  • file {Object}: The object to normalize.
  • options {Object}: Options or locals

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 or locals.

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 or locals.

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 02, 2014.

Keywords

FAQs

Package last updated on 03 Sep 2014

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