seed Class
Provision the seed information into app.yui.expose()
, and it
exposes an array of object with the information to build
the script tag or tags that forms the seed:
The following is an example of how these features can be used:
var express = require('express'),
expyui = require('express-yui'),
app = express();
expyui.extend(app);
// adjust the seed modules
app.yui.seed(['yui-base', 'loader', 'foo', 'bar']);
// Call expose middleware when a route match.
app.get('/index.html', expyui.expose(), anotherRoute);
In the example above, the array of objects with all seed urls
will be exposed thru window.YUI_config.seed
, which means you
can use it in in the client side to prepare the page to host a
yui instance. Normally, you don't have to do this manually, you
can use app.yui.ready()
or app.yui.use()
methods to do that
task automatically. Here is an example of what you need in your
layout template:
<script>
{{{state}}}
app.yui.ready(function () {
// at this point, YUI is ready in the client, plus
loader
, foo
and bar
modules injected in the page
since they were part or the seed.
});
</script>
Item Index
Properties
Methods
_buildUrls
-
modules
-
ext
-
filterMap
-
customConfig
Build a list of urls for a list of modules. Modules are described as <module-name>@<group-name>
.
Modules without the group denotation will be assumed as core modules from yui. ext
denotates
the type of the modules since this routine is able to produce css or js modules alike.
Parameters:
-
modules
Arraythe array of modules to generate the urls.
-
ext
Stringthe modules extension,
js
orcss
. -
filterMap
Objecthash table to translate filter values into suffix for modules. e.g.:
min
->-min
-
customConfig
Objectoptional configuration to overrule filter and combine per request when building the urls
-
filter
Stringoptional filter to overrule any filter
-
combine
Booleanoptional flag to overrule combine, when set to
false
, it will avoid creating combo urls.
-
Returns:
the href
url for each link tag to be inserted in the header of the page
addModuleToSeed
-
moduleName
Adds a yui module name into the core
YUI configuration
which is used by loader to identify the pieces that are
already part of the seed and should be attached to Y
automatically.
Parameters:
-
moduleName
Stringthe yui module name
buildCSSUrls
-
modules
Build a list of urls to load a list of css modules.
var links = app.yui.buildCSSUrls('cssbase', 'cssflickr@hermes');
As a result, links
will be an array with the urls that
you can use in your templates to provision styles.
Modules as cssflickr@hermes
denotate a module from a particular group,
as in <module-name>@<group-name>
. Modules without the group denotation
will be assumed as core modules from yui.
Parameters:
-
modules
String multipleOne or more module name (and optional @
)
Returns:
the href
url for each link tag to be inserted in the header of the page
buildJSUrls
-
modules
Build a list of urls to load a list of modules.
var scripts = app.yui.buildJSUrls('node', 'photos@hermes');
As a result, scripts
will be an array with one or more urls that
you can use in your templates to insert script tags.
Modules as photos@hermes
denotate a module from a particular group,
as in <module-name>@<group-name>
. Modules without the group denotation
will be assumed as core modules from yui.
Parameters:
-
modules
String multipleOne or more module name (and optional @
)
Returns:
the src
url for each script tag that forms the seed
getDefaultSeed
()
Array
protected
Gets the default list of module names that should be part of the seed files.
Returns:
list of modules in seed
getSeedUrls
-
customConfig
Build the list of urls to load the seed files for the app.
var scripts = app.yui.getSeedUrls();
As a result, scripts
will be an array with one or more urls that
you can use in your templates to provision YUI. Keep in mind that if
use expressYUI.expose()
middleware, you don't need to provision the
seed, it will be provisioned automatically as part of the state
object.
Parameters:
-
customConfig
Objectoptional configuration to overrule filter and combine per request when building the urls. This is useful if you have a custom middleware to turn debug mode on, and combine off by passing some special parameter.
-
filter
Stringoptional filter to overrule any filter
-
combine
Booleanoptional flag to overrule combine, when set to
false
, it will avoid creating combo urls.
-
Returns:
the src
url for each script tag that forms the seed
seed
-
modules
Specify a list of modules to use as seed. This
method extends the yui static configuration,
specifically setting the app.yui.config().seed
value.
app.yui.seed(["yui-base", "loader"]);
Parameters:
-
modules
Arraylist of modules to use
Returns:
express middleware
Properties
CSS_FILTERS_MAP
Object
The default mapping for suffix based on the config filter
value for css modules.
DEFAULT_FILTER
String
The default filter suffix for yui modules urls.
JS_FILTERS_MAP
Object
The default mapping for suffix based on the config filter
value for js modules.