Load YAML data files into your roots project
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.editorconfig
.gitignore
.travis.yml
Makefile
contributing.md
license.md
package.json
readme.md

readme.md

Roots-YAML

npm tests dependencies devDependencies Coverage Status

Load YAML data files into your roots project.

Note: This project is in early development, and versioning is a little different. Read this for more details.

Why Should You Care?

It's important to maintain clean DRY code. Instead of writing messy and duplicated markup, you can use the power of HTML precompilers and pass data into your templates.

Roots-YAML lets you store your site data in YAML, a human friendly data serialization format and then have that data exposed for you to use in your roots view templates.

Installation

  • make sure you are in your roots project directory
  • npm install roots-yaml --save
  • modify your app.coffee file to include the extension, as such
roots_yaml = require('roots-yaml')

module.exports =
  extensions:
    roots_yaml
      source: 'data'  # default value

Usage

Roots-YAML will look in your source directory and load any .yaml files into a data object for you to use in your views.

Each YAML file will be loaded using js-yaml and have the result set to data.<file_name>.

For example, if I have a directory data structured like this:

data/
  staff.yaml
  clients.yaml
  misc/
    doges.yaml
    manatoges.yaml

Inside my view templates I can use the following line to inspect the data object provided by roots-yaml:

pre=JSON.stringify(data, null, 2)

You will notice that, for example, data.staff contains the data in data/staff.yaml and data.misc.manatoges contains the data in data/misc/manatoges.

View Helper

Roots-YAML also adds a handy view helper to your Roots templates. Inside your views, add the following to insert a script tag setting a global data variable in your JS to your YAML data. You can also pass a string into yaml to change the name of the variable.

!= yaml()
!= yaml('manatoge')

results in:

<script>var data = {"doge":{"wow":"such yaml"}};</script>
<script>var manatoge = {"doge":{"wow":"such yaml"}};</script>

License & Contributing