Define locals for your reshape files inline
npm install reshape-define-locals![NPM Version][version_badge]
[![Build Status][build_badge]][build_link]
Define and append locals inside your reshape/sugarml files. Supports YAML and scoping. Be sure to read Gotchas
`` {{ options.join(', ') }} html`
options:
- one
- two
- three
``
$ npm i -S reshape-define-locals
` javascript
const reshape = require('reshape')
const expressions = require('reshape-expressions')
const defineLocals = require('reshape-define-locals')
const source =
paraContent: 'This is my paragraph.'
{{ file.paraContent }}
const config = {locals: {paraClass: 'center'}}const actual = await reshape({
plugins: [defineLocals(config), expressions(config)]
}).process(source)
`Configuration
` javascript
{
tag: 'define-locals',
scope: 'file',
locals
}
`$3
string, default:
'define-locals'This is the tag that is parsed as locals.
$3
string or false, default:
'file'All locals blocks are parsed and available as
locals.file, or simply file in your templates. Using usage example, you can set scope to false and the you'll be able to use {{ paraContent }} only. This will keep data between files until they are overwritten, so be sure to read gotchas.$3
object, default:
{}Locals coming from your application.
Gotchas
$3
As far as I can tell, only named blocks are processed in
extends, so either define your locals before extends, or in the named block.` html
key: value
{{ file.key }}
key: value
{{ file.key }}
key: value
{{ file.key }}
`$3
The simplest way to actually bring the data from your
define-locals block to reshape is to modify original locals object. What this means though, is that keys unchanged between files stay the same, meaning that, if file-1.html defines local property key to value and file-2.html doesn't, if you call {{ key }} in file-2.html`, you will probably not get undefined. Since there isn't particular order in which are files processed, at least with Spike, the data _may_ bleed over, or it may not, depending on the file order.What this means in practice: you need to reset data between different files yourself, or not be dependent on non-existence of some data.
[build_badge]: https://semaphoreci.com/api/v1/adamkiss/reshape-define-locals/branches/master/badge.svg
[build_link]: https://semaphoreci.com/adamkiss/reshape-define-locals
[version_badge]: https://img.shields.io/npm/v/reshape-define-locals.svg?label=NPM&style=flat-square&colorB=b54c81