target);
6 | const char* MainSource();
7 |
8 | } // namespace node
9 |
10 |
--------------------------------------------------------------------------------
/compiler/yui.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var start = (new Date()).getTime();
3 | var yui = require(path.join(__dirname, 'build/default/yui3-compiled'));
4 |
5 | var vm = require('vm');
6 |
7 | var script = vm.createScript(yui.yui + yui.nodejs_yui3, 'yui.js');
8 |
9 | var sandbox = {
10 | process: process,
11 | require: require,
12 | module: module,
13 | __filename: __filename,
14 | __dirname: __dirname,
15 | exports: {}
16 | };
17 |
18 | script.runInNewContext(sandbox);
19 |
20 | for (var i in yui) {
21 | sandbox.module.exports.execCache[i] = {
22 | data: yui[i]
23 | };
24 | }
25 |
26 | module.exports = sandbox.module.exports;
27 |
--------------------------------------------------------------------------------
/examples/colors.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys');
4 | var YUI = require("yui3").YUI;
5 |
6 | YUI({
7 | filter: 'debug',
8 | debug: true
9 | }).use('node', function(Y) {
10 |
11 | Y.log('This output should be colored');
12 |
13 | });
14 |
15 |
16 | YUI({
17 | filter: 'debug',
18 | useColor: false,
19 | debug: true
20 | }).use('node', function(Y) {
21 |
22 | Y.log('This output SHOULD NOT be colored');
23 |
24 | });
25 |
--------------------------------------------------------------------------------
/examples/config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | foo: function(num) {
3 | console.log('(' + num + ') Config::Foo called');
4 | }
5 | };
6 |
--------------------------------------------------------------------------------
/examples/configure.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 |
4 | var YUIConfig = {
5 | core: '3.3.0',
6 | gallery: '2010.09.22',
7 | '2in3': '0.0.3'
8 | };
9 |
10 | var yui3 = require('yui3');
11 | var Y = yui3.configure(YUIConfig).useSync('node', 'gallery-torelativetime');
12 |
13 | console.log(Y.config.base);
14 | console.log(Y.config.groups.gallery.base);
15 | console.log(Y.config.groups.yui2.base);
16 |
17 |
--------------------------------------------------------------------------------
/examples/daemon.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var YUI = require('yui3').YUI;
4 |
5 | YUI({
6 | debug: true,
7 | modules: {
8 | 'process': {
9 | fullpath: __dirname + '/process.js'
10 | }
11 | }
12 | }).use('base', 'process', function(Y) {
13 | var p = new Y.Process({
14 | workers: 10
15 | });
16 | p.on('ready', function() {
17 | this.message('CHILD PROCESS STARTED FROM READY EVENT');
18 | });
19 | p.on('sigcont', function(e) {
20 | this.message('SIGCONT LISTENER, stopping..');
21 | e.halt();
22 | });
23 | p.on('sigchild', function(e) {
24 | //this.message('SIGCHILD STOPPED');
25 | //e.halt();
26 | });
27 | p.on('message', function(e) {
28 | //console.log('Message from (' + e.pid + '): ', e.message);
29 | });
30 |
31 | p.spawn();
32 | });
33 |
--------------------------------------------------------------------------------
/examples/express/assets/main.js:
--------------------------------------------------------------------------------
1 | alert('Loaded..');
2 |
--------------------------------------------------------------------------------
/examples/express/assets/tabview.js:
--------------------------------------------------------------------------------
1 | YUI({ fetchCSS: false }).use('tabview', function(Y) {
2 | new Y.TabView({
3 | srcNode: '#demo .yui3-tabview-content'
4 | }).render();
5 | });
6 |
--------------------------------------------------------------------------------
/examples/express/express.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var express = require('express'),
4 | YUI = require('yui3').YUI;
5 |
6 |
7 | YUI().use('express', 'node', function(Y) {
8 |
9 | var app = express.createServer();
10 |
11 | app.configure(function(){
12 | app.use(express.methodOverride());
13 | app.use(express.bodyDecoder());
14 | app.use(app.router);
15 | app.use(express.staticProvider(__dirname + '/assets'));
16 | });
17 |
18 | app.register('.html', YUI);
19 |
20 | app.get('/combo', YUI.combo);
21 |
22 | app.get('/tabview', function(req, res) {
23 | YUI().use('node', function(Y) {
24 | Y.Env._loader.ignoreRegistered = true;
25 | Y.use('tabview', function(Y) {
26 | var div = Y.Node.create('
');
27 | Y.one('title').set('innerHTML', 'YUI3 tabView Page');
28 | Y.one('body').addClass('yui3-skin-sam').appendChild(div);
29 |
30 | Y.log('Creating the TabView from script..');
31 | var tabview = new Y.TabView({
32 | children: [{
33 | label: 'foo',
34 | content: 'foo content
'
35 | }, {
36 | label: 'bar',
37 | content: 'bar content
'
38 | }, {
39 | label: 'baz',
40 | content: 'baz content
'
41 | }]
42 | });
43 | tabview.render('#demo');
44 |
45 | res.render('tabview.html', {
46 | locals: {
47 | instance: Y,
48 | use: ['tabview'],
49 | //filter: 'debug',
50 | content: '#content',
51 | after: function(Y) {
52 | Y.Get.domScript('/tabview.js');
53 | }
54 | }
55 | });
56 | });
57 | });
58 | });
59 |
60 | YUI.partials = [
61 | {
62 | method: 'append',
63 | node: 'body',
64 | name: 'layout_append'
65 | },
66 | {
67 | method: 'prepend',
68 | node: 'body',
69 | name: 'layout_prepend'
70 | }
71 | ];
72 |
73 | app.get('/', function(req, res){
74 | res.render('index.html', {
75 | locals: {
76 | content: '#content',
77 | sub: {
78 | above_content: 'This was inserted above the content.',
79 | title1: 'Title #1',
80 | title2: 'Title #2',
81 | title3: 'Title #3',
82 | title4: 'Title #4'
83 | },
84 | partials: [
85 | {
86 | method: 'append',
87 | node: 'head',
88 | name: 'layout_head'
89 | }
90 | ],
91 | after: function(Y, options, partial) {
92 | Y.Get.domScript('/main.js');
93 | Y.one('title').set('innerHTML', 'This is a test');
94 |
95 | var str = partial('test');
96 | var html = '';
97 | var data = ['one', 'two', 'three'];
98 | data.forEach(function(v) {
99 | html += Y.Lang.sub(str, { name: v })
100 | });
101 | Y.one('#content').prepend('');
102 | },
103 | before: function(Y) {
104 | Y.one('h1').set('innerHTML', 'BooYah!!');
105 | }
106 | }
107 | });
108 | });
109 |
110 | app.get('/pre', YUI.express({render: 'index.html', locals: {}}), function(req, res){
111 | res.sub({
112 | above_content: 'This was inserted above the content.',
113 | title: 'Title #1',
114 | title2: 'Title #2',
115 | title3: 'Title #3',
116 | title4: 'Title #4'
117 | });
118 | res.send();
119 | });
120 |
121 | Y.log('Server listening: http:/'+'/localhost:3000/', 'info', 'express');
122 | app.listen(3000);
123 |
124 | });
125 |
126 |
--------------------------------------------------------------------------------
/examples/express/views/index.html:
--------------------------------------------------------------------------------
1 | {title}
2 | This is only a test. This is only a test. This is only a test. This is only a test. This is only a test. This is only a test.
3 | {title2}
4 | This is only a test. This is only a test. This is only a test. This is only a test. This is only a test. This is only a test.
5 | {title3}
6 | This is only a test. This is only a test. This is only a test. This is only a test. This is only a test. This is only a test.
7 | {title4}
8 | This is only a test. This is only a test. This is only a test. This is only a test. This is only a test. This is only a test.
9 |
--------------------------------------------------------------------------------
/examples/express/views/layout.html:
--------------------------------------------------------------------------------
1 |
6 |
7 | Above normal content
8 |
9 |
10 |
11 |
12 | {above_content}
13 |
14 |
15 |
16 |
17 | Below normal content
18 |
23 |
--------------------------------------------------------------------------------
/examples/express/views/partials/layout_append.html:
--------------------------------------------------------------------------------
1 | © 2010 DavGlass.com This is a footer test.
2 |
--------------------------------------------------------------------------------
/examples/express/views/partials/layout_head.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/examples/express/views/partials/layout_prepend.html:
--------------------------------------------------------------------------------
1 |
This is the header of the page..
2 |
--------------------------------------------------------------------------------
/examples/express/views/partials/test.html:
--------------------------------------------------------------------------------
1 | {name}
2 |
--------------------------------------------------------------------------------
/examples/express/views/tabview.html:
--------------------------------------------------------------------------------
1 | This is only a test. This is only a test. This is only a test. This is only a test. This is only a test. This is only a test.
2 |
--------------------------------------------------------------------------------
/examples/external-module.js:
--------------------------------------------------------------------------------
1 | YUI.add('external-foo', function(Y) {
2 |
3 | Y.log(__dirname, 'info', '__dirname');
4 | Y.log(__filename, 'info', '__filename');
5 |
6 | //console.log(require);
7 | //console.log(process);
8 |
9 | var sys = require('sys');
10 | sys.puts('PRINTED FROM INTERNAL REQUIRE WITH sys.puts');
11 |
12 | var config = require('./config');
13 | Y.log(config);
14 | config.foo('#1 Relative');
15 |
16 | var config = require(__dirname + '/config');
17 | Y.log(config);
18 | config.foo('#2 Full Dir Require');
19 |
20 | Y.log('EXTERNAL FOO LOADED');
21 |
22 | }, '1.0.0', { requires: ['node'] });
23 |
--------------------------------------------------------------------------------
/examples/from-string.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var html = 'My Title ' +
4 | 'Foo ' +
5 | 'Foo ' +
6 | 'Foo ' +
7 | 'Foo ' +
8 | '';
9 |
10 | require('yui3').fromString(html, function(Y) {
11 | Y.log('Page Title: ' + Y.one('title').get('innerHTML'));
12 | Y.log('Anchors: ' + Y.all('a').size());
13 | Y.log('Lists: ' + Y.all('ol,ul').size());
14 | Y.log('List Items: ' + Y.all('li').size());
15 | });
16 |
17 |
--------------------------------------------------------------------------------
/examples/gallery.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys'),
4 | yui3 = require("yui3");
5 |
6 | var YUI = yui3.YUI;
7 |
8 | var YUI3 = yui3.configure({
9 | core: '@2010.12.06',
10 | gallery: '2010.09.22'
11 | });
12 |
13 |
14 | YUI3({
15 | debug: true
16 | }).use('node', 'gallery-yql', function(Y) {
17 |
18 | new Y.yql('select * from github.user.info where (id = "davglass")', function(r) {
19 | //Do something here.
20 | Y.log(r.query, 'debug', 'yql');
21 | });
22 |
23 |
24 | console.log('Gallery: ');
25 | console.log(Y.config.groups.gallery);
26 | });
27 |
28 | YUI({
29 | debug: true
30 | }).use('node', 'gallery-yql', function(Y) {
31 |
32 | new Y.yql('select * from github.user.info where (id = "davglass")', function(r) {
33 | //Do something here.
34 | Y.log(r.query, 'debug', 'yql');
35 | });
36 |
37 |
38 | console.log('Gallery: ');
39 | console.log(Y.config.groups.gallery);
40 | });
41 |
--------------------------------------------------------------------------------
/examples/general-dom.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys'),
4 | YUI = require("yui3").YUI;
5 |
6 | YUI({
7 | filter: 'debug',
8 | _logExclude: {
9 | 'attribute': true,
10 | 'base': true,
11 | 'get': true,
12 | 'loader': true,
13 | 'yui': true,
14 | 'widget': true,
15 | 'event': true
16 | },
17 | debug: true
18 | }).use('node', function(Y) {
19 |
20 | Y.log('JSDom testing..');
21 | //sys.puts('Inside1: ' + sys.inspect(process.memoryUsage()));
22 | var document = Y.Browser.document;
23 |
24 | var i = Y.Node.create('Test This ');
25 | i.addClass('foo');
26 | Y.one('body').append(i);
27 |
28 | var div = document.createElement('div');
29 | div.id = 'foo';
30 | div.innerHTML = 'Test this awesome shit.. ';
31 | document.body.appendChild(div);
32 |
33 | var foo = Y.one('#foo');
34 | foo.addClass('bar');
35 |
36 | Y.log(document.getElementById('foo').outerHTML, 'info', 'GEBI');
37 | Y.log(document.getElementById('bax').outerHTML, 'info', 'GEBI');
38 |
39 | //sys.puts('Inside2: ' + sys.inspect(process.memoryUsage()));
40 | Y.log(Y.Node.getDOMNode(Y.one('strong')), 'info');
41 | Y.log(Y.all('em, #bax').toString(), 'info');
42 | Y.log(Y.Node.getDOMNode(Y.one('strong')), 'info');
43 |
44 | Y.log(Y.all('em, u').toString(), 'info');
45 | Y.log(Y.all('#foo, em, u, #bax'), 'info');
46 | //sys.puts('Inside3: ' + sys.inspect(process.memoryUsage()));
47 |
48 | Y.log(i.toString(), 'info', 'node-instance');
49 | Y.log(Y.Node.getDOMNode(i).outerHTML, 'info', 'HTML');
50 | Y.log(foo.toString(), 'info', 'node-instance');
51 | Y.log(foo.get('className'), 'info', 'classname');
52 | Y.log(Y.Node.getDOMNode(foo).outerHTML, 'info', 'HTML');
53 |
54 | Y.log(Y.one('body'), 'info', 'BODY');
55 | Y.log(Y.all('body, div', null, true), 'info', 'BODY');
56 |
57 | Y.log(document.body.outerHTML, 'info', 'HTML');
58 | Y.log(document.getElementById('foo\:bar'), 'info', 'HTML');
59 | Y.log(document.getElementById('foo:bar'), 'info', 'HTML');
60 |
61 |
62 | Y.log(document.parentNode, 'info', 'document.parentNode');
63 |
64 | Y.log(document.outerHTML, 'info', 'document.outerHTML');
65 |
66 | //Y.log(document.getElementById('bax').outerHTML, 'HTML');
67 |
68 | });
69 |
--------------------------------------------------------------------------------
/examples/inside.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys');
4 |
5 | var YUI = require("yui3").YUI;
6 |
7 | YUI({
8 | filter: 'debug',
9 | debug: true
10 | }).use('json', 'base', 'io', 'yql', function(Y) {
11 |
12 | console.log('YQL1: ', Y.YQL);
13 | var Y2 = YUI({ filter: 'debug', debug: true }).use('*');
14 | console.log('YQL2: ', Y2.YQL);
15 |
16 | });
17 |
--------------------------------------------------------------------------------
/examples/io.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys');
4 |
5 | var YUI = require("yui3").YUI;
6 |
7 | YUI({
8 | filter: 'debug',
9 | debug: true
10 | }).use('json', 'io', function(Y) {
11 |
12 | var url = 'http:/'+'/yuilibrary.com/gallery/api/user/davglass';
13 |
14 | var url2 = 'http:/'+'/localhost/~davglass/node-post/';
15 |
16 | var url3 = 'http:/'+'/localhost:8500/';
17 |
18 | var url4 = 'https:/'+'/graph.facebook.com:443/davglass';
19 |
20 | Y.io(url, {
21 | on: {
22 | start: function() {
23 | Y.log('Start IO #1', 'info', 'io1');
24 | },
25 | success: function(id, o) {
26 | //Y.log(o.responseText);
27 | Y.log(sys.inspect(Y.JSON.parse(o.responseText).userinfo), 'info', 'io1');
28 | }
29 | }
30 | });
31 |
32 |
33 | Y.io(url2, {
34 | method: 'POST',
35 | headers: {
36 | foo: 'bar'
37 | },
38 | //data: 'test=post&this=data&testing=three',
39 |
40 | data: {
41 | test: 'post',
42 | 'this': 'data',
43 | 'testing': 'three'
44 | },
45 | on: {
46 | start: function() {
47 | Y.log('Start IO #2', 'info', 'io2');
48 | },
49 | success: function(id, o) {
50 | Y.log(sys.inspect(Y.JSON.parse(o.responseText)), 'info', 'io2');
51 | },
52 | failure: function(id, o) {
53 | Y.log('IO #2 FAILED', 'error', 'io2');
54 | }
55 | }
56 | });
57 |
58 | Y.io(url3, {
59 | on: {
60 | start: function() {
61 | Y.log('Start IO #3', 'info', 'io3');
62 | },
63 | failure: function(id, o) {
64 | Y.log('IO FAILED', 'error', 'io3');
65 | }
66 | }
67 | });
68 |
69 | Y.io(url4, {
70 | on: {
71 | start: function() {
72 | Y.log('Start IO #4', 'info', 'io4');
73 | },
74 | success: function(id, o) {
75 | Y.log(sys.inspect(Y.JSON.parse(o.responseText)), 'info', 'io4');
76 | }
77 | }
78 | });
79 |
80 | });
81 |
--------------------------------------------------------------------------------
/examples/library.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var start = (new Date()).getTime();
3 | var sys = require('sys');
4 | var YUI = require("yui3").YUI;
5 |
6 |
7 | YUI({
8 | filter: 'debug',
9 | debug: true
10 | }).use('json', 'base', 'yql', function(Y) {
11 |
12 | //sys.puts('Inside: ' + sys.inspect(process.memoryUsage()));
13 | //Logger outputs with sys.puts
14 | Y.log('This is a test');
15 | //Lang is available
16 | Y.log('Test: ' + Y.Lang.isBoolean(true), 'debug', 'myapp');
17 |
18 | //Creating a simple class
19 | var One = function() {
20 | One.superclass.constructor.apply(this, arguments);
21 | };
22 | //Extending it with Y.Base so we have Custom Events and a lifecycle
23 | Y.extend(One, Y.Base, {
24 | test: function() {
25 | this.publish('foo', {
26 | emitFacade: true
27 | });
28 | this.fire('foo');
29 | }
30 | }, {
31 | NAME: 'one'
32 | });
33 |
34 | //Create a new instance of our new class
35 | var o = new One();
36 | o.on('foo', function(o) {
37 | Y.log('Foo Fired', 'debug', 'myapp');
38 | //Y.log(o, 'debug');
39 | });
40 | o.test(); //Should fire the one:foo Event.
41 |
42 | //sys.puts(sys.inspect(Y));
43 |
44 | Y.YQL('select * from github.user.info where (id = "davglass")', function(r) {
45 | //Do something here.
46 | Y.log(r.query, 'debug', 'yql');
47 | Y.log((new Date()).getTime() - start + 'ms', 'info', 'TIMER');
48 | });
49 |
50 | var json = '{ "test": "one" }';
51 | Y.log(Y.JSON.parse(json), 'debug', 'json');
52 |
53 | });
54 |
--------------------------------------------------------------------------------
/examples/loadDir.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys');
4 | var YUI = require("yui3").YUI;
5 |
6 |
7 | YUI.add('foo', function(Y) {
8 | Y.log('FOO LOADED');
9 | });
10 |
11 | YUI({
12 | loadDir: {
13 | base: __dirname + '/mods/',
14 | dirs: ['/', 'views/', '/modals/', '/foo/']
15 | },
16 | filter: 'debug',
17 | debug: true
18 | }).use('base', 'mod1', 'mod2', 'mod3', 'view-mod1', 'view-mod2', 'view-mod3', 'modal-mod1', 'modal-mod2', 'modal-mod3', function(Y) {
19 |
20 | Y.log('This is a test of loading internal and external custom YUI3 modules');
21 |
22 | });
23 |
--------------------------------------------------------------------------------
/examples/loader.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var start = (new Date()).getTime();
3 | var YUI = require("yui3").YUI;
4 |
5 |
6 | YUI({
7 | combine: false,
8 | filter: 'debug',
9 | debug: true
10 | }).use('node', function(Y) {
11 |
12 | var end = (new Date()).getTime();
13 | Y.log(end - start + 'ms', 'info', 'timer');
14 |
15 | });
16 |
--------------------------------------------------------------------------------
/examples/markup/layout.html:
--------------------------------------------------------------------------------
1 |
2 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
3 |
4 |
5 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
6 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
7 |
8 |
9 |
Right 1
10 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
11 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
12 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
13 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
14 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
15 |
16 |
17 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
18 |
19 |
20 |
Toggle Right Toggle Left
21 | Close Left Add Gutter to Right
22 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, .
23 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
24 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
25 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
26 |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, pharetra at, adipiscing ullamcorper.
27 |
28 |
29 |
--------------------------------------------------------------------------------
/examples/markup/tabview.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/examples/mods/mod1.js:
--------------------------------------------------------------------------------
1 | YUI.add('mod1', function(Y) {
2 |
3 | Y.log('EXTERNAL MOD1 LOADED');
4 |
5 | }, '1.0.0', { requires: ['node'] });
6 |
--------------------------------------------------------------------------------
/examples/mods/mod2.js:
--------------------------------------------------------------------------------
1 | YUI.add('mod2', function(Y) {
2 |
3 | Y.log('EXTERNAL MOD2 LOADED');
4 |
5 | }, '1.0.0', { requires: ['node'] });
6 |
--------------------------------------------------------------------------------
/examples/mods/mod3.js:
--------------------------------------------------------------------------------
1 | YUI.add('mod3', function(Y) {
2 |
3 | Y.log('EXTERNAL MOD3 LOADED');
4 |
5 | }, '1.0.0', { requires: ['node'] });
6 |
--------------------------------------------------------------------------------
/examples/mods/modals/mod1.js:
--------------------------------------------------------------------------------
1 | YUI.add('modal-mod1', function(Y) {
2 |
3 | Y.log('EXTERNAL MODAL-MOD1 LOADED');
4 |
5 | }, '1.0.0', { requires: ['node'] });
6 |
--------------------------------------------------------------------------------
/examples/mods/modals/mod2.js:
--------------------------------------------------------------------------------
1 | YUI.add('modal-mod2', function(Y) {
2 |
3 | Y.log('EXTERNAL MODAL-MOD2 LOADED');
4 |
5 | }, '1.0.0', { requires: ['node'] });
6 |
--------------------------------------------------------------------------------
/examples/mods/modals/mod3.js:
--------------------------------------------------------------------------------
1 | YUI.add('modal-mod3', function(Y) {
2 |
3 | Y.log('EXTERNAL MODAL-MOD3 LOADED');
4 |
5 | }, '1.0.0', { requires: ['node'] });
6 |
--------------------------------------------------------------------------------
/examples/mods/views/mod1.js:
--------------------------------------------------------------------------------
1 | YUI.add('view-mod1', function(Y) {
2 |
3 | Y.log('EXTERNAL VIEW-MOD1 LOADED');
4 |
5 | }, '1.0.0', { requires: ['node'] });
6 |
--------------------------------------------------------------------------------
/examples/mods/views/mod2.js:
--------------------------------------------------------------------------------
1 | YUI.add('view-mod2', function(Y) {
2 |
3 | Y.log('EXTERNAL VIEW-MOD2 LOADED');
4 |
5 | }, '1.0.0', { requires: ['node'] });
6 |
--------------------------------------------------------------------------------
/examples/mods/views/mod3.js:
--------------------------------------------------------------------------------
1 | YUI.add('view-mod3', function(Y) {
2 |
3 | Y.log('EXTERNAL VIEW-MOD3 LOADED');
4 |
5 | }, '1.0.0', { requires: ['node'] });
6 |
--------------------------------------------------------------------------------
/examples/module-dyn.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys');
4 | var YUI = require("yui3").YUI;
5 |
6 |
7 | YUI.add('foo', function(Y) {
8 | Y.log('FOO LOADED');
9 | }, '1.0', { requires: ['external-foo'] });
10 |
11 | YUI({
12 | filter: 'debug',
13 | debug: true,
14 | modules: {
15 | 'external-foo': {
16 | fullpath: __dirname + '/external-module.js'
17 | }
18 | }
19 | }).use('base', 'foo', function(Y) {
20 |
21 | Y.log('This is a test of loading internal and external custom YUI3 modules');
22 |
23 | });
24 |
--------------------------------------------------------------------------------
/examples/module-groups.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys');
4 | var YUI = require("yui3").YUI;
5 |
6 |
7 | YUI.add('foo', function(Y) {
8 | Y.log('FOO LOADED');
9 | }, '1.0', { requires: ['external-foo'] });
10 |
11 | YUI({
12 | filter: 'debug',
13 | debug: true,
14 | groups: {
15 | dav: {
16 | modules: {
17 | 'external-foo': {
18 | fullpath: __dirname + '/external-module.js',
19 | requires: ['dom']
20 | }
21 | }
22 | }
23 | }
24 | }).use('base', 'foo', function(Y) {
25 |
26 | Y.log('This is a test of loading internal and external custom YUI3 modules');
27 |
28 | });
29 |
--------------------------------------------------------------------------------
/examples/module.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys');
4 | var YUI = require("yui3").YUI;
5 |
6 |
7 | YUI.add('foo', function(Y) {
8 | Y.log('FOO LOADED');
9 | });
10 |
11 | YUI({
12 | filter: 'debug',
13 | debug: true,
14 | modules: {
15 | 'external-foo': {
16 | fullpath: __dirname + '/external-module.js'
17 | }
18 | }
19 | }).use('base', 'foo', 'external-foo', function(Y) {
20 |
21 | Y.log('This is a test of loading internal and external custom YUI3 modules');
22 |
23 | });
24 |
--------------------------------------------------------------------------------
/examples/overlay-markup.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var sys = require('sys');
3 |
4 | var YUI = require("yui3").YUI;
5 |
6 | YUI({
7 | filter: 'debug',
8 | debug: true
9 | }).use('overlay', function(Y) {
10 | var document = Y.Browser.document;
11 |
12 | Y.log('JSDom testing..');
13 | //sys.puts('Inside1: ' + sys.inspect(process.memoryUsage()));
14 |
15 | var div = document.createElement('div');
16 | div.id = 'demo';
17 | div.innerHTML = 'Overlay Header
Overlay Body
Overlay Footer
';
18 | document.body.appendChild(div);
19 |
20 | Y.log('Creating the Overlay from source..');
21 | var overlay = new Y.Overlay({
22 | // Specify a reference to a node which already exists
23 | // on the page and contains header/body/footer content
24 | srcNode:"#myContent",
25 |
26 | // Also set some of the attributes inherited from
27 | // the base Widget class.
28 | visible:false,
29 | width:"20em"
30 | });
31 |
32 | // Default everything
33 | Y.log('Rendering..');
34 | overlay.render("#demo");
35 |
36 |
37 | Y.log('Done..');
38 | Y.log(div.outerHTML, 'HTML');
39 |
40 | });
41 |
--------------------------------------------------------------------------------
/examples/overlay-script.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var sys = require('sys');
3 |
4 | var YUI = require("yui3").YUI;
5 |
6 | YUI({
7 | filter: 'debug',
8 | logExclude: {
9 | 'attribute': true,
10 | 'base': true,
11 | //'get': true,
12 | 'loader': true,
13 | 'yui': true,
14 | 'widget': true,
15 | 'event': true
16 | },
17 | debug: true
18 | }).use('nodejs-dom', 'event', 'node-base', 'overlay', function(Y) {
19 | var document = Y.Browser.document;
20 |
21 | Y.log('JSDom testing..');
22 | //sys.puts('Inside1: ' + sys.inspect(process.memoryUsage()));
23 |
24 | var div = document.createElement('div');
25 | div.id = 'demo';
26 | document.body.appendChild(div);
27 |
28 | Y.log('Creating the Overlay from script..');
29 | // Default everything
30 | var overlay = new Y.Overlay({
31 | headerContent:"My Overlay Header",
32 | bodyContent:"My Overlay Body",
33 | footerContent:"My Footer Content",
34 | x: 200,
35 | y: 200
36 | });
37 | Y.log('Rendering..');
38 | overlay.render("#demo");
39 |
40 |
41 | Y.log('Done..');
42 | Y.log(div.outerHTML, 'HTML');
43 |
44 | });
45 |
--------------------------------------------------------------------------------
/examples/parallel.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var fs = require('fs');
4 | var YUI = require("yui3").YUI;
5 |
6 | YUI({
7 | filter: 'debug',
8 | debug: true
9 | }).use('parallel', function(Y) {
10 |
11 | Y.log('Reading this directory and reading the contents of each file..');
12 | var stack = new Y.Parallel();
13 | fs.readdir(__dirname, stack.add(function(err, files) {
14 | files.forEach(function(f) {
15 | fs.readFile(__dirname + f, stack.add(function(err, data) {
16 | //Do something here..
17 | }));
18 | });
19 | }));
20 | stack.done(function() {
21 | Y.log('All callbacks have fired..');
22 | });
23 |
24 | });
25 |
--------------------------------------------------------------------------------
/examples/process.js:
--------------------------------------------------------------------------------
1 | YUI.add('process', function(Y) {
2 |
3 | var netBinding = process.binding('net'),
4 | child_process = YUI.require('child_process'),
5 | net = YUI.require('net'),
6 | cwd = process.cwd(),
7 | isChild = false;
8 |
9 | process.argv.forEach(function(v) {
10 | if (v === '--child') {
11 | isChild = true;
12 | }
13 | });
14 |
15 | var Process = function() {
16 | Process.superclass.constructor.apply(this, arguments);
17 | };
18 | Y.extend(Process, Y.Base, {
19 | _children: null,
20 | _spawnChild: function() {
21 | var fds = netBinding.socketpair();
22 |
23 | // Collect the child process arguments
24 | var args = process.argv.slice(1);
25 | args.push('--child');
26 |
27 | // Spawn the child process
28 | var child = child_process.spawn(
29 | process.argv[0],
30 | args,
31 | undefined,
32 | [fds[1], fds[2], fds[3]]
33 | );
34 |
35 | child.__pid = parseInt(child.pid);
36 |
37 | this._children[child.pid] = child;
38 |
39 | if (!child.stdin) {
40 | child.stdin = new net.Stream(fds[0], 'unix');
41 | }
42 | if (!child.stdout) {
43 | child.stdout = new net.Stream(fds[1], 'unix');
44 | }
45 |
46 | child.stdout.addListener('data', Y.bind(function(data) {
47 | var d = JSON.parse(data);
48 | Y.log('Message: ' + d.message, 'info', 'child[' + d.pid + ']');
49 |
50 | this.fire('message', d);
51 | }, this));
52 | return child;
53 | },
54 | message: function(str) {
55 | console.log(JSON.stringify({ pid: process.pid, message: str }));
56 | },
57 | _onServerSignal: function(signal) {
58 | Y.log('Killing all children with signal: '+ signal);
59 | Y.each(this._children, function(c) {
60 | try {
61 | c.kill(signal);
62 | } catch (e) {}
63 | });
64 | process.exit();
65 | },
66 | _startServer: function() {
67 | var w = this.get('workers');
68 | for (var i = 0; i < w; i++) {
69 | this._spawnChild();
70 | }
71 | var self = this;
72 | ['SIGINT', 'SIGHUP', 'SIGTERM'].forEach(function(signal) {
73 | process.addListener(signal, Y.bind(self._onServerSignal, self, signal));
74 | });
75 | this.get('respawn');
76 |
77 | this.publish('sigchild', {
78 | defaultFn: this._sigChildFn
79 | });
80 | this.publish('sigcont', {
81 | defaultFn: this._sigContFn
82 | });
83 | this.publish('message', {
84 | emitFacade: false
85 | });
86 | },
87 | _sigChildFn: function(e) {
88 | Y.log('Child[' + e.child.__pid + '] died, spawning again.');
89 | this._spawnChild();
90 | },
91 | _onChildSig: function() {
92 | Y.each(this._children, function(c, i) {
93 | if (!c.pid) {
94 | delete this._children[i];
95 | this.fire('sigchild', { child: c });
96 | }
97 | }, this);
98 | },
99 | _sigContFn: function() {
100 | Y.log('SIGCONT Received Respawning all children');
101 | Y.each(this._children, function(c) {
102 | c.kill('SIGTERM');
103 | });
104 | },
105 | _onSigCont: function() {
106 | this.fire('sigcont');
107 | },
108 | _setRespawn: function() {
109 | Y.log('Adding respawn listeners');
110 | process.addListener('SIGCHLD', Y.bind(this._onChildSig, this));
111 | process.addListener('SIGCONT', Y.bind(this._onSigCont, this))
112 | },
113 | initializer: function() {
114 | this._children = {};
115 | },
116 | spawn: function() {
117 | if (this.get('child')) {
118 | this.fire('ready');
119 | Y.later((process.pid / 10), this, function() {
120 | this.message('Child process holder exiting..');
121 | });
122 | } else {
123 | this._startServer();
124 | }
125 | }
126 | }, {
127 | ATTRS: {
128 | child: {
129 | value: isChild
130 | },
131 | respawn: {
132 | value: true,
133 | setter: '_setRespawn'
134 | },
135 | workers: {
136 | value: 5
137 | }
138 | }
139 | });
140 |
141 | Y.Process = Process;
142 | });
143 |
--------------------------------------------------------------------------------
/examples/rls.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var start = (new Date()).getTime();
3 | var yui3 = require('yui3');
4 | var path = require('path');
5 | yui3.rls({
6 | //m: 'yui,loader,dd,widget,autocomplete,gallery-yql,yui2-datatable,gallery-aui-toolbar',
7 | //m: 'yui,loader,dd',
8 | //m: 'dd',
9 | m: 'loader,dd,widget,autocomplete,gallery-yql,yui2-datatable',
10 | //m: 'yui',
11 | //env: 'yui',
12 | //m: 'dd,widget,autocomplete,gallery-yql,yui2-datatable',
13 | //env: 'node,attribute',
14 | //v: 'yui3-core@3.2.0',
15 | //v: '3.2.0',
16 | //gv: '2010.09.22',
17 | //parse: true //This parses the file content and returns it as the last arg
18 | //gmeta: __dirname + '/gallery-meta.js',
19 | //yui2meta: __dirname + '/2in3-meta.js',
20 | //filt: 'debug',
21 | //'2in3v': '2.8.0',
22 | GlobalConfig: {
23 | loaderPath: path.join(__dirname, '..', 'tests', 'extras', '/loader-min.js'),
24 | debug: true
25 | }
26 | }, function(err, data) {
27 | var end = (new Date()).getTime() - start;
28 | console.log('Callback..');
29 | console.log(data.js);
30 | console.log(data.css);
31 | var size = 0;
32 | for (var i in data.d) {
33 | if (data.d[i]) {
34 | size += data.d[i].length;
35 | console.log('i: ', i, (data.d[i].length));
36 | }
37 | }
38 | console.log('Total: ', [].concat(data.js, data.css).length);
39 | console.log('Total JS: ', data.js.length);
40 | console.log('Total CSS: ', data.css.length);
41 | console.log('Data: ', Object.keys(data.d).length);
42 | console.log('Size: (bytes)', size);
43 | console.log('Time: %sms', end);
44 |
45 | });
46 |
47 |
48 |
--------------------------------------------------------------------------------
/examples/scrape-object.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var YUI = require("yui3").YUI;
4 |
5 | YUI({
6 | debug: true
7 | }).use('node', 'io', function(Y) {
8 |
9 | //Messing with the main page..
10 | Y.one('title').set('innerHTML', 'Digg News Headlines');
11 | //Creating the list that we will append the remote data to
12 | var ul = Y.one('body').appendChild(Y.Node.create(''));
13 |
14 | //Creating a sandboxed instance that we will bind to the remote page that we fetch
15 | YUI().use('node', function(remotePage) {
16 | //The page we are fetching
17 | var url = 'http://digg.com:9500/news';
18 |
19 | //This will call io under the hood and get the content of the URL,
20 | //It will then dump the content of that page into this sandboxed document.
21 | remotePage.fetch(url, {
22 | success: function() {
23 | //Get all the news items from the remote page.
24 | var newsItems = remotePage.all('#story-items h3');
25 | //Iterate them
26 | newsItems.each(function(n) {
27 | //Import this "A" node into the outside instances document
28 | var a = ul.importNode(n.one('a'), true);
29 | //Clean up the relative URL's of hrefs
30 | a.set('href', 'http://digg.com' + a.get('href'));
31 | //Append the new node to the list
32 | ul.appendChild(Y.Node.create(' ')).append(a);
33 | });
34 | //Now, we can print the "outer" instances html and drop it to the screen
35 | console.log(Y.get('doc').get('outerHTML'));
36 | },
37 | failure: function() {
38 | Y.log('Fetch FAILED', 'error');
39 | }
40 | });
41 | });
42 |
43 | });
44 |
--------------------------------------------------------------------------------
/examples/scrape.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var YUI = require("yui3").YUI;
4 |
5 | YUI({
6 | debug: true
7 | }).use('node', 'io', function(Y) {
8 |
9 | //Messing with the main page..
10 | Y.one('title').set('innerHTML', 'Digg News Headlines');
11 | //Creating the list that we will append the remote data to
12 | var ul = Y.one('body').appendChild(Y.Node.create(''));
13 |
14 | //Creating a sandboxed instance that we will bind to the remote page that we fetch
15 | YUI().use('node', function(remotePage) {
16 | //The page we are fetching
17 | var url = 'http://digg.com/news';
18 |
19 | //This will call io under the hood and get the content of the URL,
20 | //It will then dump the content of that page into this sandboxed document.
21 | remotePage.fetch(url, function() {
22 | //Get all the news items from the remote page.
23 | var newsItems = remotePage.all('#story-items h3');
24 | //Iterate them
25 | newsItems.each(function(n) {
26 | //Import this "A" node into the outside instances document
27 | var a = ul.importNode(n.one('a'), true);
28 | //Clean up the relative URL's of hrefs
29 | a.set('href', 'http://digg.com' + a.get('href'));
30 | //Append the new node to the list
31 | ul.appendChild(Y.Node.create(' ')).append(a);
32 | });
33 | //Now, we can print the "outer" instances html and drop it to the screen
34 | console.log(Y.one('doc').get('outerHTML'));
35 | });
36 | });
37 |
38 | });
39 |
--------------------------------------------------------------------------------
/examples/slider-script.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var sys = require('sys');
3 |
4 | var YUI = require("yui3").YUI;
5 |
6 | YUI({
7 | filter: 'debug',
8 | logExclude: {
9 | 'attribute': true,
10 | 'base': true,
11 | 'get': true,
12 | 'loader': true,
13 | 'yui': true,
14 | 'widget': true,
15 | 'event': true
16 | },
17 | debug: true
18 | }).use('nodejs-dom', 'event', 'node-base', 'slider', function(Y) {
19 | var document = Y.Browser.document;
20 |
21 | Y.log('JSDom testing..');
22 | //sys.puts('Inside1: ' + sys.inspect(process.memoryUsage()));
23 |
24 | var div = document.createElement('div');
25 | div.id = 'demo';
26 | document.body.appendChild(div);
27 |
28 | Y.log('Creating the Slider from script..');
29 | // Default everything
30 | var slider = new Y.Slider();
31 | Y.log('Rendering..');
32 | slider.render("#demo");
33 |
34 | Y.log('Done..');
35 | Y.log(div.outerHTML, 'HTML');
36 |
37 | });
38 |
--------------------------------------------------------------------------------
/examples/stdin.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | //Catch example errors
3 | var timer = setTimeout(function() {
4 | console.log('Failed to read stdin in 5 seconds, exiting..');
5 | process.exit(1)
6 | }, 5000);
7 |
8 | // curl -s http://yuilibrary.com/ | ./stdin.js
9 |
10 | require('yui3').stdin(function(Y) {
11 | clearTimeout(timer);
12 | Y.log('Page Title: ' + Y.one('title').get('innerHTML'));
13 | Y.log('Anchors: ' + Y.all('a').size());
14 | Y.log('Lists: ' + Y.all('ol,ul').size());
15 | Y.log('List Items: ' + Y.all('li').size());
16 | });
17 |
18 |
--------------------------------------------------------------------------------
/examples/sync-mod.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var Y = require('./sync-module');
3 |
4 | Y.YQL('select * from github.user.info where (id = "davglass")', function(r) {
5 | //Do something here.
6 | Y.log(r.query, 'debug', 'yql');
7 | });
8 |
--------------------------------------------------------------------------------
/examples/sync-module.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var YUI = require("yui3").YUI;
4 |
5 | YUI({
6 | filter: 'debug',
7 | _logExclude: {
8 | 'attribute': true,
9 | 'base': true,
10 | 'get': true,
11 | 'loader': true,
12 | 'yui': true,
13 | 'widget': true,
14 | 'event': true
15 | },
16 | debug: true
17 | }).useSync('yql', function(Ysync) {
18 |
19 | module.exports = Ysync;
20 |
21 | });
22 |
--------------------------------------------------------------------------------
/examples/sync.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var Y = require('yui3').useSync('yql');
3 |
4 | Y.YQL('select * from github.user.info where (id = "davglass")', function(r) {
5 | //Do something here.
6 | Y.log(r.query, 'debug', 'yql');
7 | });
8 |
--------------------------------------------------------------------------------
/examples/tabview-markup.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys');
4 |
5 | var YUI = require("yui3").YUI;
6 |
7 | YUI({
8 | filter: 'debug',
9 | debug: true
10 | }).use('tabview', function(Y) {
11 |
12 | var document = Y.Browser.document;
13 | Y.log('JSDom testing..');
14 | //sys.puts('Inside1: ' + sys.inspect(process.memoryUsage()));
15 |
16 | var div = document.createElement('div');
17 | div.id = 'demo';
18 | div.innerHTML = '';
19 | document.body.appendChild(div);
20 |
21 | console.log(div.outerHTML);
22 |
23 |
24 | Y.log('Creating the TabView from source..');
25 | Y.log(Y.one('#demo'));
26 |
27 | var tabview = new Y.TabView({
28 | srcNode: '#demo'
29 | });
30 |
31 | Y.log('Rendering..');
32 | tabview.on('render', function() {
33 | console.log(Y.one('doc').get('outerHTML'));
34 |
35 | Y.log('Render event listener');
36 | });
37 | tabview.render();
38 |
39 | Y.log('Done..');
40 | Y.log(div.outerHTML, 'HTML');
41 |
42 | });
43 |
--------------------------------------------------------------------------------
/examples/tabview-script.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var sys = require('sys');
3 |
4 | var YUI = require("yui3").YUI;
5 |
6 | YUI({
7 | filter: 'debug',
8 | logExclude: {
9 | 'attribute': true,
10 | 'base': true,
11 | //'get': true,
12 | //'loader': true,
13 | 'yui': true,
14 | 'widget': true,
15 | 'event': true
16 | },
17 | debug: true
18 | }).use('nodejs-dom', 'event', 'node-base', 'tabview', function(Y) {
19 |
20 | var document = Y.Browser.document;
21 | Y.log('JSDom testing..');
22 | //sys.puts('Inside1: ' + sys.inspect(process.memoryUsage()));
23 |
24 | var div = document.createElement('div');
25 | div.id = 'demo';
26 | document.body.appendChild(div);
27 |
28 | Y.log('Creating the TabView from script..');
29 | var tabview = new Y.TabView({
30 | children: [{
31 | label: 'foo',
32 | content: 'foo content
'
33 | }, {
34 | label: 'bar',
35 | content: 'bar content
'
36 | }, {
37 | label: 'baz',
38 | content: 'baz content
'
39 | }]
40 | });
41 |
42 | Y.log('Rendering..');
43 | tabview.render('#demo');
44 | //tabview.render(div);
45 | //tabview.render(Y.Node.getDOMNode(Y.one('#demo')));
46 | //Y.log(Y.Node.getDOMNode(Y.one('#demo')));
47 | //Y.log(div);
48 | Y.log('Done..');
49 | //Y.log(div.outerHTML, 'HTML');
50 | Y.log(Y.config.doc.outerHTML);
51 | });
52 |
--------------------------------------------------------------------------------
/examples/tnt-calendar-script.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var sys = require('sys'),
3 | fs = require('fs');
4 |
5 | var YUI = require("yui3").YUI;
6 |
7 | YUI({
8 | filter: 'debug',
9 | _logExclude: {
10 | 'attribute': true,
11 | 'base': true,
12 | 'get': true,
13 | 'loader': true,
14 | 'yui': true,
15 | 'widget': true,
16 | 'event': true
17 | },
18 | debug: true
19 | }).use('nodejs-dom', function(Y) {
20 | document = Y.Browser.document;
21 | navigator = Y.Browser.navigator;
22 | window = Y.Browser.window;
23 |
24 | Y.use('yui2-calendar', 'yui2-logger', function() {
25 | var YAHOO = Y.YUI2;
26 |
27 | Y.log('JSDom testing..');
28 |
29 | var el = document.createElement('div');
30 | el.id = 'cal1Container';
31 | document.body.appendChild(el);
32 |
33 | var cal1 = new YAHOO.widget.Calendar("cal1Container");
34 | cal1.renderEvent.subscribe(function() {
35 | Y.log('Done..');
36 | Y.log(document.outerHTML, 'HTML');
37 | });
38 | cal1.render();
39 | });
40 |
41 | });
42 |
--------------------------------------------------------------------------------
/examples/tnt-calendar-serve.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var sys = require('sys'),
3 | http = require('http'),
4 | url = require('url'),
5 | fs = require('fs');
6 |
7 | var YUI = require("yui3").YUI;
8 |
9 | YUI({
10 | filter: 'raw',
11 | _logExclude: {
12 | 'attribute': true,
13 | 'base': true,
14 | 'get': true,
15 | 'loader': true,
16 | 'yui': true,
17 | 'widget': true,
18 | 'event': true
19 | },
20 | debug: true
21 | }).use('nodejs-dom', 'node', function(Y) {
22 | document = Y.Browser.document;
23 | navigator = Y.Browser.navigator;
24 | window = Y.Browser.window;
25 |
26 | var docType = '' + "\n";
27 |
28 | http.createServer(function (req, res) {
29 | var urlInfo = url.parse(req.url, true);
30 | YUI().use('nodejs-dom', 'node', function(Page) {
31 | Page.log(sys.inspect(urlInfo));
32 |
33 | Y.log('JSDom testing..');
34 | document = Page.Browser.document;
35 | navigator = Page.Browser.navigator;
36 | window = Page.Browser.window;
37 |
38 | document.title = 'Calendar Test';
39 |
40 | Page.one('body').addClass('yui-skin-sam');
41 |
42 | var ln = document.createElement('link');
43 | ln.href = "http://yui.yahooapis.com/2in3.1/2.8.0/build/yui2-skin-sam-calendar/assets/skins/sam/yui2-skin-sam-calendar-min.css"
44 | ln.setAttribute('rel', 'stylesheet');
45 | ln.setAttribute('type', 'text/css');
46 | document.getElementsByTagName('head')[0].appendChild(ln);
47 |
48 | var el = document.createElement('div');
49 | el.id = 'cal1Container';
50 | document.body.appendChild(el);
51 |
52 |
53 | Page.log('Fetching Calendar');
54 | Page.use('yui2-calendar', function () {
55 | var YAHOO = Page.YUI2,
56 | config = {};
57 | if (urlInfo.query) {
58 | var q = urlInfo.query;
59 | if (q.day && q.month && q.year) {
60 | config.pagedate = q.month + '/' + q.year;
61 | config.selected = q.month + '/' + q.day + '/' + q.year;
62 | }
63 | if (q.page) {
64 | config.pagedate = q.page;
65 | }
66 | }
67 | var cal1 = new YAHOO.widget.Calendar('cal1', "cal1Container", config);
68 | cal1.HIDE_BLANK_WEEKS = true;
69 | cal1.renderEvent.subscribe(function() {
70 | var pageDate = cal1.cfg.getProperty('pagedate');
71 | var next = YAHOO.widget.DateMath.add(pageDate, 'M', 1);
72 | var prev = YAHOO.widget.DateMath.subtract(pageDate, 'M', 1);
73 | next = (next.getMonth() + 1) + '/' + next.getFullYear();
74 | prev = (prev.getMonth() + 1) + '/' + prev.getFullYear();
75 |
76 | //Fix up the dom
77 | Page.one('#cal1 .calheader .calnavright').set('href', '/?page=' + next);
78 | Page.one('#cal1 .calheader .calnavleft').set('href', '/?page=' + prev);
79 | var as = Page.all('#cal1 .calcell a');
80 | Page.log('Found: ' + as.size());
81 | as.each(function(node) {
82 | node.set('href', '/?month=' + (pageDate.getMonth() + 1) + '&year=' + pageDate.getFullYear() + '&day=' + node.get('innerHTML'));
83 | });
84 |
85 | var oom = Page.all('#cal1 .calcell.oom');
86 | Page.log('Found: ' + oom.size());
87 | oom.set('innerHTML', '');
88 |
89 | Y.log('Done..');
90 | res.writeHead(200, {
91 | 'Content-Type': 'text/html'}
92 | );
93 | var out = docType + Page.one('doc').get('outerHTML');
94 | res.write(out);
95 | res.close();
96 |
97 | Page.log('PAGE: Serving Page');
98 | });
99 | cal1.render();
100 | });
101 |
102 |
103 | });
104 | }).listen(8000);
105 |
106 | Y.log('Server running at http://127.0.0.1:8000/');
107 |
108 | });
109 |
--------------------------------------------------------------------------------
/examples/tnt-datatable-script.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var sys = require('sys'),
3 | fs = require('fs');
4 |
5 | var YUI = require("yui3").YUI;
6 |
7 | YUI({
8 | //yui2: '2.8.0',
9 | filter: 'debug',
10 | _logExclude: {
11 | 'attribute': true,
12 | 'base': true,
13 | //'get': true,
14 | //'loader': true,
15 | 'yui': true,
16 | 'widget': true,
17 | 'event': true
18 | },
19 | debug: true
20 | }).use('nodejs-dom', function(Y) {
21 | document = Y.Browser.document;
22 | navigator = Y.Browser.navigator;
23 | window = Y.Browser.window;
24 |
25 | Y.log('JSDom testing..');
26 | Y.use('yui2-datatable', 'yui2-datasource', function(Y) {
27 | var YAHOO = Y.YUI2;
28 |
29 | var el = document.createElement('div');
30 | el.id = 'basic';
31 | document.body.appendChild(el);
32 |
33 | YAHOO.example.Data = {
34 | bookorders: [
35 | {id:"po-0167", date:new Date(1980, 2, 24), quantity:1, amount:4, title:"A Book About Nothing"},
36 | {id:"po-0783", date:new Date("January 3, 1983"), quantity:null, amount:12.12345, title:"The Meaning of Life"},
37 | {id:"po-0297", date:new Date(1978, 11, 12), quantity:12, amount:1.25, title:"This Book Was Meant to Be Read Aloud"},
38 | {id:"po-1482", date:new Date("March 11, 1985"), quantity:6, amount:3.5, title:"Read Me Twice"}
39 | ]
40 | };
41 |
42 |
43 | var myColumnDefs = [
44 | {key:"id", sortable:true, resizeable:true},
45 | {key:"date", formatter:YAHOO.widget.DataTable.formatDate, sortable:true, sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC},resizeable:true},
46 | {key:"quantity", formatter:YAHOO.widget.DataTable.formatNumber, sortable:true, resizeable:true},
47 | {key:"amount", formatter:YAHOO.widget.DataTable.formatCurrency, sortable:true, resizeable:true},
48 | {key:"title", sortable:true, resizeable:true}
49 | ];
50 |
51 | Y.log('Creating DataSource..');
52 | var myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.bookorders);
53 | myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
54 | myDataSource.responseSchema = {
55 | fields: ["id","date","quantity","amount","title"]
56 | };
57 | Y.log('Creating DataTable..');
58 |
59 | var myDataTable = new YAHOO.widget.DataTable("basic",
60 | myColumnDefs, myDataSource, {caption:"DataTable Caption"});
61 |
62 | myDataTable.on('renderEvent', function() {
63 | Y.log('Done..');
64 | Y.log(document.body.outerHTML, 'HTML');
65 | });
66 | });
67 | });
68 |
--------------------------------------------------------------------------------
/examples/tnt-layout-script.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var sys = require('sys'),
3 | fs = require('fs');
4 |
5 | var YUI = require("yui3").YUI;
6 |
7 | YUI({
8 | filter: 'debug',
9 | logExclude: {
10 | 'attribute': true,
11 | 'base': true,
12 | 'get': true,
13 | 'loader': true,
14 | 'yui': true,
15 | 'widget': true,
16 | 'event': true
17 | },
18 | debug: true
19 | }).use('nodejs-dom', function(Y) {
20 | //GLOBALS!!!!
21 | document = Y.Browser.document;
22 | navigator = Y.Browser.navigator;
23 | window = Y.Browser.window;
24 | location = Y.Browser.location;
25 | self = Y.Browser.self;
26 |
27 |
28 | Y.log('JSDom testing..');
29 |
30 | Y.use('yui2-layout', function(Y) {
31 | var YAHOO = Y.YUI2;
32 | fs.readFile('./markup/layout.html', encoding='utf-8', function(err, data) {
33 | Y.log('Markup loaded..');
34 | Y.log(data);
35 | document.body.innerHTML = data;
36 | var layout = new YAHOO.widget.Layout({
37 | units: [
38 | { position: 'top', height: 50, body: 'top1', header: 'Top', gutter: '5px', collapse: true, resize: true },
39 | { position: 'right', header: 'Right', width: 300, resize: true, gutter: '5px', footer: 'Footer', collapse: true, scroll: true, body: 'right1', animate: true },
40 | { position: 'bottom', header: 'Bottom', height: 100, resize: true, body: 'bottom1', gutter: '5px', collapse: true },
41 | { position: 'left', header: 'Left', width: 200, resize: true, body: 'left1', gutter: '5px', collapse: true, close: true, collapseSize: 50, scroll: true, animate: true },
42 | { position: 'center', body: 'center1' }
43 | ]
44 | });
45 | Y.log('Rendering..');
46 | layout.render();
47 |
48 |
49 | Y.log('Done..');
50 | Y.log(document.body.outerHTML, 'HTML');
51 | });
52 | });
53 |
54 | });
55 |
--------------------------------------------------------------------------------
/examples/trap-error.js:
--------------------------------------------------------------------------------
1 | YUI.add('error', function(Y) {
2 | //This file contains a syntax error...
3 |
4 | if (baz.foo) {
5 | //This should error
6 | }
7 |
8 |
9 | }, '1.0.1');
10 |
--------------------------------------------------------------------------------
/examples/trap-test.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys');
4 |
5 | var YUI = require("yui3").YUI;
6 |
7 | YUI({
8 | filter: 'debug',
9 | debug: true,
10 | modules: {
11 | 'error': {
12 | fullpath: __dirname + '/trap-error.js'
13 | }
14 | }
15 | }).use('json', 'error', function(Y) {
16 |
17 | Y.log('Loaded..');
18 |
19 | });
20 |
21 |
--------------------------------------------------------------------------------
/examples/versions.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var netBinding = process.binding('net'),
4 | net = require('net'),
5 | fds = netBinding.socketpair(),
6 | npm = require('npm'),
7 | config = {
8 | exit: false,
9 | loglevel: 'silent',
10 | outfd: new net.Stream(fds[0], 'unix'),
11 | logfd: new net.Stream(fds[1], 'unix')
12 | };
13 |
14 | console.log('Fetching YUI versions from npm, this may take a moment...');
15 |
16 | npm.load(config, function() {
17 | npm.commands.ls(['yui3'], function(err, data) {
18 | var installed = {};
19 | for (var i in data) {
20 | if (i.match(/yui3-/)) {
21 | var c = i.split('@');
22 | installed[c[0]] = data[i].data.versions;
23 | }
24 | }
25 | start(installed);
26 | });
27 | });
28 |
29 | var express = require('express'),
30 | app = express.createServer();
31 |
32 | var start = function(mods) {
33 | var qs = require('querystring');
34 |
35 |
36 | var items = {
37 | 'core': {
38 | q: 'v'
39 | },
40 | 'gallery': {
41 | q: 'g'
42 | },
43 | '2in3': {
44 | q: 'yui2'
45 | }
46 | };
47 |
48 | app.get('/', function(req, res) {
49 | var p = req.query,
50 | out = '',
51 | helpers = {};
52 |
53 | var modules = 'Installed Packages ';
54 | for (var i in items) {
55 | var name = 'yui3-' + i;
56 | modules += '' + name + ' ';
57 | for (var v in mods[name]) {
58 | var m = mods[name][v];
59 | modules += '' + ((m.installed) ? '' + v + ' ' : v) + ((m.installed) ? ' Installed ' : ' Not Installed install via: npm install ' + name + '@' + v + '
') + ' ';
60 | if (m.installed) {
61 | if (!helpers[items[i].q]) {
62 | if (p[items[i].q] !== v) {
63 | helpers[items[i].q] = v;
64 | }
65 | }
66 | }
67 | }
68 | modules += ' ';
69 | }
70 |
71 | var YUIConfig = {};
72 | if (p.v) {
73 | YUIConfig.core = p.v;
74 | }
75 | if (p.g) {
76 | YUIConfig.gallery = p.g;
77 | }
78 | if (p.yui2) {
79 | YUIConfig['2in3'] = p.yui2;
80 | }
81 | var yui3 = require('yui3');
82 | var YUI = yui3.configure(YUIConfig).YUI;
83 |
84 | out += 'YUI Loaded From Config ';
85 | out += 'Core: ' + YUI.GlobalConfig.base + ' ';
86 | if (YUI.GlobalConfig.groups && YUI.GlobalConfig.groups.gallery) {
87 | out += 'Gallery: ' + YUI.GlobalConfig.groups.gallery.base + ' ';
88 | } else {
89 | out += 'Gallery is not installed: npm install yui3-gallery
';
90 | }
91 | if (YUI.GlobalConfig.groups && YUI.GlobalConfig.groups.yui2) {
92 | out += '2in3: ' + YUI.GlobalConfig.groups.yui2.base + ' ';
93 | } else {
94 | out += '2in3 is not installed: npm install yui3-2in3
';
95 | }
96 |
97 | var u = 'http:/'+'/localhost:8181/?' + qs.stringify(helpers);
98 | out += 'Hint: Try passing a config to the url: ' + u + ' ';
99 |
100 | out += modules;
101 |
102 | res.send(out);
103 | });
104 |
105 | console.log('Done, Server listening: http:/'+'/localhost:8181/');
106 | app.listen(8181);
107 | };
108 |
--------------------------------------------------------------------------------
/examples/y-browser.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys'),
4 | YUI = require("yui3").YUI;
5 |
6 | YUI({
7 | filter: 'debug',
8 | _logExclude: {
9 | 'attribute': true,
10 | 'base': true,
11 | 'get': true,
12 | 'loader': true,
13 | 'yui': true,
14 | 'widget': true,
15 | 'event': true
16 | },
17 | debug: false
18 | }).use('nodejs-dom', 'node', function(Y) {
19 |
20 | var document = Y.Browser.document;
21 | var window = Y.Browser.window;
22 | var self = Y.Browser.self;
23 | var navigator = Y.Browser.navigator;
24 | var location = Y.Browser.location;
25 |
26 | document.title = 'Example #1';
27 |
28 | //With the local aliases
29 | var el = document.createElement('div');
30 | el.id = 'foo';
31 | el.innerHTML = 'This is a test This is another test ';
32 | document.body.appendChild(el);
33 |
34 |
35 | //SCOPED
36 | var el2 = Y.Browser.document.createElement('div');
37 | el2.id = 'foo2bar';
38 | el2.innerHTML = 'This is a test This is another test ';
39 | Y.Browser.document.body.appendChild(el2);
40 |
41 | sys.puts('getElementByid(foo2bar): ' + Y.Browser.document.getElementById('foo2bar'));
42 | sys.puts('getElementByid(foo): ' + Y.Browser.document.getElementById('foo'));
43 | sys.puts('getElementByTagName(em): ' + Y.Browser.document.getElementsByTagName('em'));
44 | sys.puts('getElementByClassName(odd): ' + Y.Browser.document.getElementsByClassName('odd'));
45 |
46 | sys.puts('');
47 | sys.puts('Y.Browser.document.outerHTML: ');
48 | sys.puts(Y.Browser.document.outerHTML);
49 | });
50 |
51 | YUI({
52 | filter: 'debug',
53 | _logExclude: {
54 | 'attribute': true,
55 | 'base': true,
56 | 'get': true,
57 | 'loader': true,
58 | 'yui': true,
59 | 'widget': true,
60 | 'event': true
61 | },
62 | debug: false
63 | }).use('nodejs-dom', 'node', function(Y) {
64 |
65 | var document = Y.Browser.document;
66 | var window = Y.Browser.window;
67 | var self = Y.Browser.self;
68 | var navigator = Y.Browser.navigator;
69 | var location = Y.Browser.location;
70 |
71 | document.title = 'Example #2';
72 |
73 | //With the local aliases
74 | var el = document.createElement('div');
75 | el.id = 'foo';
76 | el.innerHTML = 'This is a test This is another test ';
77 | document.body.appendChild(el);
78 |
79 |
80 | //SCOPED
81 | var el2 = Y.Browser.document.createElement('div');
82 | el2.id = 'foo2bar';
83 | el2.innerHTML = 'This is a test This is another test ';
84 | Y.Browser.document.body.appendChild(el2);
85 |
86 | sys.puts('getElementByid(foo2bar): ' + Y.Browser.document.getElementById('foo2bar'));
87 | sys.puts('getElementByid(foo): ' + Y.Browser.document.getElementById('foo'));
88 | sys.puts('getElementByTagName(em): ' + Y.Browser.document.getElementsByTagName('em'));
89 | sys.puts('getElementByClassName(odd): ' + Y.Browser.document.getElementsByClassName('odd'));
90 |
91 | sys.puts('');
92 | sys.puts('Y.Browser.document.outerHTML: ');
93 | sys.puts(Y.Browser.document.outerHTML);
94 |
95 | });
96 |
--------------------------------------------------------------------------------
/examples/y-server-template.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys'),
4 | http = require('http'),
5 | fs = require('fs'),
6 | YUI = require("yui3").YUI;
7 |
8 | var DEBUG = true;
9 |
10 | YUI({ debug: DEBUG }).use('base', 'nodejs-dom', 'node', 'gallery-yql', 'json-stringify', function(Y) {
11 | Y.log('Loaded first instance..');
12 |
13 | var docType = '' + "\n";
14 |
15 | http.createServer(function (req, res) {
16 |
17 | YUI({ debug: DEBUG }).use('nodejs-dom', 'node', 'gallery-yql', 'json-stringify', function(Page) {
18 | //This is an example, normally we would use HTML templates.
19 | //Some JSON data to work on the template.
20 | var data = {
21 | TITLE: 'Test Page: ' + (new Date()),
22 | PARAS: [
23 | 'This is some test',
24 | 'This is some test',
25 | 'This is some test',
26 | 'This is some test',
27 | 'This is some test',
28 | 'This is some test'
29 | ]
30 | };
31 | Page.one('title').set('innerHTML', data.TITLE);
32 |
33 |
34 | var body = Page.one('body');
35 | body.append('The content below is dynamically generated on the server. You can access this code in 3 different ways:
');
36 | body.append('
');
37 |
38 | var el = Page.one('#wrapper');
39 |
40 | Y.each(data.PARAS, function(v, k) {
41 | el.append('' + v + ' : #' + k + '
');
42 | });
43 |
44 | var out = '', contentType = 'text/html';
45 | switch (req.url) {
46 | case '/json':
47 | out = Page.JSON.stringify(data);
48 | contentType = 'text/plain';
49 | break;
50 | case '/html':
51 | out = el.get('innerHTML');
52 | break;
53 | default:
54 | out = docType + Page.one('doc').get('outerHTML');
55 | }
56 | res.writeHead(200, {
57 | 'Content-Type': contentType
58 | });
59 | res.write(out);
60 | res.close();
61 |
62 | Page.log('PAGE: Serving Page');
63 | });
64 |
65 |
66 | }).listen(8000);
67 |
68 | Y.log('Server running at http://127.0.0.1:8000/');
69 |
70 | });
71 |
72 |
--------------------------------------------------------------------------------
/examples/y-server.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var sys = require('sys'),
4 | http = require('http'),
5 | YUI = require("yui3").YUI;
6 |
7 | var DEBUG = true;
8 |
9 | YUI({ debug: DEBUG }).use('base', 'nodejs-dom', 'node', function(Y) {
10 | Y.log('Loaded first instance..');
11 |
12 | var docType = '' + "\n";
13 |
14 | http.createServer(function (req, res) {
15 |
16 | YUI({ debug: DEBUG }).use('nodejs-dom', 'node', function(Page) {
17 |
18 | Page.one('title').set('innerHTML', 'Test Page: ' + (new Date()));
19 | Page.one('body').append('This is a test
');
20 |
21 | res.writeHead(200, {
22 | 'Content-Type': 'text/html'}
23 | );
24 | var out = docType + Page.one('doc').get('outerHTML');
25 | //Y.log(out);
26 | res.write(out);
27 | res.close();
28 |
29 | Page.log('PAGE: Serving Page');
30 | //sys.puts(sys.inspect(process.memoryUsage(), true));
31 | });
32 |
33 |
34 | }).listen(8000);
35 |
36 | Y.log('Server running at http://127.0.0.1:8000/');
37 |
38 | });
39 |
40 |
--------------------------------------------------------------------------------
/lib/node-yui3.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | /**
4 | *
5 | * IMPORTED FROM node-yui3.js
6 | *
7 | */
8 |
9 |
10 | var getYUI = function(c) {
11 | //var yui3 = require('./yui3-yui3');
12 | //var YUI = yui3.configure(c);
13 | var YUI = configureYUI(c);
14 | return YUI;
15 | }
16 |
17 | // YInterface allows these two to work:
18 | // var Y = yui3.useSync("io");
19 | // var Y = yui3.configure({core:"3.3.0"}).useSync("io");
20 | // See also: tests/interface.js
21 | var inter = {};
22 |
23 | inter.__defineGetter__('YUI', function() {
24 | var YUI = getYUI();
25 | return YUI;
26 | });
27 |
28 | inter.silent = function(c) {
29 | var YUI = getYUI(c);
30 | return YUI({ debug: false });
31 | };
32 | inter.sync = function(c) {
33 | var YUI = getYUI(c);
34 | YUI.loadSync = true;
35 | return YUI();
36 | };
37 | inter.async = function(c) {
38 | var YUI = getYUI(c);
39 | YUI.loadSync = false;
40 | return YUI();
41 | };
42 |
43 | inter.useSync = function() {
44 | var YUI = getYUI();
45 | YUI.loadSync = true;
46 | var Y = YUI();
47 | return Y.use.apply(Y, arguments);
48 | }
49 |
50 | inter.use = function() {
51 | var YUI = getYUI();
52 | YUI.loadSync = false;
53 | var Y = YUI();
54 | return Y.use.apply(Y, arguments);
55 | }
56 |
57 | inter.configure = function (config) {
58 | var YUI = getYUI(config);
59 | var Y = YUI();
60 | //Workaround for old school .YUI access..
61 | Y.__defineGetter__('YUI', function() {
62 | var YUI = getYUI(config);
63 | return YUI;
64 | });
65 | return Y;
66 | };
67 |
68 | /**
69 | * This method accepts the default RLS configuration object and returns two arrays of file paths for js and css files.
70 | * @method rls
71 | * @param {Object} config The RLS configuration to work from
72 | * @param {Function} fn The callback executed when the process is completed
73 | * @returns {Callback} js, css Callback returns two arguments. Both arrays of file paths, one for JS and one for CSS files.
74 | */
75 | inter.rls = function(config, fn) {
76 | //The config to create the YUI instance with
77 | var c = {
78 | core: config.v,
79 | gallery: config.gv,
80 | yui2: config['2v'] || config['2in3v']
81 | };
82 |
83 | var YUI = getYUI(c);
84 | new RLS(YUI, config).compile(fn);
85 |
86 | };
87 |
88 | /**
89 | * Just returns the base class for RLS so you can control and override any method
90 | */
91 | inter.__defineGetter__('RLS', function() {
92 | return RLS;
93 | });
94 |
95 | /**
96 | * Inject the given HTML into a new YUI instance and return the instance.
97 | * @method fromString
98 | * @param {HTML} html The HTML string to inject into the YUI instance
99 | * @param {Object} config Optional YUI Config object
100 | * @param {Function} fn The callback executed when the process is completed
101 | * @returns {Callback} Y, html Callback returns two arguments. Y is the Y instance created, html is the original HTML.
102 | */
103 | inter.fromString = function(html, config, fn) {
104 | if (typeof config === 'function') {
105 | fn = config;
106 | config = {};
107 | }
108 | makeYUIFromHTML(html, config, fn);
109 | };
110 |
111 | /**
112 | * Inspired by: https://github.com/visionmedia/query/
113 | */
114 | /**
115 | * This method listens for the process stdin and takes the html from it and injects it into a new YUI instance.
116 | * @method stdin
117 | * @param {Object} config Optional YUI Config object
118 | * @param {Function} fn The callback executed when the process is completed
119 | * @returns {Callback} Y, html Callback returns two arguments. Y is the Y instance created, html is the original HTML.
120 | */
121 | inter.stdin = function(config, fn) {
122 | if (typeof config === 'function') {
123 | fn = config;
124 | config = {};
125 | }
126 | var YUI = getYUI(config);
127 |
128 | var stdin = process.openStdin(),
129 | html = '';
130 |
131 | stdin.setEncoding('utf8');
132 | stdin.on('data', function(data) {
133 | html += data;
134 | });
135 | stdin.on('end', function() {
136 | makeYUIFromHTML(html, config, fn);
137 | });
138 |
139 | };
140 |
141 | //Helper method to make a YUI instance from a string, used in fromString and stdin
142 | var makeYUIFromHTML = function(html, config, fn) {
143 | var YUI = getYUI(config);
144 |
145 | YUI({ logInclude: { cli: true } , debug: true }).use('node', function(Y) {
146 | if (html.indexOf(' -1) {
150 | //This is an HTML doc
151 | Y.one('doc').set('innerHTML', html);
152 | } else if (html.indexOf('', null, {features: features});
26 | browser.window = browser.document.createWindow();
27 |
28 | // Setup an html doctype
29 | var doctype = new dom.DocumentType(browser.document, 'html');
30 | browser.document.doctype = doctype;
31 |
32 | browser.document.getElementsByTagName('head').item(0).appendChild(browser.document.createElement('title'));
33 |
34 |
35 | browser.document.scrollTop = browser.document.documentElement.scrollTop = browser.document.body.scrollTop = 0;
36 | browser.document.scrollLeft = browser.document.documentElement.scrollLeft = browser.document.body.scrollLeft = 0;
37 |
38 | browser.window.eval = eval;
39 |
40 | browser.self = browser.window;
41 | browser.navigator = browser.window.navigator;
42 | browser.location = browser.window.navigator;
43 |
44 |
45 | if (Y.config.UA) {
46 | browser.window.navigator.userAgent = Y.config.UA;
47 | }
48 |
49 | browser.window.focus = function() {};
50 | browser.window.blur = function() {};
51 | browser.window.scrollTo = function() {};
52 |
53 | Y.config.doc = browser.window.document;
54 | Y.config.win = browser.window;
55 |
56 | if (Y.config.UA) {
57 | Y.UA = YUI.Env.parseUA();
58 | }
59 |
60 | Y.Browser = browser;
61 |
62 | Y.processCSS();
63 |
64 | }, 'NODE', { requires: ['oop'], after: ['oop'] } );
65 |
66 |
--------------------------------------------------------------------------------
/lib/yui3-express.js:
--------------------------------------------------------------------------------
1 | /**
2 | * ExpressJS view engine for YUI3
3 | * @module express
4 | */
5 | YUI.add('express', function(Y) {
6 |
7 | if (YUI.express) {
8 | //Catch double loading of YUI().use('*');
9 | return;
10 | }
11 |
12 | var path = YUI.require('path'),
13 | fs = YUI.require('fs'),
14 | DEBUG = false;
15 | /**
16 | * The default content holder for partials, if one is not given this one is used.
17 | * @property defaultContent
18 | * @static
19 | */
20 | YUI.defaultContent = '#content';
21 |
22 | /**
23 | * Express middleware to "pre-parse" the layout and add it to a YUI instance
24 | * that is then bound to the req as req.Y. Calling res.send() will automatically call
25 | * Y.config.doc.outerHTML and echo to the response.
26 | * The middleware can be used like this: http://gist.github.com/657453
27 | * @static
28 | * @method express
29 | */
30 | YUI.express = function(req, res, next) {
31 | var fn = function(req, res, next, yConfig) {
32 | if (!req.Y) {
33 | var ua = req.headers['user-agent'];
34 | var config = {
35 | UA: ua
36 | };
37 | if (yConfig.config) {
38 | var c = yConfig.config;
39 | delete yConfig.config;
40 | for (var i in c) {
41 | config[i] = c[i];
42 | }
43 | if (!config.debug) {
44 | config.debug = DEBUG;
45 | }
46 | } else {
47 | config.debug = DEBUG;
48 | }
49 | YUI(config).use('*', function(Y) {
50 | Y.config.win.location.href = req.originalUrl;
51 | Y.express = yConfig;
52 | req.Y = res.Y = Y;
53 | if (yConfig.render) {
54 | res._ySend = res.send;
55 | res.sub = function(sub, fn) {
56 | var html = this.Y.config.doc.outerHTML,
57 | extraction = _substituteStylesAndScripts(html);
58 | this.Y.mix(sub, extraction.sub);
59 | html = this.Y.substitute(extraction.string, sub, fn, true);
60 | this.Y.config.doc.innerHTML = html;
61 | };
62 | res.send = function(str) {
63 | Y.config.doc.innerHTML = str;
64 | this.send = function() {
65 | this._ySend.call(this, Y.config.doc.outerHTML);
66 | req.Y = res.Y = null;
67 | YUI._express[Y.id] = Y;
68 | YUI.cleanExpress();
69 | };
70 | next();
71 | };
72 | var c = {};
73 | if (yConfig.locals) {
74 | c.locals = yConfig.locals;
75 | }
76 | res.render(yConfig.render, c);
77 | }
78 | });
79 | } else {
80 | next();
81 | }
82 | };
83 | if (req && res && next) {
84 | return fn.call(this, req, res, next);
85 | } else {
86 | return function(req2, res2, next2) {
87 | fn.call(this, req2, res2, next2, req);
88 | };
89 | }
90 |
91 | };
92 |
93 | /**
94 | * Extracts all