Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 112 lines (79 sloc) 3.142 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
45e90aa @davglass Updated README with new IO calls
authored
5 This module includes support for remote script loading via Y.Get.script() and remote data fetching via Y.io.
a608d33 @davglass Initial Import
authored
6
04778c4 @davglass Moved around source and examples
authored
7 See "JSDom Support" below for DOM manipulation.
8
a608d33 @davglass Initial Import
authored
9 h2. Setup this repo
10
bac601b @davglass Updated README to remove the submodule step and add the checkout step
authored
11 Clone this project, then do this:
a608d33 @davglass Initial Import
authored
12 <pre class="console">
bac601b @davglass Updated README to remove the submodule step and add the checkout step
authored
13 cd nodejs-yui3/lib
14 git clone git://github.com/yui/yui3.git
a608d33 @davglass Initial Import
authored
15 </pre>
16
04778c4 @davglass Moved around source and examples
authored
17 You should go into that repo every now and then and do a git pull to keep it up to date with the latest YUI source.
18
19
20 h2. Node.js
21
22 These tests and examples are all known to be working with latest stable Node.js: v0.1.33
23
24 All of the examples and tests assume you nave @node@ in your path and they are all executable.
25
bac601b @davglass Updated README to remove the submodule step and add the checkout step
authored
26
04778c4 @davglass Moved around source and examples
authored
27 h2. JSDom Support
a608d33 @davglass Initial Import
authored
28
04778c4 @davglass Moved around source and examples
authored
29 Currently YUI 3 on Node.js supports "JSDom":http://github.com/tmpvar/jsom
30 It also requires my forked "node-htmlparser":http://github.com/davglass/node-htmlparser
31
32 Getting it up and running:
a608d33 @davglass Initial Import
authored
33
34 <pre class="console">
04778c4 @davglass Moved around source and examples
authored
35 mkdir ~/.node_libraries
36 cd ~/.node_libraries
37 wget http://github.com/tmpvar/jsdom/raw/master/lib/level1/core.js -O jsdom.js
38 wget http://github.com/tmpvar/jsdom/raw/master/lib/browser/index.js -O browser.js
39 wget http://github.com/davglass/node-htmlparser/raw/master/node-htmlparser.js
a608d33 @davglass Initial Import
authored
40 </pre>
41
04778c4 @davglass Moved around source and examples
authored
42 Now that the libraries are in the right places you can now use the dom related examples.
43
c4facb3 @davglass Added Y Browser example
authored
44
45 h2. Using the Y.Browser object
46
47 To comply with the "no-globals" CommonJS spec, there is no global document or window in this mode.
48 Just including the nodejs-dom module will create a fake dom for this instance.
49 You can create a document like this:
50 <pre class="console">
51 YUI().use('nodejs-dom', function(Y) {
52 // Y.Browser
53 {
54 window, //fake window
55 document, //jsdom document
56 self, //window
57 location, //window.location, has an href == __filename
58 navigator //Fake navigator, appVersion => Node version, appName => Node.js, userAgent => Custom for Node ;)
59 }
60 });
61 </pre>
62
63 Making older DOM code run:
64 <pre class="console">
65 YUI().use('nodejs-dom', function(Y) {
66 var document = Y.Browser.document;
67 document.createElement('div');
68 });
69 </pre>
70
71 If you are using YUI to serve pages, you should use a Nested Use to create the document when the request comes in.
72
73 Something like this:
74
75 Making older DOM code run:
76 <pre class="console">
77 YUI().use('event', 'io', function(Y) {
78 //Do your stuff
79
80 //Inside the request handler callback:
81 //Now each request get's a new DOM and not a shared one.
82 Y.use('nodejs-dom', function(Y) {
83 var document = Y.Browser.document;
84 document.createElement('div');
85 });
86 });
87 </pre>
88
3923dca @davglass README updates
authored
89 I have an example showing this: @examples/y-browser.js@
c4facb3 @davglass Added Y Browser example
authored
90
91
04778c4 @davglass Moved around source and examples
authored
92 h2. Examples
a608d33 @davglass Initial Import
authored
93
94 <pre class="console">
04778c4 @davglass Moved around source and examples
authored
95 cd examples/
96 ./general-dom.js
97 ./io.js
98 ./library.js
3923dca @davglass README updates
authored
99 ./y-brower.js
a608d33 @davglass Initial Import
authored
100 </pre>
101
04778c4 @davglass Moved around source and examples
authored
102 h2. Tests
103
104 When using JSDom, All relevent YUI 3 Dom & Selector tests pass. The ones that are skipped revolve around styles and postioning. Since there is no window or CSS cascade, these seem unimportant at the moment.
105
106 <pre class="console">
107 cd ./tests/
108 ./dom.js
109 ./selector.js
110 </pre>
a608d33 @davglass Initial Import
authored
111
Something went wrong with that request. Please try again.