Skip to content

Instantly share code, notes, and snippets.

@caridy
Last active December 20, 2015 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caridy/6161103 to your computer and use it in GitHub Desktop.
Save caridy/6161103 to your computer and use it in GitHub Desktop.
Patching YUI Core Modules with `express-yui`

What is this?

This is a gist to showcase how to patch a yui core module when using express-yui, in this particular case, patching the router module by defining a new module router-patched as a replacement for the original module core module router.

Instalation

npm install
node app.js
/*jslint node:true, nomen: true*/
'use strict';
var express = require('express'),
expyui = require('express-yui'),
Locator = require('locator'),
LocatorHandlebars = require('locator-handlebars'),
app = express();
expyui.extend(app);
app.set('view', app.yui.view());
// serving static yui modules
app.use(expyui['static']());
// creating a page with YUI embeded
app.get('/', expyui.expose(), function (req, res, next) {
res.render('demo');
});
// locator initialiation
new Locator({
buildDirectory: 'build'
})
.plug(LocatorHandlebars.yui())
.plug(app.yui.plugin({
registerGroup: true,
registerServerModules: true
}))
.parseBundle(__dirname, {}).then(function (have) {
// listening for traffic only after locator finishes the walking process
app.listen(3000, function () {
console.log("Server listening on port 3000");
});
}, function (e) {
console.log(e);
console.log(e.stack);
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>demo - patching yui core modules</title>
</head>
<body>
<div id="content">
Patching `router`
</div>
<script>{{{state}}}</script>
<script>
app.yui.use('router', function (Y) {
alert(Y.Router);
});
</script>
</body>
</html>
{
"name": "demo",
"description": "Overruling YUI.",
"version": "0.0.1",
"private": true,
"main": "app.js",
"dependencies": {
"express": "*",
"express-yui": "*",
"locator": "~0.3.0",
"locator-handlebars": "*",
"yui": "~3.11.0"
}
}
YUI.add('router-patched', function (Y, NAME) {
alert(NAME);
}, '3.10.2', {
"optional": ["querystring-parse"],
"requires": ["array-extras", "base-build", "history"],
"condition": {
"name": "router-patched",
"trigger": "router",
"when": "instead"
}
});
@pdokas
Copy link

pdokas commented Aug 6, 2013

Awesome, worked like a charm. I’d never seen condition.when before, clever stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment