🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

middleware-rename-file

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middleware-rename-file

Middleware for renaming views based on front-matter properties.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
2.1K
-9.22%
Maintainers
1
Weekly downloads
 
Created
Source

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:

---
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

  • 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.

Keywords

assemble

FAQs

Package last updated on 01 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts