middleware-rename-file

Middleware for renaming views based on front-matter properties.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
middleware-rename-file
1.0.06 years ago6 years agoMinified + gzip package size for middleware-rename-file in KB

Readme

middleware-rename-file NPM version NPM monthly downloads NPM total downloads Linux Build Status
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:

```html

rename: basename: default.hbs dirname: templates ---
<meta charset="UTF-8">
<title>{{title}}</title>
{% body %}
The generated destination path would be, `templates/default.hbs`.

## Usage

This can be used with [assemble](https://github.com/assemble/assemble), [verb](https://github.com/verbose/verb), [generate](https://github.com/generate/generate), [update](https://github.com/update/update) or an other library that is based on [templates](https://github.com/jonschlinkert/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).

```js
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.