Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit f7252ca97497e4860e5933d569e32ea4b29e8da4 @davglass committed Feb 23, 2011
Showing with 210 additions and 0 deletions.
  1. +30 −0 LICENSE
  2. +35 −0 README.md
  3. +122 −0 bin/yui-repl.js
  4. +23 −0 package.json
30 LICENSE
@@ -0,0 +1,30 @@
+Software License Agreement (BSD License)
+
+Copyright (c) 2007, Dav Glass <dav.glass@yahoo.com>.
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms, with or without modification, are
+permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* The name of Dav Glass may not be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of Dav Glass.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
@@ -0,0 +1,35 @@
+# YUI REPL
+
+A NodeJS REPL environment reloaded with a Y variable populated by a YUI sandbox.
+
+## Install
+
+ npm install yui-repl
+
+## Usage
+
+ yui3
+
+
+## Commands
+
+`.import {url}` Import this url into the REPL context and bind Y to the DOM.
+ .import http://yuilibrary.com/
+ .import http://twitter.com/
+ .import http://yahoo.com/
+
+
+`.use {modules,to,use}` Modules to load into to the Y context inside the REPL
+ .use dd
+ .use yql,io
+ .use jsonp,io
+
+`.io {url}` Make an IO request to the passed URL
+ .io https://graph.facebook.com/davglass
+ .io http://yuilibrary.com/gallery/api/show/yql
+
+`.yql {sql}` Make an YQL request with the passed SQL statement
+ .yql select * from weather.forecast where location=90210
+ .yql select * from flickr.photos.recent
+
+
@@ -0,0 +1,122 @@
+#!/usr/bin/env node
+
+var net = require('net'),
+ util = require('util'),
+ replServer = require('repl');
+
+require('colors');
+
+
+var Y = require('yui3').silent().useSync('yui-base');
+
+Y.toString = function() {
+ return 'Dav was here..'
+};
+
+var repl = replServer.start('YUI@' + Y.version + '> ');
+var ctx = repl.context;
+ctx.Y = Y;
+
+repl.defineCommand('clear', {
+ help: 'Clear the current Y context',
+ action: function() {
+ this.outputStream.write('Resetting Y to the default state\n');
+ this.bufferedCommand = '';
+ this.context.Y = require('yui3').silent().useSync('yui-base');
+ this.displayPrompt();
+ }
+});
+
+var load = function(url) {
+ var self = this;
+ self.outputStream.write('Fetching URL: '.magenta + url.yellow);
+ this.context.Y.load(url, function() {
+ self.outputStream.write(' [done]\n'.white);
+ self.displayPrompt();
+ });
+};
+
+repl.defineCommand('import', {
+ help: 'Import a document into this context',
+ action: load
+});
+
+repl.defineCommand('load', {
+ help: 'Alias for import',
+ action: load
+});
+
+repl.defineCommand('fetch', {
+ help: 'Alias for import',
+ action: load
+});
+
+repl.defineCommand('version', {
+ help: 'Show the YUI version',
+ action: function() {
+ this.outputStream.write('Current YUI Version: '.magenta + this.context.Y.version.yellow + '\n');
+ this.displayPrompt();
+ }
+});
+
+repl.defineCommand('use', {
+ help: 'Comma seperated list of modules to use inside this Y context',
+ action: function(l) {
+ var args = l.split(',');
+ this.outputStream.write('Using modules: '.magenta + l);
+ this.context.Y.useSync.apply(this.context.Y, args);
+ this.outputStream.write(' [done]\n'.white);
+ this.displayPrompt();
+ }
+});
+
+repl.defineCommand('io', {
+ help: 'Make an IO request to the passed URL',
+ action: function(url) {
+ var self = this,
+ Y = this.context.Y;
+ self.outputStream.write('Making IO Request: '.magenta + url.yellow);
+ Y.use('io', function() {
+ Y.io(url, {
+ on: {
+ complete: function(id, e) {
+ self.outputStream.write(' [done]\n'.white);
+ var str;
+ try {
+ str = util.inspect(JSON.parse(e.responseText), false, 1, true);
+ } catch (e) {
+ str = e.responseText
+ }
+ self.outputStream.write(str);
+ self.outputStream.write('\n');
+ self.displayPrompt();
+ }
+ }
+ });
+ });
+ }
+});
+
+repl.defineCommand('yql', {
+ help: 'Make an YQL request with the passed SQL statement',
+ action: function(sql) {
+ var self = this,
+ Y = this.context.Y;
+ self.outputStream.write('Making YQL Request: '.magenta + sql.yellow);
+ Y.use('yql', function() {
+ Y.YQL(sql, function(r) {
+ self.outputStream.write(' [done]\n'.white);
+ var str;
+ try {
+ str = util.inspect(r.query.results, false, Infinity, true);
+ } catch (e) {
+ str = util.inspect(r, false, Infinity, true);
+ }
+ self.outputStream.write(str);
+ self.outputStream.write('\n');
+ self.displayPrompt();
+ });
+ });
+ }
+});
+
@@ -0,0 +1,23 @@
+{
+ "name": "yui-repl",
+ "description": "YUI 3 Powered REPL",
+ "version": "0.0.1",
+ "author": "Dav Glass <davglass@gmail.com>",
+ "bugs": { "web": "http://github.com/davglass/yui-repl/issues" },
+ "os": [ "darwin", "linux" ],
+ "engines": { "node": ">=0.4.0" },
+ "bin": { "yui3": "./bin/yui-repl.js" },
+ "licenses": [{
+ "type": "BSD",
+ "url": "http://developer.yahoo.com/yui/license.html"
+ }],
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/davglass/yui-repl.git"
+ },
+ "dependencies": {
+ "yui3": ">=0.5.26",
+ "yui3-core": "3.3.0",
+ "colors": "0.3.0"
+ }
+}

0 comments on commit f7252ca

Please sign in to comment.