roots-config

0.0.2 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i roots-config

Weekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • jescalan
  • kylemac