API Docs for: 0.2.0
Show:

middleware Class

Exports few middleware.

Methods

_bootstrap

(
  • method
  • args
)
private

Inherited from client: lib/client.js:220

The internal bootstraping implementation.

Parameters:

  • method String

    The method to call on Y, either "use" or "require".

  • args Any

    Array of arguments to apply to the Y method.

debug

(
  • config
)
Function public

Forces a request to use yui in debug mode with combine disabled. This exposes YUI configuration overrides per request on res.locals.state (which inherits from app.locals.state.)

// exposing yui into the client side through state object
app.use(expyui.expose());
// using yui in debug mode when node runs in debug mode with custom filter
if (app.get('env') === 'development') {
    app.use(expyui.debug({filter: 'raw'}));
}

More details about the yui debug mode settings in the YUI API Docs.

Parameters:

  • config Object

    optional debug settings

    • combine Boolean

      default to false

    • logLevel String

      default to "debug"

    • filter String

      default to "debug"

    • useBrowserConsole Boolean

      optional debug settings

Returns:

Function:

express middleware

expose

() Function public

Exposes YUI into the client side. This middleware bundles expyui.exposeConfig() and expyui.exposeSeed() middleware.

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

expyui.extend(app);

// using it for a mounted middleware for all requests
app.use(expyui.expose());

In the example above, the state of the app will be serialized once, on the first 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>

Returns:

Function:

express middleware

exposeConfig

() Function protected

Exposes the yui configuration into app.locals.state. It also exposes the express-yui wrapper for YUI on the client so you can access app.yui.* on the client side just like you do on the server side. The client wrapper includes app.yui.ready() and app.yui.use() with the corresponding bootstraping code to inject YUI into the page. This middleware will be invoked by expyui.expose() middleware automatically, which means you do not need to call it directly.

Returns:

Function:

express middleware

exposeSeed

() Function protected

Expose the seed information into app.locals.state. This seed is an array of urls based on the call to app.yui.seed(), which is going to be used by the client bootstrap code to inject YUI into the page. This middleware will be invoked by expyui.expose() middleware automatically, which means you do not need to call it directly.

Returns:

Function:

express middleware

ready

(
  • callback
)
public

Inherited from client: lib/client.js:193

Boots the application, rehydrate the app state and calls back to notify the ready state of the app.

<script>{{{state}}}</script>
<script>
app.yui.ready(function (err) {
    if (err) {
        throw err;
    }
    app.yui.use('foo', 'bar', function (Y) {
        // do something!
    });
});
</script>

Parameters:

  • callback Function

    when the app is ready. If an error occurr, the error object will be passed as the first argument of the callback function.

require

() public

Inherited from client: lib/client.js:172

Like app.yui.use() but instead delegates to YUI().require() after getting the seed ready. The callback passed to require() receives two arguments, the Y object like use(), but also imports which holds all of the exports from the required modules.

<script>{{{state}}}</script>
<script>
app.yui.require('foo', 'bar', function (Y, imports) {
    var Foo         = imports['foo'],
        namedExport = imports['bar'].baz;
});
</script>

static

(
  • buildDirectory
  • options
)
Object public

Serves YUI Modules as static assets. All registered groups and core will be served from app origin.

app.use(expyui.static(__dirname + '/build'));

The example above behaves very similar to express.static() middleware, but it adds some sugar to also server YUI core modules as synthetic files, so you can combine yui core modules with app specific modules for better performance. If also adds some extra headers to avoid caching static files in a browser when nodejs is running in debug mode to facilitate development.

Parameters:

  • buildDirectory String

    fullpath to locator build directory

  • options Object

    express static handler options

Returns:

Object:

express app that can be mounted into another express app.

use

() public chainable

Inherited from client: lib/client.js:148

Attaches the seed into the head, then creates a YUI Instance and attaches modules into it. This is equivalent to YUI().use() after getting the seed ready. This method is a bootstrap implementation for the library, and the way you use this in your templates, is by doing this:

<script>{{{state}}}</script>
<script>
app.yui.use('foo', 'bar', function (Y) {
    // do something!
});
</script>

Where state defines the state of the express app, and app.yui defines the helpers that express-yui brings into the client side.