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
# Index page Hello world.
config.yaml
site_title: Foo Bar
gulpfile.js
var gulp = ;var yamlData = ;var md2html = ;var wrap = ; gulp
The template file referenced in gulp-wrap
(templates/template.html
)
could look a little something like this:
<%= site_title %> <%= contents %>
When you run gulp markdown
the following file should appear inside
public/index.html
:
Foo Bar Index page Hello world.
Options
Pass in options as a JS object like so:
var options = property: 'data' src: 'file.yaml' override: false ; ...
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.