roots-yaml

0.0.4 • Public • Published

Roots-YAML

npm tests dependencies 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:

data.staff returns the data in data/staff.yaml

data.misc.manatoges returns 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

Readme

Keywords

Package Sidebar

Install

npm i roots-yaml

Weekly Downloads

1

Version

0.0.4

License

MIT

Last publish

Collaborators

  • kylemac
  • joshrowley