Skip to content

Commit

Permalink
Added examples and updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
imalberto committed May 30, 2013
1 parent 7bfdfd1 commit 604e292
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -6,6 +6,8 @@ YCB is a multi-dimensional configuration library that builds bundles from resour

More info on the [wiki](https://github.com/yahoo/ycb/wiki).

Examples are provided in the [this directory](https://github.com/yahoo/ycb/tree/master/tests).

### Install

`npm install ycb --save`
Expand Down
16 changes: 16 additions & 0 deletions examples/full/README.md
@@ -0,0 +1,16 @@


full
======

This examples shows how to use a more realistic YCB dimensions and
configuration to "contextualized" a set of configuration.

To run this example:

cd ../../ && npm i && cd examples/full
node app.js




51 changes: 51 additions & 0 deletions examples/full/app.js
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/

/*jslint node:true, nomen:true*/

var libfs = require('fs'),
libpath = require('path'),
libycb = require('../../'),
assert = require('assert'),
data,
ycb,
context,
config;

/**
@param {string} file JSON valid file representing a configuration
@return {object} the parsed version of `file`
**/
function readFile(file) {
var raw = libfs.readFileSync(libpath.join(__dirname, file));
return JSON.parse(raw);
}

data = readFile('dimensions.json').concat(readFile('application.json'));

// create a new Ycb instance with `data`
ycb = new libycb.Ycb(data, {});

// read "master"
config = ycb.read({});
assert.equal(8000, config.appPort);
assert.equal(false, config.viewEngine.cacheTemplates);
assert.equal(undefined, config.selector);


// read "device:opera-mini"
config = ycb.read({ device: 'opera-mini' });
assert.equal('opera-mini', config.selector);
assert.equal(8000, config.appPort);

// read "environment:development"
config = ycb.read({ environment: 'development' });
assert.equal(false, config.yui.config.combine);
assert.equal("debug", config.yui.config.logLevel);
assert.equal(false, config.yui.config.fetchCSS);

config = ycb.readNoMerge({ environment: 'development' }, {});
assert.equal(2, config.length);
90 changes: 90 additions & 0 deletions examples/full/application.json
@@ -0,0 +1,90 @@
[{
"settings": ["master"],

"appPort": 8000,
"builds": {
"html5app": {
"attachManifest": true,
"forceRelativePaths": true,
"urls": ["/read.html"]
}
},
"viewEngine": {
"cacheTemplates": false
},
"yui": {
"config": {
"combine": true,
"logLevel": "info",
"fetchCSS": false
}
},

"specs": {

"_frame": {
"type": "HTMLFrameMojit",
"config": {
"deploy": true,
"assets": {
"top": {
"blob": ["<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"],
"css": ["/static/Frame/assets/reset.css"]
}
}
}
},

"shelf": {
"base": "_frame",
"config": {
"title": "NewsBoxes",
"child": {
"type": "Shelf",
"config": {
"children": {
"weather": {"type": "Weather"}
},
"assets": {
"top": {
"css": ["/static/Shelf/assets/shelf.css"]
}
}
}
}
}
},

"read": {
"base": "_frame",
"config": {
"title": "NewsBoxes » Read",
"child": {
"type": "Read",
"config": {
"assets": {
"top": {"css": ["/static/Read/assets/read.css"]}
}
}
}
}
}
}
},
{
"settings": [ "device:opera-mini" ],
"selector": "opera-mini"
},
{
"settings": [ "environment:development" ],
"staticHandling": {
"forceUpdate": true,
"serveYUIFromAppOrigin": true
},
"yui": {
"config": {
"combine": false,
"logLevel": "debug"
}
}
}]
183 changes: 183 additions & 0 deletions examples/full/dimensions.json
@@ -0,0 +1,183 @@
[
{
"dimensions": [
{
"runtime": {
"common": {
"client": null,
"server": null
}
}
},
{
"device": {
"android": null,
"blackberry": null,
"iemobile": null,
"iphone": null,
"ipad": null,
"kindle": null,
"opera-mini": null,
"palm": null
}
},
{
"environment": {
"development": {
"dev": null,
"test": null
},
"production": {
"stage": null,
"prod": null
}
}
},
{
"lang": {
"ar": {
"ar-JO": null,
"ar-MA": null,
"ar-SA": null,
"ar-EG": null
},
"bn": {
"bn-IN": null
},
"ca": {
"ca-ES": null
},
"cs": {
"cs-CZ": null
},
"da": {
"da-DK": null
},
"de": {
"de-AT": null,
"de-DE": null
},
"el": {
"el-GR": null
},
"en": {
"en-AU": null,
"en-BG": null,
"en-CA": null,
"en-GB": null,
"en-GY": null,
"en-HK": null,
"en-IE": null,
"en-IN": null,
"en-MY": null,
"en-NZ": null,
"en-PH": null,
"en-SG": null,
"en-US": null,
"en-ZA": null
},
"es": {
"es-AR": null,
"es-BO": null,
"es-CL": null,
"es-CO": null,
"es-EC": null,
"es-ES": null,
"es-MX": null,
"es-PE": null,
"es-PY": null,
"es-US": null,
"es-UY": null,
"es-VE": null
},
"fi": {
"fi-FI": null
},
"fr": {
"fr-BE": null,
"fr-CA": null,
"fr-FR": null,
"fr-GF": null
},
"hi": {
"hi-IN": null
},
"hu": {
"hu-HU": null
},
"id": {
"id-ID": null
},
"it": {
"it-IT": null
},
"ja": {
"ja-JP": null
},
"kn": {
"kn-IN": null
},
"ko": {
"ko-KR": null
},
"ml": {
"ml-IN": null
},
"mr": {
"mr-IN": null
},
"ms": {
"ms-MY": null
},
"nb": {
"nb-NO": null
},
"nl": {
"nl-BE": null,
"nl-NL": null,
"nl-SR": null
},
"pl": {
"pl-PL": null
},
"pt": {
"pt-BR": null
},
"ro": {
"ro-RO": null
},
"ru": {
"ru-RU": null
},
"sv": {
"sv-SE": null
},
"ta": {
"ta-IN": null
},
"te": {
"te-IN": null
},
"th": {
"th-TH": null
},
"tr": {
"tr-TR": null
},
"vi": {
"vi-VN": null
},
"zh": {
"zh-Hans": {
"zh-Hans-CN": null
},
"zh-Hant": {
"zh-Hant-HK": null,
"zh-Hant-TW": null
}
}
}
}
]
}
]
11 changes: 11 additions & 0 deletions examples/full/package.json
@@ -0,0 +1,11 @@
{
"name": "full",
"description": "A more complete example of how to use ycb.",
"author": "nobody",
"version": "0.1.0",
"keywords": [
"ycb"
],
"dependencies": {
}
}
16 changes: 16 additions & 0 deletions examples/simple/README.md
@@ -0,0 +1,16 @@


simple
======

This examples shows how to use a simple YCB dimensions and configuration to
"contextualized" a set of configuration.

To run this example:

cd ../../ && npm i && cd examples/simple
node app.js




0 comments on commit 604e292

Please sign in to comment.