Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/doowb/layouts
Wraps templates with layouts. Layouts can use other layouts and be nested to any depth. This can be used 100% standalone to wrap any kind of file with banners, headers or footer content. Use for markdown, HTML, handlebars views, lo-dash templates, etc. Layouts can also be vinyl files.
https://github.com/doowb/layouts
consolidate ejs express handlebars jade javascript layout layouts liquid nested-layouts templates vinyl vinyl-files
Last synced: 2 months ago
JSON representation
Wraps templates with layouts. Layouts can use other layouts and be nested to any depth. This can be used 100% standalone to wrap any kind of file with banners, headers or footer content. Use for markdown, HTML, handlebars views, lo-dash templates, etc. Layouts can also be vinyl files.
- Host: GitHub
- URL: https://github.com/doowb/layouts
- Owner: doowb
- License: mit
- Created: 2014-07-28T05:54:34.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-04-11T15:35:19.000Z (over 5 years ago)
- Last Synced: 2024-09-28T08:42:20.070Z (3 months ago)
- Topics: consolidate, ejs, express, handlebars, jade, javascript, layout, layouts, liquid, nested-layouts, templates, vinyl, vinyl-files
- Language: JavaScript
- Homepage:
- Size: 202 KB
- Stars: 28
- Watchers: 4
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# layouts [![NPM version](https://img.shields.io/npm/v/layouts.svg?style=flat)](https://www.npmjs.com/package/layouts) [![NPM monthly downloads](https://img.shields.io/npm/dm/layouts.svg?style=flat)](https://npmjs.org/package/layouts) [![NPM total downloads](https://img.shields.io/npm/dt/layouts.svg?style=flat)](https://npmjs.org/package/layouts) [![Linux Build Status](https://img.shields.io/travis/doowb/layouts.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/layouts)
> Wraps templates with layouts. Layouts can use other layouts and be nested to any depth. This can be used 100% standalone to wrap any kind of file with banners, headers or footer content. Use for markdown, HTML, handlebars views, lo-dash templates, etc. Layouts can also be vinyl files.
Please consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save layouts
```## Usage
```js
const renderLayouts = require('layouts');renderLayouts(file, layoutCollection, options);
```* `file` - a file object (or [vinyl](https://github.com/gulpjs/vinyl) file) with a `file.contents` property that must be a buffer
* `layoutCollection` - an object of file objects to use as layouts
* `options` - see [available options](#options)## Heads up!
This library does not clone the file object. If you want to prevent `file.contents` from being mutated (after rendering layouts), clone the file first before passing it to this library.
## Example
```js
const renderLayouts = require('layouts');const file = {
contents: Buffer.from('Wrap me with a layout!!!'),
layout: 'one'
};const layoutCollection = {
one: { contents: Buffer.from('one before\n{% body %}\none after'), layout: 'two' },
two: { contents: Buffer.from('two before\n{% body %}\ntwo after') }
};const res = renderLayouts(file, layoutCollection);
console.log(res.contents.toString());
// two before
// one before
//Wrap me with a layout!!!
// one after
// two after
```## Options
### options.disableHistory
**Type**: `boolean`
**Default**: `undefined`
By default, layouts are prevented from being applied multiple times to the same string. Disable this by setting `disableHistory` to true.
**Example**
```js
layouts(file, layoutCollection, { disableHistory: true });
```### options.layoutDelims
Custom delimiters to use for injecting contents into layouts.
**Type**: `regex`
**Default**: `/{% (body) %}/g`
### options.preserveWhitespace
Preserve leading whitespace when injecting a string into a layout.
**Type**: `boolean`
**Default**: `undefined`
## History
### 1.0.0
**Breaking changes**
* renames `layoutHistory` to `layoutStack`
* layouts in `layoutStack` are now the actual layout object, instead of the layout name**Added**
* Adds support for a function as the last argument. If passed, the function is called on the file and each layout with this signature: `fn(file, layout)`.
### 0.13.0
**Breaking changes**
* The main `layouts()` function now expects a `file` object as the first argument. This can be an object with `path`, `layout` and `contents` properties, or a valid [vinyl](https://github.com/gulpjs/vinyl) file. See the [API docs](#api) for more details.
### 0.12.0
**Breaking changes**
* change `options.tag` to `options.contentTag`
**Housekeeping**
* update tests to use `assert` instead of `should`
### 0.11.0
* All view objects must now have a `path` property, following [vinyl](https://github.com/gulpjs/vinyl) conventions.
## About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```### Related projects
You might also be interested in these projects:
* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit")
* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates "System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.")
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.")### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 151 | [jonschlinkert](https://github.com/jonschlinkert) |
| 26 | [doowb](https://github.com/doowb) |### Author
**Brian Woodward**
* [GitHub Profile](https://github.com/doowb)
* [Twitter Profile](https://twitter.com/doowb)
* [LinkedIn Profile](https://linkedin.com/in/woodwardbrian)### License
Copyright © 2019, [Brian Woodward](https://github.com/doowb).
Released under the [MIT License](LICENSE).***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 11, 2019._