Simple configuration for roots, shared throughout the whole project
CoffeeScript JavaScript Makefile
Latest commit a5315f6 Jan 14, 2015 Jeff Escalante 0.0.2
Permalink
Failed to load latest commit information.
lib strip out extra dependencies Jan 14, 2015
test correct mocha timeout Jan 14, 2015
.editorconfig initial commit Jan 14, 2015
.gitignore initial commit Jan 14, 2015
.npmignore initial commit Jan 14, 2015
.travis.yml initial commit Jan 14, 2015
Makefile initial commit Jan 14, 2015
contributing.md initial commit Jan 14, 2015
license.md initial commit Jan 14, 2015
package.json 0.0.2 Jan 14, 2015
readme.md readme edit, trigger builds Jan 14, 2015

readme.md

Roots Config

npm tests dependencies Coverage Status

Simple configuration for roots, shared through your html, css, and javascript.

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

Installation

  • make sure you are in your roots project directory
  • npm install roots-config --save
  • modify your app.coffee file to include the extension, as such

    roots_config = require('roots-config')
    
    module.exports =
      extensions: [roots_config()]

Usage

Roots config is a very basic convenience extension. Often times you will want to store all your project's configuration values in one place, and have them available both to your html as locals and to your javascript. To use roots-config, just add it to the extensions as shown above, and pass it an object containing your config values. These values will automatically be available in your views under the config key, and if you use the config_js helper, will also be available globally for your javascript to pick up.

For example, you could have this in your app.coffee file:

extensions: [roots_config(env: 'development')]

Now, in one of your main view templates, you could have this:

p The current environment is #{config.env}!
!= config_js()
script(src='/js/main.js')

So here, you can see that anything we passed to the extension is available on config. Now, the config_js helper just outputs a script tag that attaches all the config variables to window.config as well, so your js can pick them up. With the helper in place, you could do this in your main.js file:

console.log(config);

...and it would return all your config variables. It's that simple!

License & Contributing