2.0.0 • Published 7 years ago

metalsmith-jstransformer-partials v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Metalsmith JSTransformer Partials NPM version

Build Status Dependency Status

Metalsmith plugin to add partial support through any JSTransformer.

Installation

npm install --save metalsmith-jstransformer-partials

CLI

If you are using the command-line version of Metalsmith, you can install via npm, and then add the metalsmith-jstransformer-partials key above metalsmith-jstransformer in your metalsmith.json file:

{
  "plugins": {
    "metalsmith-jstransformer-partials": {},
    "metalsmith-jstransformer": {}
  }
}

JavaScript API

If you are using the JavaScript API for Metalsmith, then you can require the module and add it to your .use() directives above metalsmith-jstransformer:

var partials = require('metalsmith-jstransformer-partials');
var jstransformer = require('metalsmith-jstraxnsformer');

metalsmith.use(partials());
metalsmith.use(jstransformer());

Usage

Partials are automatically defined in the partials/ directory, but you are able to define them manually by adding partials: true to your file metadata. The following example using Swig, so ensure you also install jstransformer-swig. To call a partial, invoke partial(<partialname>, locals) or `partials:

src/partials/name.swig

---
partial: true
name: Default Name
---
<div class="name">
  <h2>Name: {{ name }}</h2>
</div>

src/index.html.swig

<div class="name-wrapper">
  {{ partial('name', { name: 'TJ Holowaychuk' })|safe }}
</div>

Result

<div class="name-wrapper">
<div class="name">
  <h2>Name: TJ Holowaychuk</h2>
</div>
</div>

Options

.pattern

The pattern in which to automatically detect partials, without having to set partial: true. Defaults to partials/**.

.partials

An array of already existing partials to add to the array.

License

MIT

2.0.0

7 years ago

1.2.3

7 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.1

9 years ago