Permalink
Browse files

Added examples and updated README.md

  • Loading branch information...
1 parent 7bfdfd1 commit 604e2928b45244ad5b9e89f379b3ce16a0b16d27 @imalberto imalberto committed May 30, 2013
View
@@ -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`
View
@@ -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
+
+
+
+
View
@@ -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);
@@ -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"
+ }
+ }
+}]
@@ -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
+ }
+ }
+ }
+ }
+ ]
+ }
+]
View
@@ -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": {
+ }
+}
View
@@ -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
+
+
+
+
Oops, something went wrong.

0 comments on commit 604e292

Please sign in to comment.