├── .gitignore ├── .npmignore ├── DEVELOPER.markdown ├── INSTALL ├── LICENSE ├── Makefile ├── README.textile ├── compiler ├── Makefile ├── scripts │ ├── clean.sh │ ├── custom_source.js │ └── fetch_source.js ├── test │ ├── load-js.js │ ├── load.js │ └── rls.js ├── tools │ └── js2c.py ├── wscript ├── yui.cc ├── yui.h └── yui.js ├── examples ├── 2in3-meta.js ├── colors.js ├── config.js ├── configure.js ├── daemon.js ├── express │ ├── assets │ │ ├── main.js │ │ └── tabview.js │ ├── express.js │ └── views │ │ ├── index.html │ │ ├── layout.html │ │ ├── partials │ │ ├── layout_append.html │ │ ├── layout_head.html │ │ ├── layout_prepend.html │ │ └── test.html │ │ └── tabview.html ├── external-module.js ├── from-string.js ├── gallery-meta.js ├── gallery.js ├── general-dom.js ├── inside.js ├── io.js ├── library.js ├── loadDir.js ├── loader.js ├── markup │ ├── layout.html │ └── tabview.html ├── mods │ ├── mod1.js │ ├── mod2.js │ ├── mod3.js │ ├── modals │ │ ├── mod1.js │ │ ├── mod2.js │ │ └── mod3.js │ └── views │ │ ├── mod1.js │ │ ├── mod2.js │ │ └── mod3.js ├── module-dyn.js ├── module-groups.js ├── module.js ├── overlay-markup.js ├── overlay-script.js ├── parallel.js ├── process.js ├── rls.js ├── scrape-object.js ├── scrape.js ├── slider-script.js ├── stdin.js ├── sync-mod.js ├── sync-module.js ├── sync.js ├── tabview-markup.js ├── tabview-script.js ├── tnt-calendar-script.js ├── tnt-calendar-serve.js ├── tnt-datatable-script.js ├── tnt-layout-script.js ├── trap-error.js ├── trap-test.js ├── versions.js ├── y-browser.js ├── y-server-template.js └── y-server.js ├── lib ├── node-yui3.js ├── yui3-dom-after.js ├── yui3-dom.js ├── yui3-express.js ├── yui3-files.js ├── yui3-io.js ├── yui3-node.js ├── yui3-parallel.js ├── yui3-rls.js └── yui3-yui3.js ├── packages ├── bare-package.json ├── base-package.json ├── default-package.json └── full-package.json ├── perf └── load.js ├── scripts ├── deps.sh ├── install.sh ├── make_package.sh ├── merge_package_json.js ├── publish.sh └── test.sh └── tests ├── deps.js ├── dom.js ├── extras ├── loader-debug.js └── loader-min.js ├── html ├── dd.html ├── dom.html ├── node.html └── selector.html ├── interface.js ├── manual ├── comments.html ├── comments.js └── dd.js ├── node.js ├── selector.js └── yql.js /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | compiler/.lock-wscript 3 | compiler/build/* 4 | compiler/src/* 5 | tests/node_modules 6 | examples/node_modules 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git 2 | sandbox 3 | yui3 4 | -------------------------------------------------------------------------------- /DEVELOPER.markdown: -------------------------------------------------------------------------------- 1 | ##Packaging 2 | 3 | To install from this source tree: 4 | 5 | make dev 6 | 7 | To make all packages 8 | 9 | make all 10 | make install 11 | 12 | ##Testing the latest YUI release with Node 13 | 14 | I've tried to make it simple to test the latest YUI source code against my nodejs package. 15 | First you need to install yuitest: 16 | 17 | npm install yuitest 18 | 19 | Now, go into your clone of the yui3 source tree and npm install it: 20 | 21 | cd /path/to/yui3 22 | npm install . 23 | 24 | Now you can test this code: 25 | 26 | yuitest ./tests/*.js 27 | 28 | Currently there are over 100 tests that should pass 100% if your YUI3 code works ;) 29 | 30 | ##Developing 31 | 32 | If you are patching YUI core or working with Dom/Event/Node code, you really need to check to make sure 33 | that your code doesn't contain things that will break on the server. Each time you do a build, you should also 34 | follow the steps above to `npm install` then `yuitest ./tests/*.js` to make sure you didn't introduce a 35 | change that will break when your code is executed on the server. 36 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | This repository includes 3 yui3 npm packages. bare, base and full. 2 | 3 | Bare: 4 | This package is just the contents of this repository with a package.json file that 5 | contains no dependencies. This package should only be used if you are providing your 6 | own special yui3-core package. 7 | 8 | Base: 9 | This package is the contents of this directory with the dependency of yui3-core. This 10 | package assumes you are running YUI3 inside of NodeJS without needing DOM. Even tho 11 | DOM support is in this package, jsom and other dependencies will not be installed. 12 | 13 | Full: 14 | The original YUI3 source package that requires the dependencies required for using DOM 15 | on the server. 16 | 17 | 18 | Installation: 19 | 20 | make: Will make all 3 packages 21 | make && make install: Will make all 3 packages and install them via npm 22 | 23 | make bare: Will only make the bare package 24 | make base: Will only make the base package 25 | make full: Will only make the full package 26 | 27 | make full && make install: Will make the full package and install it 28 | 29 | make clean: Will delete the ./build directory 30 | 31 | make test: Will run the yuitest's for this project 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010 Yahoo! Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the Yahoo! Inc. nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL YAHOO! INC. BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: deps clean bare base full 2 | 3 | full: deps 4 | @./scripts/make_package.sh full 5 | 6 | bare: deps 7 | @./scripts/make_package.sh bare 8 | 9 | base: deps 10 | @./scripts/make_package.sh base 11 | 12 | publish: deps all test 13 | @./scripts/publish.sh 14 | 15 | dev: deps clean full 16 | @echo "make clean && make full DONE" 17 | @echo "Now you can: npm install /path/to/source/yui3/build/full to install it locally" 18 | @echo "Or you can: npm link /path/to/source/yui3/build/full to link it into your project" 19 | 20 | test: deps 21 | @./scripts/test.sh 22 | 23 | tests: test 24 | isntall: install 25 | 26 | install: deps all 27 | @./scripts/install.sh 28 | 29 | deps: ./scripts/deps.sh 30 | 31 | clean: 32 | rm -rRf ./build/ 33 | 34 | help: 35 | @cat ./INSTALL 36 | 37 | .PHONY: all install test bare base full publish clean deps test help 38 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. YUI Bootstrapper for Node.js 2 | 3 | The YUI3NodeJS project uses several 3rd party open source libraries and tools. 4 | 5 | This file summarizes the tools used, their purpose, and the licenses under which they're released. 6 | 7 | This node.js module attempts to setup and bootstrap a working YUI 3 instance. 8 | 9 | This module includes support for remote script loading via Y.Get.script() and remote data fetching via Y.io. 10 | 11 | See "JSDom Support" below for DOM manipulation. 12 | 13 | h2. Node.js 14 | 15 | All of the examples and tests assume you have @node@ in your path and they are all executable. 16 | 17 | h2. Dependencies 18 | 19 | All dependencies are installed when you install the yui3 package via @npm@ 20 | 21 | For server side dom manipulation, you need the following packages installed: 22 | 23 | "JSDom":http://github.com/tmpvar/jsdom : "LICENSE":http://github.com/tmpvar/jsdom/blob/master/LICENSE.txt 24 | 25 |
npm install jsdom
26 | 27 | "HTML Parser":http://github.com/tautologistics/node-htmlparser : "LICENSE":http://github.com/tautologistics/node-htmlparser/blob/master/LICENSE 28 | 29 |
npm install htmlparser
30 | 31 | h2. Optional Dependancies 32 | 33 | "Express":http://expressjs.com/ : LICENSE (MIT) 34 | 35 |
npm install express
36 | 37 | "Connect":http://github.com/senchalabs/connect : LICENSE (MIT) 38 | 39 |
npm install connect
40 | 41 | h2. Installing - via NPM 42 | 43 |
 44 | npm install yui3
 45 | 
46 | 47 | h2. Installing - as a developer 48 | 49 | You must have git and npm installed before you can develop. 50 | 51 |
 52 | git clone git://github.com/davglass/nodejs-yui3.git
 53 | cd nodejs-yui3/
 54 | npm install .
 55 | 
56 | 57 | h2. Using YUI3 58 | 59 | "This is the general-dom example":http://gist.github.com/541501 60 | 61 | h2. Remote Fetching 62 | 63 | "This example shows fetching a remote document and then using Node to modify it":http://gist.github.com/574000 64 | 65 | h2. Using the Y.Browser object 66 | 67 | To comply with the "no-globals" CommonJS spec, there is no global document or window in this mode. 68 | Just including the nodejs-dom module will create a fake dom for this instance. 69 | You can create a document like this: 70 | "View this Gist":http://gist.github.com/359776 71 | 72 | You can make older DOM code run by setting up a couple of local variables, "like this":http://gist.github.com/359778 73 | 74 | 75 | If you are using YUI to serve pages, you should use a Nested Use to create the document when the request comes in. 76 | 77 | "Something like this":http://gist.github.com/359781 78 | 79 | 80 | I have an example showing this: @examples/y-browser.js@ 81 | 82 | 83 | h2. Examples 84 | 85 |
 86 |     cd examples/
 87 |     ./general-dom.js
 88 |     ./io.js
 89 |     ./library.js
 90 |     ./y-brower.js
 91 | 
92 | 93 | h2. Tests 94 | 95 | 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. 96 | 97 | Testing is pretty simple now once you install `yuitest`: 98 | 99 |
100 |     npm install yuitest
101 |     yuitest ./tests/*.js
102 | 
103 | 104 | h2. License 105 | 106 | This software is offered under the terms of the BSD license. See the LICENSE file or the "YUI License":http://developer.yahoo.com/yui/license.html for license text and copyright information. 107 | 108 | h2. Contribute 109 | 110 | Your contributions are welcome! Please review the "YUI contributor guide":http://developer.yahoo.com/yui/community/#cla before contributing. If you haven't contributed to a "YUI project":http://yuilibrary.com before, you'll need to review and sign the "YUI CLA":http://developer.yahoo.com/yui/community/#cla before we can accept your pull request. 111 | 112 | 113 | -------------------------------------------------------------------------------- /compiler/Makefile: -------------------------------------------------------------------------------- 1 | all: files source 2 | 3 | source: 4 | node-waf configure build 5 | 6 | files: clean 7 | ./scripts/fetch_source.js 8 | make sync 9 | 10 | sync: 11 | cat ../lib/* >> ./src/lib/nodejs_yui3.js 12 | cp ./src/yui.js ./src/lib/ 13 | 14 | clean: 15 | ./scripts/clean.sh 16 | -------------------------------------------------------------------------------- /compiler/scripts/clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -d ./build ]; then 4 | rm -r ./build 5 | fi 6 | 7 | if [ -d ./src ]; then 8 | rm -r ./src 9 | mkdir ./src 10 | fi 11 | 12 | if [ -d .lock-wscript ]; then 13 | rm -r .lock-wscript 14 | fi 15 | 16 | -------------------------------------------------------------------------------- /compiler/scripts/custom_source.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var yui3 = require('yui3'), 4 | fs = require('fs'), 5 | path = require('path'), 6 | cli = require('cli'), 7 | start = (new Date()).getTime(); 8 | 9 | post = path.join(__dirname, '../src/lib'); 10 | 11 | if (!path.existsSync(post)) { 12 | fs.mkdirSync(post, 0777); 13 | } 14 | 15 | 16 | cli.enable('status', 'help'); 17 | cli.parse({ 18 | modules: ['m', 'Required: Comma seperated list of modules to pass to YUI().use()', 'string'], 19 | filter: ['f', 'The file type to produce: debug, raw, min', 'string', 'min'], 20 | version: ['v', 'The YUI version to use', 'string', '3.3.0'], 21 | gversion: ['gv', 'The Gallery version to use', 'string'], 22 | yui2: ['yui2', 'The YUI2 version to use', 'string', '2.8.0'] 23 | }); 24 | 25 | var parseUse = function(u) { 26 | u = u.replace(/ /g, '').split(','); 27 | return u; 28 | } 29 | 30 | cli.main(function() { 31 | if (!this.options.modules) { 32 | cli.getUsage(); 33 | return; 34 | } 35 | 36 | var opts = this.options; 37 | //Hack to make sure loader is in the queue 38 | var o = opts.modules.split(','); 39 | o.push('loader'); 40 | opts.modules = o.join(','); 41 | var config = { 42 | m: opts.modules, 43 | v: opts.version, 44 | parse: true, 45 | filt: opts.filter, 46 | '2in3v': opts.yui2 47 | }; 48 | config.env = 'get'; 49 | 50 | if (opts.gversion) { 51 | config.gv = opts.gversion; 52 | } 53 | yui3.rls(config, function(err, data) { 54 | var size = 0; 55 | var d = [], 56 | pre = [], 57 | count = 0; 58 | console.log(data.js); 59 | for (var k in data.d) { 60 | size += data.d[k].length; 61 | if (count < 2) { 62 | pre.push(data.d[k]); 63 | } else { 64 | //d.push(data.d[k]); 65 | var parts = k.split('/'); 66 | //Only test against minned files. all others will be loaded from disk 67 | var name = (parts[parts.length - 1]).replace(/-/g, '_').replace('_min.js', ''); 68 | 69 | fs.writeFileSync(path.join(post, name + '.js'), data.d[k], encoding='utf8'); 70 | } 71 | 72 | count++; 73 | }; 74 | fs.writeFileSync(path.join(__dirname, '../src/yui.js'), pre.join('\n'), encoding='utf8'); 75 | 76 | console.log('Files: ', d.length); 77 | console.log('Build Time: %sms', (new Date()).getTime() - start); 78 | }); 79 | 80 | }); 81 | 82 | -------------------------------------------------------------------------------- /compiler/scripts/fetch_source.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var yui3 = require('yui3-core@3.3.0').path(), 4 | fs = require('fs'), 5 | path = require('path'), 6 | util = require('util'), 7 | noop = function() {}, 8 | copyFile = function(src, dest, cb) { 9 | var is = fs.createReadStream(src); 10 | var os = fs.createWriteStream(dest, { flags: 'a+' }); 11 | util.pump(is, os, cb); 12 | }, 13 | yui3_base = path.join(yui3, 'build'), 14 | pre = path.join(__dirname, '../src/yui.js'), 15 | post = path.join(__dirname, '../src/lib'); 16 | 17 | if (!path.existsSync(post)) { 18 | fs.mkdirSync(post, 0777); 19 | } 20 | 21 | console.log('Reading Main Directory'); 22 | var dirs = fs.readdirSync(yui3_base); 23 | 24 | var preFiles = []; 25 | var finalFiles = []; 26 | 27 | dirs.forEach(function(d) { 28 | if (d.indexOf('.') === 0) { 29 | return; 30 | } 31 | files = fs.readdirSync(path.join(yui3_base, d)); 32 | files.forEach(function(file) { 33 | switch (file) { 34 | case 'text-data-accentfold-min.js': 35 | case 'text-min.js': 36 | case 'text-data-wordbreak-min.js': 37 | //Non-Ascii Characters, need to fix this in the C file 38 | return; 39 | } 40 | if (d === 'yui' || d === 'loader' || d === 'io') { 41 | if (file.indexOf(d + '-min.js') === 0) { 42 | preFiles.push(path.join(yui3_base, d, file)); 43 | } 44 | return; 45 | } else { 46 | if (file.indexOf('-min.js') > 0) { 47 | finalFiles.push({ file: path.join(yui3_base, d, file), name: file.replace(/-/g, '_').replace('_min.js', '.js') }); 48 | } 49 | } 50 | }); 51 | }); 52 | 53 | preFiles = preFiles.reverse(); //YUI needs to come first ;) 54 | 55 | copyFile(preFiles[0], pre, function() { 56 | copyFile(preFiles[1], pre, noop); 57 | }); 58 | 59 | var copy = function() { 60 | if (finalFiles.length) { 61 | var i = finalFiles.pop(); 62 | copyFile(i.file, path.join(post, i.name), copy); 63 | } 64 | } 65 | console.log('Copying', finalFiles.length, 'files'); 66 | copy(); 67 | 68 | -------------------------------------------------------------------------------- /compiler/test/load-js.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var startTime = (new Date()).getTime(), 4 | times = [], 5 | max = 500; 6 | 7 | for (var i = 0; i < max; i++) { 8 | var start = (new Date()).getTime(); 9 | var YUI = require('yui3').YUI; 10 | YUI({debug: false}).useSync('yql'); 11 | var end = (new Date()).getTime(); 12 | times.push((end - start)); 13 | } 14 | 15 | var endTime = (new Date()).getTime(), 16 | t = 0; 17 | times.forEach(function(v) { 18 | t += v; 19 | }); 20 | 21 | console.log('Test time: ', ((endTime - startTime) / 1000), 'sec'); 22 | console.log('Average Time: ', ((t / max) / 1000), 'sec'); 23 | 24 | -------------------------------------------------------------------------------- /compiler/test/load.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var util = require('util'), 3 | assert = require('assert'), 4 | i, start, end, times, startTime, endTime, t, 5 | max = 10500; 6 | 7 | console.log('Starting C++ Load test with', max, 'requires'); 8 | 9 | var print = function(i) { 10 | var per = Math.round(Math.max((i / max) * 100)), 11 | bar = '', o; 12 | for (o = 0; o < 50; o++) { 13 | if ((o*2) <= per) { 14 | bar += '#'; 15 | } 16 | } 17 | util.print('\r(' + i + ') ' + per + '% ' + bar); 18 | } 19 | 20 | startTime = (new Date()).getTime(); 21 | times = []; 22 | 23 | for (var i = 0; i <= max; i++) { 24 | start = (new Date()).getTime(); 25 | var yui3 = require('../yui'); 26 | var YUI = yui3.YUI; 27 | var Y = YUI({debug: false}).useSync('yql'); 28 | //assert.ok(Y.YQL); 29 | end = (new Date()).getTime(); 30 | times.push((end - start)); 31 | print(i); 32 | } 33 | 34 | endTime = (new Date()).getTime(); 35 | t = 0; 36 | 37 | times.forEach(function(v) { 38 | t += v; 39 | }); 40 | 41 | util.print('\r\n'); 42 | console.log('Test time: ', ((endTime - startTime) / 1000), 'sec'); 43 | console.log('Average Time: ', ((t / max) / 1000), 'sec'); 44 | 45 | -------------------------------------------------------------------------------- /compiler/test/rls.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var start = (new Date()).getTime(); 3 | var yui3 = require('yui3-compiled'); 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 | -------------------------------------------------------------------------------- /compiler/tools/js2c.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2006-2008 the V8 project authors. All rights reserved. 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are 6 | # met: 7 | # 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above 11 | # copyright notice, this list of conditions and the following 12 | # disclaimer in the documentation and/or other materials provided 13 | # with the distribution. 14 | # * Neither the name of Google Inc. nor the names of its 15 | # contributors may be used to endorse or promote products derived 16 | # from this software without specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | # This is a utility for converting JavaScript source code into C-style 31 | # char arrays. It is used for embedded JavaScript code in the V8 32 | # library. 33 | 34 | import os 35 | from os.path import dirname 36 | import re 37 | import sys 38 | import string 39 | 40 | sys.path.append(dirname(__file__) + "/../deps/v8/tools"); 41 | import jsmin 42 | 43 | 44 | def ToCArray(filename, lines): 45 | result = [] 46 | row = 1 47 | col = 0 48 | for chr in lines: 49 | col += 1 50 | if chr == "\n" or chr == "\r": 51 | row += 1 52 | col = 0 53 | 54 | value = ord(chr) 55 | 56 | if value > 128: 57 | print 'non-ascii value ' + filename + ':' + str(row) + ':' + str(col) 58 | sys.exit(1); 59 | 60 | result.append(str(value)) 61 | result.append("0") 62 | return ", ".join(result) 63 | 64 | 65 | def CompressScript(lines, do_jsmin): 66 | # If we're not expecting this code to be user visible, we can run it through 67 | # a more aggressive minifier. 68 | if do_jsmin: 69 | minifier = JavaScriptMinifier() 70 | return minifier.JSMinify(lines) 71 | 72 | # Remove stuff from the source that we don't want to appear when 73 | # people print the source code using Function.prototype.toString(). 74 | # Note that we could easily compress the scripts mode but don't 75 | # since we want it to remain readable. 76 | #lines = re.sub('//.*\n', '\n', lines) # end-of-line comments 77 | #lines = re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', lines) # comments. 78 | #lines = re.sub('\s+\n+', '\n', lines) # trailing whitespace 79 | return lines 80 | 81 | 82 | def ReadFile(filename): 83 | file = open(filename, "rt") 84 | try: 85 | lines = file.read() 86 | finally: 87 | file.close() 88 | return lines 89 | 90 | 91 | def ReadLines(filename): 92 | result = [] 93 | for line in open(filename, "rt"): 94 | if '#' in line: 95 | line = line[:line.index('#')] 96 | line = line.strip() 97 | if len(line) > 0: 98 | result.append(line) 99 | return result 100 | 101 | 102 | def LoadConfigFrom(name): 103 | import ConfigParser 104 | config = ConfigParser.ConfigParser() 105 | config.read(name) 106 | return config 107 | 108 | 109 | def ParseValue(string): 110 | string = string.strip() 111 | if string.startswith('[') and string.endswith(']'): 112 | return string.lstrip('[').rstrip(']').split() 113 | else: 114 | return string 115 | 116 | 117 | def ExpandConstants(lines, constants): 118 | for key, value in constants.items(): 119 | lines = lines.replace(key, str(value)) 120 | return lines 121 | 122 | 123 | def ExpandMacros(lines, macros): 124 | for name, macro in macros.items(): 125 | start = lines.find(name + '(', 0) 126 | while start != -1: 127 | # Scan over the arguments 128 | assert lines[start + len(name)] == '(' 129 | height = 1 130 | end = start + len(name) + 1 131 | last_match = end 132 | arg_index = 0 133 | mapping = { } 134 | def add_arg(str): 135 | # Remember to expand recursively in the arguments 136 | replacement = ExpandMacros(str.strip(), macros) 137 | mapping[macro.args[arg_index]] = replacement 138 | while end < len(lines) and height > 0: 139 | # We don't count commas at higher nesting levels. 140 | if lines[end] == ',' and height == 1: 141 | add_arg(lines[last_match:end]) 142 | last_match = end + 1 143 | elif lines[end] in ['(', '{', '[']: 144 | height = height + 1 145 | elif lines[end] in [')', '}', ']']: 146 | height = height - 1 147 | end = end + 1 148 | # Remember to add the last match. 149 | add_arg(lines[last_match:end-1]) 150 | result = macro.expand(mapping) 151 | # Replace the occurrence of the macro with the expansion 152 | lines = lines[:start] + result + lines[end:] 153 | start = lines.find(name + '(', end) 154 | return lines 155 | 156 | class TextMacro: 157 | def __init__(self, args, body): 158 | self.args = args 159 | self.body = body 160 | def expand(self, mapping): 161 | result = self.body 162 | for key, value in mapping.items(): 163 | result = result.replace(key, value) 164 | return result 165 | 166 | class PythonMacro: 167 | def __init__(self, args, fun): 168 | self.args = args 169 | self.fun = fun 170 | def expand(self, mapping): 171 | args = [] 172 | for arg in self.args: 173 | args.append(mapping[arg]) 174 | return str(self.fun(*args)) 175 | 176 | CONST_PATTERN = re.compile('^const\s+([a-zA-Z0-9_]+)\s*=\s*([^;]*);$') 177 | MACRO_PATTERN = re.compile('^macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$') 178 | PYTHON_MACRO_PATTERN = re.compile('^python\s+macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$') 179 | 180 | def ReadMacros(lines): 181 | constants = { } 182 | macros = { } 183 | for line in lines: 184 | hash = line.find('#') 185 | if hash != -1: line = line[:hash] 186 | line = line.strip() 187 | if len(line) is 0: continue 188 | const_match = CONST_PATTERN.match(line) 189 | if const_match: 190 | name = const_match.group(1) 191 | value = const_match.group(2).strip() 192 | constants[name] = value 193 | else: 194 | macro_match = MACRO_PATTERN.match(line) 195 | if macro_match: 196 | name = macro_match.group(1) 197 | args = map(string.strip, macro_match.group(2).split(',')) 198 | body = macro_match.group(3).strip() 199 | macros[name] = TextMacro(args, body) 200 | else: 201 | python_match = PYTHON_MACRO_PATTERN.match(line) 202 | if python_match: 203 | name = python_match.group(1) 204 | args = map(string.strip, python_match.group(2).split(',')) 205 | body = python_match.group(3).strip() 206 | fun = eval("lambda " + ",".join(args) + ': ' + body) 207 | macros[name] = PythonMacro(args, fun) 208 | else: 209 | raise ("Illegal line: " + line) 210 | return (constants, macros) 211 | 212 | 213 | HEADER_TEMPLATE = """\ 214 | #ifndef node_natives_h 215 | #define node_natives_h 216 | namespace node { 217 | 218 | %(source_lines)s\ 219 | 220 | struct _native { 221 | const char* name; 222 | const char* source; 223 | }; 224 | 225 | static const struct _native natives[] = { 226 | 227 | %(native_lines)s\ 228 | 229 | { NULL, NULL } /* sentinel */ 230 | 231 | }; 232 | 233 | } 234 | #endif 235 | """ 236 | 237 | 238 | NATIVE_DECLARATION = """\ 239 | { "%(id)s", %(id)s_native }, 240 | """ 241 | 242 | SOURCE_DECLARATION = """\ 243 | const char %(id)s_native[] = { %(data)s }; 244 | """ 245 | 246 | 247 | GET_DELAY_INDEX_CASE = """\ 248 | if (strcmp(name, "%(id)s") == 0) return %(i)i; 249 | """ 250 | 251 | 252 | GET_DELAY_SCRIPT_SOURCE_CASE = """\ 253 | if (index == %(i)i) return Vector(%(id)s, %(length)i); 254 | """ 255 | 256 | 257 | GET_DELAY_SCRIPT_NAME_CASE = """\ 258 | if (index == %(i)i) return Vector("%(name)s", %(length)i); 259 | """ 260 | 261 | def JS2C(source, target): 262 | ids = [] 263 | delay_ids = [] 264 | modules = [] 265 | # Locate the macros file name. 266 | consts = {} 267 | macros = {} 268 | 269 | for s in source: 270 | if 'macros.py' == (os.path.split(str(s))[1]): 271 | (consts, macros) = ReadMacros(ReadLines(str(s))) 272 | else: 273 | modules.append(s) 274 | 275 | # Build source code lines 276 | source_lines = [ ] 277 | source_lines_empty = [] 278 | 279 | native_lines = [] 280 | 281 | for s in modules: 282 | delay = str(s).endswith('-delay.js') 283 | lines = ReadFile(str(s)) 284 | do_jsmin = lines.find('// jsminify this file, js2c: jsmin') != -1 285 | 286 | lines = ExpandConstants(lines, consts) 287 | lines = ExpandMacros(lines, macros) 288 | lines = CompressScript(lines, do_jsmin) 289 | data = ToCArray(s, lines) 290 | id = (os.path.split(str(s))[1])[:-3] 291 | if delay: id = id[:-6] 292 | if delay: 293 | delay_ids.append((id, len(lines))) 294 | else: 295 | ids.append((id, len(lines))) 296 | source_lines.append(SOURCE_DECLARATION % { 'id': id, 'data': data }) 297 | source_lines_empty.append(SOURCE_DECLARATION % { 'id': id, 'data': 0 }) 298 | native_lines.append(NATIVE_DECLARATION % { 'id': id }) 299 | 300 | # Build delay support functions 301 | get_index_cases = [ ] 302 | get_script_source_cases = [ ] 303 | get_script_name_cases = [ ] 304 | 305 | i = 0 306 | for (id, length) in delay_ids: 307 | native_name = "native %s.js" % id 308 | get_index_cases.append(GET_DELAY_INDEX_CASE % { 'id': id, 'i': i }) 309 | get_script_source_cases.append(GET_DELAY_SCRIPT_SOURCE_CASE % { 310 | 'id': id, 311 | 'length': length, 312 | 'i': i 313 | }) 314 | get_script_name_cases.append(GET_DELAY_SCRIPT_NAME_CASE % { 315 | 'name': native_name, 316 | 'length': len(native_name), 317 | 'i': i 318 | }); 319 | i = i + 1 320 | 321 | for (id, length) in ids: 322 | native_name = "native %s.js" % id 323 | get_index_cases.append(GET_DELAY_INDEX_CASE % { 'id': id, 'i': i }) 324 | get_script_source_cases.append(GET_DELAY_SCRIPT_SOURCE_CASE % { 325 | 'id': id, 326 | 'length': length, 327 | 'i': i 328 | }) 329 | get_script_name_cases.append(GET_DELAY_SCRIPT_NAME_CASE % { 330 | 'name': native_name, 331 | 'length': len(native_name), 332 | 'i': i 333 | }); 334 | i = i + 1 335 | 336 | # Emit result 337 | output = open(str(target[0]), "w") 338 | output.write(HEADER_TEMPLATE % { 339 | 'builtin_count': len(ids) + len(delay_ids), 340 | 'delay_count': len(delay_ids), 341 | 'source_lines': "\n".join(source_lines), 342 | 'native_lines': "\n".join(native_lines), 343 | 'get_index_cases': "".join(get_index_cases), 344 | 'get_script_source_cases': "".join(get_script_source_cases), 345 | 'get_script_name_cases': "".join(get_script_name_cases) 346 | }) 347 | output.close() 348 | 349 | if len(target) > 1: 350 | output = open(str(target[1]), "w") 351 | output.write(HEADER_TEMPLATE % { 352 | 'builtin_count': len(ids) + len(delay_ids), 353 | 'delay_count': len(delay_ids), 354 | 'source_lines': "\n".join(source_lines_empty), 355 | 'get_index_cases': "".join(get_index_cases), 356 | 'get_script_source_cases': "".join(get_script_source_cases), 357 | 'get_script_name_cases': "".join(get_script_name_cases) 358 | }) 359 | output.close() 360 | 361 | def main(): 362 | natives = sys.argv[1] 363 | source_files = sys.argv[2:] 364 | JS2C(source_files, [natives]) 365 | 366 | if __name__ == "__main__": 367 | main() 368 | -------------------------------------------------------------------------------- /compiler/wscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import re 4 | import Options 5 | import sys, os, shutil, glob 6 | import Utils 7 | from Utils import cmd_output 8 | from os.path import join, dirname, abspath, normpath 9 | from logging import fatal 10 | 11 | 12 | srcdir = "." 13 | blddir = "build" 14 | VERSION = "0.1.0" 15 | 16 | sys.path.append('./tools'); 17 | import js2c 18 | 19 | def set_options(opt): 20 | opt.tool_options("compiler_cxx") 21 | 22 | def configure(conf): 23 | conf.check_tool("compiler_cxx") 24 | conf.check_tool("node_addon") 25 | 26 | def build(bld): 27 | print "Preparing to Build YUI3" 28 | obj = bld.new_task_gen("cxx", "shlib", "node_addon") 29 | obj.target = "yui3-compiled" 30 | obj.source = "yui.cc" 31 | 32 | def javascript_in_c(task): 33 | print "Compiling YUI Source Files into C files, this may take a little bit \m/" 34 | env = task.env 35 | source = map(lambda x: x.srcpath(env), task.inputs) 36 | targets = map(lambda x: x.srcpath(env), task.outputs) 37 | #source.append(macros_loc_default) 38 | js2c.JS2C(source, targets) 39 | 40 | native_cc = bld.new_task_gen( 41 | source=bld.path.ant_glob('src/lib/*.js'), 42 | target="yui_natives.h", 43 | before="cxx", 44 | install_path=None 45 | ) 46 | 47 | native_cc.rule = javascript_in_c 48 | 49 | -------------------------------------------------------------------------------- /compiler/yui.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "build/default/yui_natives.h" 4 | #include 5 | #include 6 | 7 | using namespace v8; 8 | 9 | namespace node { 10 | 11 | const char* MainSource() { 12 | return yui_native; 13 | } 14 | 15 | extern "C" void init(Handle target) { 16 | HandleScope scope; 17 | 18 | for (int i = 0; natives[i].name; i++) { 19 | Local name = String::New(natives[i].name); 20 | Local source = String::New(natives[i].source); 21 | target->Set(name, source); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /compiler/yui.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace node { 4 | 5 | void DefineJavaScript(v8::Handle 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('
    ' + html + '
'); 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 RightToggle Left 21 | Close LeftAdd 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 = '

        foo content

        bar content

        baz content

        '; 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