pwf-config

Wrapper that simplifies reading global configuration

This is a wrapper module that simplifies reading global configuration. Go ahead and jump to examples

Requirements

Installation

bower install pwf-config

<DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="bower/pwf.js/lib/pwf.js"></script> 
    <script type="text/javascript" src="bower/pwf-config/lib/config.js"></script> 
  </head>
</html>

Usage

Config has very few methods.

When module is initialized, it reads variable sys from global scope and uses it as config data. If it finds sys to be undefined, it waits for pwf-jquery-compat module to be initialized and then tries the same again.

Use new_cfg as configuration data

pwf.use({
  'models':{
    'url':{
      'browse':'/api/{model}/browse'
    }
  }
});

Lookup this path in config. Return def if not found.

console.log(pwf.config.get('models.url.browse'));
...
'/api/{model}/browse'

Examples

You need to pass JSON encoded data to your page and ensure it is defined before pwf-config initializes. Like this:

<!DOCTYPE html>
<html>
<script type="text/javascript">
    var sys = {
        'some_config':{
            'value':1
        }
    };
</script> 
</html>

This config is later accessible with pwf.config.get('some_config.value');. If you don't want to use this method, see #use