API Docs for: 0.2.0
Show:

ExpressYUI Class

Uses
Defined in: lib/index.js:35
Module: express-yui

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.

Item Index

Methods

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

extend

(
  • app
)
Object public static

Defined in lib/index.js:76

Extends an express application instance with express-yui functionalities.

Parameters:

  • app Object

    express app instance to be extended with the yui member.

Returns:

Object:

express app instance

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.