An open API service indexing awesome lists of open source software.

https://github.com/rask/gulp-yaml-data

Read and use YAML metadata files in Gulp tasks
https://github.com/rask/gulp-yaml-data

Last synced: 10 months ago
JSON representation

Read and use YAML metadata files in Gulp tasks

Awesome Lists containing this project

README

          

# gulp-yaml-data

This Gulp plugin can be used to import metadata from YAML files into
a stream. This allows templates to read data from a wanted property in
the streamed file.

## Installation

$ npm install --save-dev gulp-yaml-data

## Usage

This example shows how to convert Markdown to HTML, and use `gulp-wrap`
to generate a lodash template from the converted Markdown.

`markdown/index.md`

```markdown
# Index page

Hello world.
```

`config.yaml`

```yaml
site_title: Foo Bar
```

`gulpfile.js`

```js
var gulp = require('gulp');
var yamlData = require('gulp-yaml-data');
var md2html = require('gulp-markdown');
var wrap = require('gulp-wrap');

gulp.task('markdown', function ()
{
// Read all template files which should be infused with
return gulp.src('markdown/*.html')

// Read data from config.yaml and set to a property named `data`
.pipe(yamlData({
property: 'data'
src: 'config.yaml'
})

// Convert Markdown to HTML
.pipe(md2html())

// Wrap generated HTML to a HTML lodash template
.pipe(wrap({
src: 'templates/template.html'
}))

// Output to directory `website`
.pipe(gulp.dest('website');
});
```

The template file referenced in `gulp-wrap` (`templates/template.html`)
could look a little something like this:

```html



<%= site_title %>



<%= contents %>

```

When you run `gulp markdown` the following file should appear inside
`public/index.html`:

```html



Foo Bar



Index page



Hello world.


```

## Options

Pass in options as a JS object like so:

```js
var options = {
property: 'data',
src: 'file.yaml',
override: false
};

...
.pipe(yamlData(options)
...
```

### options.property

`property` marks the property to which to append the YAML data in the
file stream. See your templating module of choice for the data property
name to use.

Default: `'data'`

### options.src

`src` contains either a filename string on an array of filename strings.

Single file:

src: 'config.yaml'

Multiple files:

src: [
'config.yaml',
'config.local.yaml'
]

Files are read in order, and files that are listed later will overwrite
values which are already present in earlier files.

Default: not defined, you need to explicitly define this in your
gulpfile.

### options.override

In case the file stream already has data tied to `options.property`,
this option value determines whether the `gulp-yaml-data` data overrides
the data set in those.

Default: `false`

## License

See LICENSE.md.