metalsmith-jstransformer
Advanced tools
Comparing version 0.7.2 to 0.8.0
# Changelog | ||
## v0.8.0: 2016-11-08 | ||
- Updated devDependencies | ||
- Added Metalsmith's `root` to engine compilation | ||
- Allow rendering only content matching `pattern` | ||
## v0.7.2 | ||
@@ -4,0 +10,0 @@ |
16
index.js
@@ -29,2 +29,3 @@ var path = require('path') | ||
opts.layoutPattern = opts.layoutPattern || 'layouts/**' | ||
opts.pattern = opts.pattern || '**' | ||
var defaultLayout = opts.defaultLayout | ||
@@ -48,4 +49,6 @@ | ||
// Retrieve the options for the JSTransformer. | ||
var thefilename = path.join(metalsmith._directory, metalsmith._source, layout) | ||
var options = extend({}, files[layout], { | ||
filename: path.join(metalsmith._directory, metalsmith._source, layout) | ||
filename: thefilename, | ||
root: metalsmith.source() | ||
}) | ||
@@ -93,5 +96,7 @@ | ||
// Build the options/locals. | ||
var thefilename = path.join(metalsmith._directory, metalsmith._source, layoutName) | ||
var locals = extend({}, metalsmith.metadata(), files[layoutName], files[file], { | ||
contents: files[file].contents.toString(), | ||
filename: path.join(metalsmith._directory, metalsmith._source, layoutName) | ||
filename: thefilename, | ||
root: metalsmith.source() | ||
}) | ||
@@ -185,4 +190,5 @@ | ||
} else { | ||
// Render the content individually. | ||
async.map(filesKeys, processFile, function (err) { | ||
// Render all individual content. | ||
var contentFiles = minimatch.match(filesKeys, opts.pattern, {matchBase: true}) | ||
async.map(contentFiles, processFile, function (err) { | ||
if (err) { | ||
@@ -192,3 +198,3 @@ done(err) | ||
// Render the content within the layouts. | ||
async.map(filesKeys, renderContent, function (err) { | ||
async.map(contentFiles, renderContent, function (err) { | ||
if (err) { | ||
@@ -195,0 +201,0 @@ done(err) |
{ | ||
"name": "metalsmith-jstransformer", | ||
"version": "0.7.2", | ||
"version": "0.8.0", | ||
"description": "Metalsmith JSTransformer Plugin", | ||
@@ -37,5 +37,5 @@ "files": [ | ||
"jstransformer-coffee-script": "*", | ||
"jstransformer-jade": "*", | ||
"jstransformer-markdown-it": "*", | ||
"jstransformer-nunjucks": "^0.2.0", | ||
"jstransformer-nunjucks": "*", | ||
"jstransformer-pug": "*", | ||
"jstransformer-styl": "*", | ||
@@ -42,0 +42,0 @@ "jstransformer-uglify-js": "*", |
@@ -35,2 +35,3 @@ # Metalsmith JSTransformer Plugin [![NPM version](https://img.shields.io/npm/v/metalsmith-jstransformer.svg)](https://www.npmjs.org/package/metalsmith-jstransformer) | ||
metalsmith.use(jstransformer({ | ||
'pattern': '**', | ||
'layoutPattern': 'layouts/**', | ||
@@ -45,13 +46,13 @@ 'defaultLayout': null | ||
Create files that you would like to act on with JSTransformers with file extensions representing the transformer to use, in the format `example.html.<transformer>`. For example, if you would like to process with Jade, you would name it `src/example.html.jade`. | ||
Create files that you would like to act on with JSTransformers with file extensions representing the transformer to use, in the format `example.html.<transformer>`. For example, if you would like to process with Pug, you would name it `src/example.html.pug`. | ||
Use multiple transformers by appending additional file extension transformer names at the end. For example, to [HTML-Minifier](https://github.com/jstransformers/jstransformer-html-minifier) our Jade example above, you would use the filename `src/example.html.html-minifier.jade`. | ||
Use multiple transformers by appending additional file extension transformer names at the end. For example, to [HTML-Minifier](https://github.com/jstransformers/jstransformer-html-minifier) our Pug example above, you would use the filename `src/example.html.html-minifier.pug`. | ||
#### Example | ||
The following example uses [Jade](http://jade-lang.com), so we must additionally install [`jstransformer-jade`](http://npm.im/jstransformer-jade): | ||
The following example uses [Pug](https://pugjs.org/), so we must additionally install [`jstransformer-pug`](http://npm.im/jstransformer-pug): | ||
npm install jstransformer-jade --save | ||
npm install jstransformer-pug --save | ||
##### `src/example.html.jade` | ||
##### `src/example.html.pug` | ||
@@ -91,10 +92,10 @@ ``` | ||
The following example uses [Jade](http://jade-lang.com) and [Markdown-it](https://www.npmjs.com/package/markdown-it), so we must additionally install [`jstransformer-jade`](http://npm.im/jstransformer-jade) and [`jstransformer-markdown-it`](https://www.npmjs.com/package/jstransformer-markdown-it): | ||
The following example uses [Pug](https://pugjs.org) and [Markdown-it](https://www.npmjs.com/package/markdown-it), so we must additionally install [`jstransformer-pug`](http://npm.im/jstransformer-pug) and [`jstransformer-markdown-it`](https://www.npmjs.com/package/jstransformer-markdown-it): | ||
npm install jstransformer-jade --save | ||
npm install jstransformer-pug --save | ||
npm install jstransformer-markdown-it --save | ||
##### `src/layouts/default.jade` | ||
##### `src/layouts/default.pug` | ||
``` jade | ||
``` pug | ||
--- | ||
@@ -116,3 +117,3 @@ pretty: true | ||
--- | ||
layout: layouts/default.jade | ||
layout: layouts/default.pug | ||
--- | ||
@@ -137,2 +138,6 @@ This is my **site**! | ||
### `.pattern` | ||
Render content only matching the given [minimatch](https://www.npmjs.com/package/minimatch) pattern. Defaults to `**`. | ||
### `.layoutPattern` | ||
@@ -139,0 +144,0 @@ |
14296
194
149