Upgrade to Pro — share decks privately, control downloads, hide ads and more …

YUI on Node.js

okuryu
March 08, 2012

YUI on Node.js

okuryu

March 08, 2012
Tweet

More Decks by okuryu

Other Decks in Programming

Transcript

  1. YUI 3.5.0 “3.5.0 final is tentatively scheduled for April 3rd.

    We will post another update when the date is finalized.” via: http://www.yuiblog.com/blog/2012/03/12/update-on-3-5-0-release-schedule/
  2. YUI on Node.js $ npm install yui (only dependency “request”)

    // AND var YUI = require(‘yui’).YUI; YUI().use(‘yql’, function (Y) { Y.YQL(‘select * from ...’); }); // OR var Y = require(‘yui/yql’); Y.YQL(‘select * from ...’);
  3. Work with DOM // npm install jsdom var jsdom =

    require('jsdom'); var YUI = require('yui').YUI; var document = jsdom.jsdom('<html><body><h1>Hello!!</h1></body></html>'); var window = document.createWindow(); YUI({ win: window, doc: document }).use('node-base', function (Y) { Y.log(Y.one("h1").getContent()); });
  4. YUI module module.js YUI.add('my-module', function(Y) { Y.MyModule = function ()

    { Y.YQL(‘select * from ...’, function (r) { Y.log(r.query.results); }); }; });
  5. npm packaging index.js var path = require('path'); var meta =

    { 'my-module': { requires: ['yql'], fullpath: path.join(__dirname, 'module.js') } }; module.exports = { module: function() { var inst = require('yui').getInstance(); inst.applyConfig({useSync: true, modules: meta}); return inst.use(Object.keys(meta)); }, metadata: function() { return meta; } }
  6. npm packaging How to use my module: // npm install

    my-module var mod = require('my-module'); var YUI = require('yui').YUI; YUI({ modules: mod.metadata() }).use('my-module', function (Y) { Y.MyModule(); });