API Docs for: 0.2.0
Show:

File: lib/index.js

/*
 * Copyright (c) 2013, Yahoo! Inc.  All rights reserved.
 * Copyrights licensed under the New BSD License.
 * See the accompanying LICENSE file for terms.
 */

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

/**
The `express-yui` module implements an express extension to provide
yui capabilities to express applications.

@module express-yui
**/

'use strict';

var expstate = require('express-state'),
    YUIClass = require('./yui'),
    middleware = require('./middleware'),
    utils = require('./utils');

function ExpressYUI(app) {
    if (app['@yui']) { return app; }

    // Brand.
    Object.defineProperty(app, '@yui', { value: ExpressYUI });
    // extend express with some other requirements.
    expstate.extend(app);
    // adding the `yui` member.
    app.yui = new YUIClass(app);
    return app;
}

/**
The `express-yui` extension provides the foundation and some basic
features to boot `YUI` in the client and server runtimes.

The following is an example of how to extend an express application:

    var express = require('express'),
        expyui = require('express-yui'),
        app = express();

    expyui.extend(app);

    // setting some basic configurations for YUI
    app.yui.applyConfig({
        fetchCSS: false
    });

    // calling expose middleware when a route match.
    app.get('/index.html', expyui.expose(), anotherRoute);

In the example above, the `state` of the app will be serialized
per request, and can be used in the template to set up the client
side to run YUI with the same configuration used on the server side.
Here is an example of a handlebars template:

    <script>
    {{{state}}}
    app.yui.use('node', function (Y) {
        Y.one('#content').setContent('<p>Ready!</p>');
    });
    </script>

In this particular case, `state` will hold all the
appropiated settings generated by `expose` middleware.

@class ExpressYUI
@static
@uses middleware
*/
module.exports = utils.extend({

    /**
    Extends an express application instance with `express-yui` functionalities.
    
    @method extend
    @static
    @public
    @param {Object} app express app instance to be extended with the `yui` member.
    @return {object} express app instance
    **/
    extend: ExpressYUI

}, middleware);