middleware-rename-file
v1.0.0
Published
Middleware for renaming views based on front-matter properties.
Downloads
5,980
Maintainers
Readme
middleware-rename-file
Middleware for renaming views based on front-matter properties.
Install
Install with npm:
$ npm install --save middleware-rename-file
How it works
You can rename the destination path of a file using properties defined in its front-matter. Any of the path properties on a vinyl file should work.
Example
Given the source file, scaffolds/layouts/base.hbs
:
---
rename:
basename: default.hbs
dirname: templates
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{title}}</title>
</head>
<body>
{% body %}
</body>
</html>
The generated destination path would be, templates/default.hbs
.
Usage
This can be used with assemble, verb, generate, update or an other library that is based on templates.
.onLoad
The main export is a middleware function that should be passed to .onLoad
to ensure that files are renamed as early in the render cycle as possible (so that when rendering begins, the actual file names are available on the context).
var rename = require('middleware-rename-file');
var assemble = require('assemble');
var app = assemble();
app.onLoad(/\.md$/, rename());
In addition to the regex provided to .onLoad
, you may also optionally pass a filter function to rename()
:
Example
Don't modify a file with the name (stem) index
:
app.onLoad(/\.md$/, rename(function(file) {
return file.stem !== 'index';
}));
About
Related projects
- assemble: Get the rocks out of your socks! Assemble makes you fast at creating web projects… more | homepage
- generate: Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… more | homepage
- templates: System for creating and managing template collections, and rendering templates with any node.js template engine… more | homepage
- update: Be scalable! Update is a new, open source developer framework and CLI for automating updates… more | homepage
- verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert. MIT
This file was generated by verb-generate-readme, v0.4.2, on February 01, 2017.