Skip to content

Commit

Permalink
Merge pull request #23 from superwolff/partials
Browse files Browse the repository at this point in the history
Update readme and only accept partials string
  • Loading branch information
Ismay committed Aug 6, 2015
2 parents addcf6d + da40cc4 commit c020dd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 14 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
This plugin renders templating syntax in your source files. You can use any templating engine supported by [consolidate.js](https://github.com/tj/consolidate.js#supported-template-engines). Pass options to `metalsmith-in-place` with the [Javascript API](https://github.com/segmentio/metalsmith#api) or [CLI](https://github.com/segmentio/metalsmith#cli). The options are:

* `engine`: templating engine (required)
* `partials`: a folder to scan for partials, will register all found files as partials (optional)
* `pattern`: only files that match this pattern will be processed (optional)

Any unrecognised options will be passed on to consolidate.js. You can use this, for example, to disable caching by passing `cache: false` to consolidate. See the [consolidate.js documentation](https://github.com/tj/consolidate.js) for all available options.

Note that consolidates `partials` option isn't accessible, as the implementation of consolidate for `metalsmith-in-place` skips the `readPartials` method. This is why anything other than a string passed to the `partials` option will be discarded.

## Installation

```
Expand All @@ -25,7 +28,8 @@ Configuration in `metalsmith.json`:
{
"plugins": {
"metalsmith-in-place": {
"engine": "handlebars"
"engine": "handlebars",
"partials": "partials"
}
}
}
Expand All @@ -37,12 +41,21 @@ Source file `src/index.html`:
---
title: The title
---
{{>nav}}
<p>{{title}}</p>
```

Partial file `partials/nav.html`:

```html
<!-- The partial name is the path relative to the `partials` folder, without the extension -->
<nav>Nav</nav>
```

Results in `dist/index.html`:

```html
<nav>Nav</nav>
<p>The title</p>
```

Expand Down
10 changes: 2 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ function plugin(opts){
/**
* Process any partials and pass them to consolidate as a partials object
*/
if (partials) {
if (typeof partials === 'string') {
// If a partials folder was specified process the folder
params.partials = readPartials(partials, metalsmith);
} else {
// If it's a regular partials object pass it to consolidate as is
params.partials = partials;
}
if (partials && typeof partials === 'string') {
params.partials = readPartials(partials, metalsmith);
}

/**
Expand Down

0 comments on commit c020dd7

Please sign in to comment.