Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 111 lines (84 sloc) 2.756 kB
a608d33 @davglass Initial Import
authored
1 h1. YUI Bootstrapper for Node.js
2
3 This node.js module attempts to setup and bootstrap a working YUI 3 instance.
4 It does not support any DOM manipulation, but it gives you our class management
5 and language extras.
6
45e90aa @davglass Updated README with new IO calls
authored
7 This module includes support for remote script loading via Y.Get.script() and remote data fetching via Y.io.
a608d33 @davglass Initial Import
authored
8
9 h2. Setup this repo
10
11 <pre class="console">
5c83119 @davglass Updated README and removed submodule
authored
12 git clone git://github.com/davglass/nodejs-yui3.git
13
14 git clone git://github.com/yui/yui3.git
15
16 cd nodejs-yui3/lib
17
18 ln -s ../../yui3 ./
a608d33 @davglass Initial Import
authored
19 </pre>
20
5c83119 @davglass Updated README and removed submodule
authored
21
bc5be79 @davglass Updated README
authored
22 That should make everything work.
23
24 Now you can run this from the nodejs-yui3 root:
25 <pre class="console">
26 node ./test.js
27 </pre>
a608d33 @davglass Initial Import
authored
28
29 h2. Including the files
30
31 <pre class="console">
fc71bd3 @isaacs Update documentation
isaacs authored
32 // get the exported YUI object
33 var YUI = require('./lib/node-yui3')).YUI;
a608d33 @davglass Initial Import
authored
34 </pre>
35
36 h2. Using YUI
37
38 <pre class="console">
9d1d174 @isaacs Add a TODO regarding YUI 3's global usage.
isaacs authored
39 // load YUI
fc71bd3 @isaacs Update documentation
isaacs authored
40 var YUI = require("./lib/node-yui3").YUI;
a608d33 @davglass Initial Import
authored
41
42 //sys.puts('After: ' + sys.inspect(process.memoryUsage()));
43
44 //Now use non-DOM related YUI utilities
45 YUI({
46 filter: 'debug',
47 debug: true
7470ed5 @davglass Updated README with new IO calls
authored
48 }).use('gallery-yql', 'json', 'base', 'io-nodejs', function(Y) {
a608d33 @davglass Initial Import
authored
49
50 //sys.puts('Inside: ' + sys.inspect(process.memoryUsage()));
51 //Logger outputs with sys.puts
52 Y.log('This is a test');
53 //Lang is available
54 Y.log('Test: ' + Y.Lang.isBoolean(true), 'debug', 'myapp');
55
56 //Creating a simple class
57 var One = function() {
58 One.superclass.constructor.apply(this, arguments);
59 };
60 //Extending it with Y.Base so we have Custom Events and a lifecycle
61 Y.extend(One, Y.Base, {
62 test: function() {
63 this.publish('foo', {
64 emitFacade: true
65 });
66 this.fire('foo');
67 }
68 }, {
69 NAME: 'one'
70 });
71
72 //Create a new instance of our new class
73 var o = new One();
74 o.on('foo', function(o) {
75 Y.log('Foo Fired', 'debug', 'myapp');
76 //Y.log(o, 'debug');
77 });
78 o.test(); //Should fire the one:foo Event.
2997c10 @davglass Updated README
authored
79
80 //Make a YQL query
81 var q1 = new Y.yql('select * from github.user.info where (id = "davglass")');
82 q1.on('query', function(r) {
83 //Do something here.
84 sys.puts(sys.inspect(r));
85 });
45e90aa @davglass Updated README with new IO calls
authored
86
87 var url = 'http:/'+'/yuilibrary.com/gallery/api/user/davglass';
88 //url = 'http:/'+'/query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20location%3D90210&format=json';
89
90 Y.io(url, {
91 xdr: {
92 use: 'nodejs'
93 },
94 on: {
95 start: function() {
96 Y.log('Start IO', 'info', 'TEST');
97 },
98 success: function(id, o) {
99 //Y.log(o.responseText);
100 Y.log(Y.JSON.parse(o.responseText));
101 }
102 }
103 });
104
105
a608d33 @davglass Initial Import
authored
106 });
107 </pre>
108
109
110 Now you can run @node ./test.js@
Something went wrong with that request. Please try again.