Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rogeriopvl/gulp-mustache
〰 A gulp plugin that renders mustache templates
https://github.com/rogeriopvl/gulp-mustache
gulp gulp-plugin javascript mustache
Last synced: 11 days ago
JSON representation
〰 A gulp plugin that renders mustache templates
- Host: GitHub
- URL: https://github.com/rogeriopvl/gulp-mustache
- Owner: rogeriopvl
- License: mit
- Created: 2014-01-08T00:14:06.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T17:13:51.000Z (about 2 years ago)
- Last Synced: 2024-12-15T20:17:10.983Z (22 days ago)
- Topics: gulp, gulp-plugin, javascript, mustache
- Language: JavaScript
- Homepage:
- Size: 279 KB
- Stars: 45
- Watchers: 2
- Forks: 17
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gulp-mustache [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]
> mustache plugin for [gulp](https://github.com/wearefractal/gulp)
## Usage
First, install `gulp-mustache` as a development dependency:
```shell
npm install --save-dev gulp-mustache
```Then, add it to your `gulpfile.js`:
```javascript
var mustache = require("gulp-mustache");gulp.src("./templates/*.mustache")
.pipe(mustache({
msg: "Hello Gulp!"
}))
.pipe(gulp.dest("./dist"));
```You may also pass in an object representing mustache partials and their contents
as a third argument to the call to `mustache()` like so:With key/value pairs:
```javascript
gulp.src("./templates/*.mustache")
.pipe(mustache({
msg: "Hello Gulp!",
nested_value: "I am nested.",
another_value: "1 2 3"
},{},{
some_inner_partial: "{{nested_value}}
",
another_partial: "{{another_value}}"
})).pipe(gulp.dest("./dist"));
```
With a json file:```javascript
gulp.src("./templates/*.mustache")
.pipe(mustache('your_json_file.json',{},{}))
.pipe(gulp.dest("./dist"));
```## Partials loaded from disk
[Mustache partials](https://mustache.github.io/mustache.5.html#Partials) not given in the `partials` argument will be loaded from disk, relative from the file currently being processed:
```
{{> ../partials/head }}
```This will find a `head.mustache` in the partials directory next to the current file's directory. Partials loading is recursive.
## API
### mustache(view, options, partials)
#### view
Type: `hash` or `string`
Default: `undefined`The view object, containing all template variables as keys. If you pass a `string` it will be used as the path to a JSON file containing view variables.
As of `v1.0.1`, `file.data` is supported as a way of passing data into mustache. See [this](https://github.com/colynb/gulp-data#note-to-gulp-plugin-authors).
#### options
Type: `hash`
Default: `{ }`The options object to configure the plugin.
##### options.extension
Type: `string`
Default: the extension of the current file##### options.tags
Type `Array`
Default `undefined`Pass custom mustache delimiters. This must be an Array of strings where the first item is the opening tag and the second the closing tag.
Example:
```javascript
['{{custom', 'custom}}']
```#### partials
Type: `hash`
Default: `{ }`An optional object of mustache partial strings. See [mustache.js](https://github.com/janl/mustache.js/) for details on partials in mustache.
## License
[MIT License](http://en.wikipedia.org/wiki/MIT_License)
[npm-url]: https://npmjs.org/package/gulp-mustache
[npm-image]: https://badge.fury.io/js/gulp-mustache.png[travis-url]: http://travis-ci.org/rogeriopvl/gulp-mustache
[travis-image]: https://secure.travis-ci.org/rogeriopvl/gulp-mustache.png?branch=master[depstat-url]: https://david-dm.org/rogeriopvl/gulp-mustache
[depstat-image]: https://david-dm.org/rogeriopvl/gulp-mustache.png