metalsmith-layouts
Advanced tools
Comparing version 1.4.4 to 1.5.4
@@ -0,11 +1,16 @@ | ||
1.5.4 - February 14, 2016 | ||
------------------------- | ||
* add rename option | ||
* prevent path issue on windows | ||
1.4.4 - January 27, 2016 | ||
-------------------------- | ||
------------------------ | ||
* update lodash.omit | ||
1.4.3 - January 27, 2016 | ||
-------------------------- | ||
------------------------ | ||
* update consolidate | ||
1.4.2 - October 17, 2015 | ||
-------------------------- | ||
------------------------ | ||
* update fs-readdir-recursive | ||
@@ -12,0 +17,0 @@ |
@@ -34,4 +34,4 @@ /** | ||
for (var i = 0; i < files.length; i++) { | ||
var ext = path.extname(files[i]); | ||
var name = files[i].replace(ext, ''); | ||
var fileInfo = path.parse(files[i]); | ||
var name = path.join(fileInfo.dir, fileInfo.name); | ||
var partialAbs = path.join(partialsAbs, name); | ||
@@ -38,0 +38,0 @@ var partialPath = path.relative(layoutsAbs, partialAbs); |
@@ -9,2 +9,3 @@ /** | ||
var omit = require('lodash.omit'); | ||
var path = require('path'); | ||
@@ -27,3 +28,10 @@ /** | ||
*/ | ||
var settings = ['default', 'directory', 'engine', 'partials', 'pattern']; | ||
var settings = [ | ||
'default', | ||
'directory', | ||
'engine', | ||
'partials', | ||
'pattern', | ||
'rename' | ||
]; | ||
@@ -39,2 +47,3 @@ /** | ||
* @property {String} pattern (optional) | ||
* @property {Boolean} rename (optional) | ||
* @return {Function} | ||
@@ -69,2 +78,3 @@ */ | ||
var pattern = opts.pattern; | ||
var rename = opts.rename; | ||
@@ -119,2 +129,11 @@ // Move all unrecognised options to params | ||
// Rename file if necessary | ||
var fileInfo; | ||
if (rename) { | ||
delete files[file]; | ||
fileInfo = path.parse(file); | ||
file = path.join(fileInfo.dir, fileInfo.name + '.html'); | ||
debug('renamed file to: %s', file); | ||
} | ||
render(str, clone, function(err, str){ | ||
@@ -127,2 +146,4 @@ if (err) { | ||
debug('converted file: %s', file); | ||
files[file] = data; | ||
done(); | ||
@@ -129,0 +150,0 @@ }); |
@@ -6,7 +6,7 @@ { | ||
"repository": "git://github.com/superwolff/metalsmith-layouts.git", | ||
"version": "1.4.4", | ||
"version": "1.5.4", | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "make test" | ||
"test": "mocha --reporter spec" | ||
}, | ||
@@ -25,3 +25,2 @@ "dependencies": { | ||
"assert-dir-equal": "^1.0.1", | ||
"eslint": "^1.0.0", | ||
"handlebars": "^4.0.2", | ||
@@ -28,0 +27,0 @@ "metalsmith": "^2.0.1", |
# metalsmith-layouts | ||
[![npm](https://img.shields.io/npm/v/metalsmith-layouts.svg)](https://www.npmjs.com/package/metalsmith-layouts) [![Build Status](https://travis-ci.org/superwolff/metalsmith-layouts.svg)](https://travis-ci.org/superwolff/metalsmith-layouts) [![Dependency Status](https://david-dm.org/superwolff/metalsmith-layouts.svg)](https://david-dm.org/superwolff/metalsmith-layouts) [![devDependency Status](https://david-dm.org/superwolff/metalsmith-layouts/dev-status.svg)](https://david-dm.org/superwolff/metalsmith-layouts#info=devDependencies) [![npm](https://img.shields.io/npm/dm/metalsmith-layouts.svg)](https://www.npmjs.com/package/metalsmith-layouts) | ||
[![npm version][version-badge]][version-url] | ||
[![build status][build-badge]][build-url] | ||
[![dependency status][dependency-badge]][dependency-url] | ||
[![devdependency status][devdependency-badge]][devdependency-url] | ||
[![downloads][downloads-badge]][downloads-url] | ||
> A metalsmith plugin for layouts | ||
This plugin allows you to apply layouts to your source files. It passes your source files to the selected layout as `contents` and renders the result with the templating engine of your choice. You can use any templating engine supported by [consolidate.js](https://github.com/tj/consolidate.js#supported-template-engines). | ||
[![stack overflow][stackoverflow-badge]][stackoverflow-url] | ||
[![slack chat][slack-badge]][slack-url] | ||
This plugin allows you to apply layouts to your source files. It passes your source files to the selected layout as the variable `contents` and renders the result with the templating engine of your choice. You can use any templating engine supported by [consolidate.js](https://github.com/tj/consolidate.js#supported-template-engines). For support questions please use [stack overflow][stackoverflow-url] or our [slack channel][slack-url]. For templating engine specific questions try the aforementioned channels, as well as the documentation for [consolidate.js](https://github.com/tj/consolidate.js) and your templating engine of choice. | ||
## Installation | ||
@@ -67,3 +74,3 @@ | ||
This is a very basic example. For a ready-to-use boilerplate that utilizes this plugin see [metalsmith-boilerplates](https://github.com/superwolff/metalsmith-boilerplates). | ||
This is a very basic example. For more elaborate examples see the [metalsmith tag on stack overflow][stackoverflow-url]. | ||
@@ -79,2 +86,3 @@ ## Options | ||
* [pattern](#pattern): only files that match this pattern will be processed (optional) | ||
* [rename](#rename): change the file extension of processed files to `.html` (optional) | ||
@@ -148,2 +156,4 @@ ### engine | ||
Make sure to check [consolidate.js](https://github.com/tj/consolidate.js) and your templating engine's documentation for guidelines on how to use partials. | ||
### pattern | ||
@@ -166,2 +176,19 @@ | ||
### rename | ||
Change the file extension of processed files to `.html` (optional). This option is set to `false` by default. So for example this `metalsmith.json`: | ||
```json | ||
{ | ||
"plugins": { | ||
"metalsmith-in-place": { | ||
"engine": "handlebars", | ||
"rename": true | ||
} | ||
} | ||
} | ||
``` | ||
Would rename the extensions of all processed files to `.html`. | ||
### Consolidate | ||
@@ -181,1 +208,16 @@ | ||
MIT | ||
[build-badge]: https://travis-ci.org/superwolff/metalsmith-layouts.svg | ||
[build-url]: https://travis-ci.org/superwolff/metalsmith-layouts | ||
[dependency-badge]: https://david-dm.org/superwolff/metalsmith-layouts.svg | ||
[dependency-url]: https://david-dm.org/superwolff/metalsmith-layouts | ||
[devdependency-badge]: https://david-dm.org/superwolff/metalsmith-layouts/dev-status.svg | ||
[devdependency-url]: https://david-dm.org/superwolff/metalsmith-layouts#info=devDependencies | ||
[downloads-badge]: https://img.shields.io/npm/dm/metalsmith-layouts.svg | ||
[downloads-url]: https://www.npmjs.com/package/metalsmith-layouts | ||
[slack-badge]: https://img.shields.io/badge/Slack-Join%20Chat%20→-blue.svg | ||
[slack-url]: http://metalsmith-slack.herokuapp.com/ | ||
[stackoverflow-badge]: https://img.shields.io/badge/stack%20overflow-%23metalsmith-red.svg | ||
[stackoverflow-url]: http://stackoverflow.com/questions/tagged/metalsmith | ||
[version-badge]: https://img.shields.io/npm/v/metalsmith-layouts.svg | ||
[version-url]: https://www.npmjs.com/package/metalsmith-layouts |
@@ -152,2 +152,40 @@ var assert = require('assert'); | ||
it('should not change file extension by default', function(done) { | ||
Metalsmith('test/fixtures/rename-option-default') | ||
.use(layouts({ | ||
engine: 'handlebars' | ||
})) | ||
.build(function (err) { | ||
if (err) return done(err); | ||
equal('test/fixtures/rename-option-default/expected', 'test/fixtures/rename-option-default/build'); | ||
done(); | ||
}); | ||
}); | ||
it('should change file extension when rename option is set to true', function(done) { | ||
Metalsmith('test/fixtures/rename-option') | ||
.use(layouts({ | ||
engine: 'handlebars', | ||
rename: true | ||
})) | ||
.build(function (err) { | ||
if (err) return done(err); | ||
equal('test/fixtures/rename-option/expected', 'test/fixtures/rename-option/build'); | ||
done(); | ||
}); | ||
}); | ||
it('should change file extension for nested files when rename option is set to true', function(done) { | ||
Metalsmith('test/fixtures/rename-option-nested') | ||
.use(layouts({ | ||
engine: 'handlebars', | ||
rename: true | ||
})) | ||
.build(function (err) { | ||
if (err) return done(err); | ||
equal('test/fixtures/rename-option-nested/expected', 'test/fixtures/rename-option-nested/build'); | ||
done(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
255568
5
82
376
219