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

layouts

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

layouts

Wrap templates with layouts. Layouts can be nested and optionally use other layouts.

  • 0.5.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32K
increased by0.12%
Maintainers
2
Weekly downloads
 
Created
Source

layouts NPM version

Wrap templates with layouts. Layouts can be nested and optionally use other layouts.

Install

npm
npm i layouts --save

Usage

var layouts = require('layouts');

API

Heads up! Although most of the examples use <%= foo %> syntax for delimiters, you can change these to be whatever you need.

.loader

  • options {Object}

Initilize the template loader with the given options. By default [load-templates] is used.

.setLayout

Store a template on the cache by its name, the layout to use, and the template's `content.

  • name {String|Object}: If name is a string, layout and content are required.
  • data {String|Object}: Pass a string defining the name of layout to use for the given template, or pass an object with a layout property.
  • content {String}: The template "content", this will not be compiled or rendered.

Example:

layouts.setLayout('a', 'b', '<h1>Foo</h1>\n<%= body %>\n');

.pickLayout

Get the layout to use for a template by looking for a layout property on the template object.

  • template {Object}: The template object.
  • returns {String}: The name of the layout to use.

Example:

layouts.pickLayout('a');
//=> 'b'

.getLayout

Get a cached layout template by key.

  • key {String}: The key to lookup. This is often a full filepath or file name.
  • returns: {Object}

Example:

layouts.getLayout('foo');
//=> { layout: 'b', content: '<h1>Foo</h1>\n<%= body %>\n' }

.stack

Reduce a layout stack for a template into a single flattened layout. Pass the name of the layout defined for the template (e.g. the first layout in the stack).

  • name {String}: The layout to start with.
  • options {Object}
  • returns {Array}: The template's layout stack is returned as an array.

Example:

layouts.stack('base');

.replaceTag

Replace a <%= body %> tag with the given str. Custom delimiters and/or variable may be passed on the options. Unlike renderLayout, this method does not render templates, it only peforms a basic regex replacement.

  • str {String}: The string to use as a replacement value.
  • content {String}: A string with a <%= body %> tag where the str should be injected.
  • returns {String}: Resulting flattened content.

Example:

layouts.replaceTag('ABC', 'Before <%= body %> After');
//=> 'Before ABC After'

.renderLayout

Render a layout using Lo-Dash, by passing content (str), context and options.

  • str {String}: Content for the layout to render.
  • options {Object}: Additional options used for building the render settings.
  • returns {String}: Rendered string.

Example:

layouts.renderLayout(str, context, options);

Since this method uses Lo-Dash to process templates custom delimiters may be passed on the options.delims property. This allows layouts to be rendered prior to injecting "pages" or other str with templates that should not be rendered when the layout stack is processed.

Example:

layouts.renderLayout(str, context, {
  delims: ['<%','%>']
});

.render

Return an object with the string (str) and data required to build a final layout. This is useful if you need to use your own template engine to handle this final step.

  • str {String}: The string to be injected into the layout. Usually a page, or inner layout, etc.
  • name {String}: The name of the first layout to use to build the stack.
  • returns {Object}: Resulting flattened layout.

Example:

var page = layouts.render(str, 'base');
var tmpl = _.template(page, context);

Author

Jon Schlinkert

License

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


This file was generated by verb-cli on October 13, 2014.

Keywords

FAQs

Package last updated on 14 Oct 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