https://github.com/jonschlinkert/common-middleware
Common middleware for apps built with base-methods (like assemble, verb, generate, and update)
https://github.com/jonschlinkert/common-middleware
assemble generate middleware templates
Last synced: 5 months ago
JSON representation
Common middleware for apps built with base-methods (like assemble, verb, generate, and update)
- Host: GitHub
- URL: https://github.com/jonschlinkert/common-middleware
- Owner: jonschlinkert
- License: mit
- Created: 2015-11-29T11:50:21.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-08-30T18:44:06.000Z (about 7 years ago)
- Last Synced: 2025-04-20T17:02:07.792Z (6 months ago)
- Topics: assemble, generate, middleware, templates
- Language: JavaScript
- Size: 40 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# common-middleware [](https://www.npmjs.com/package/common-middleware) [](https://npmjs.org/package/common-middleware) [](https://npmjs.org/package/common-middleware) [](https://travis-ci.org/jonschlinkert/common-middleware)
> Common middleware for applications built with base-methods (like assemble, verb, generate, and update)
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save common-middleware
```## Usage
```js
var middleware = require('common-middleware');
var assemble = require('assemble-core');// create your app
var app = assemble();// register the middleware
app.use(middleware());
```## Middleware
The following middleware are included.
### [front matter](index.js#L48)
Parses front-matter on files that match `options.extRegex` and
adds the resulting data object to `file.data`. This object is
passed as context to the template engine at render time.### [unescape templates](index.js#L65)
Registers a `.preWrite` middleware for unescaping escaped delimiters.
### [escape templates](index.js#L135)
Uses C-style macros to escape templates with `{%%= foo %}` or
`<%= foo %>` syntax, so they will not be evaluated by a template
engine when `.render` is called.### [JSON on-load](index.js#L181)
Adds a `json` property to the `file` object when the file extension
matches `options.jsonRegex`. This allows JSON files to be updated
by other middleware or pipeline plugins without having to parse and
stringify with each modification.### [JSON pre-write](index.js#L214)
If `file.contents` has not already been updated directly, the `file.contents` property
is updated with stringified JSON before writing the file back to the file
system.## Options
### options.jsonRegex
Customize the regex used for matching JSON files.
**Example**
```js
app.use(middleware({jsonRegex: /\.json$/}));
```### options.extRegex
Customize the regex used for matching template file extensions.
**Example**
```js
app.use(middleware({jsonRegex: /\.(hbs|tmpl)$/}));
```### options.escapeRegex
Customize the regex used for matching the extensions of files with templates to escape.
**Example**
```js
app.use(middleware({jsonRegex: /\.(tmpl|hbs)$/}));
```## About
### Related projects
* [assemble-core](https://www.npmjs.com/package/assemble-core): The core assemble application with no presets or defaults. All configuration is left to the… [more](https://github.com/assemble/assemble-core) | [homepage](https://github.com/assemble/assemble-core "The core assemble application with no presets or defaults. All configuration is left to the implementor.")
* [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality node.js applications, using plugins like building blocks")
* [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate "Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.")
* [update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update "Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.")
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.")### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
### Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ 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:
```sh
$ npm install && npm test
```### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)### License
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 16, 2017._