Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added .debug and .headers repl commands, upped the package number and…

… updated the README
  • Loading branch information...
commit 32b08648e74bc2aae61a2a7b56a1e6722ac5c97d 1 parent d8958b8
@davglass authored
Showing with 55 additions and 9 deletions.
  1. +11 −0 README.md
  2. +43 −8 bin/yui-repl.js
  3. +1 −1  package.json
View
11 README.md
@@ -33,12 +33,23 @@ A NodeJS REPL environment preloaded with a Y variable populated by a YUI sandbox
.io http://yuilibrary.com/gallery/api/show/yql
</pre>
+`.headers {url}` Make an IO request to the passed URL and return the headers
+<pre class="console">
+ .headers https://graph.facebook.com/davglass
+ .headers http://yuilibrary.com/gallery/api/show/yql
+</pre>
+
`.yql {sql}` Make an YQL request with the passed SQL statement
<pre class="console">
.yql select * from weather.forecast where location=90210
.yql select * from flickr.photos.recent
</pre>
+`.debug` Toggle the debug config on the YUI instance, outputs the new debug setting.
+<pre class="console">
+ .debug
+</pre>
+
## Screencast
Here is a simple little screencast of it in action: [View Video](http://dl.dropbox.com/u/5669457/YUI3-REPL-2.mov)
View
51 bin/yui-repl.js
@@ -9,12 +9,10 @@ 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 debug = false;
+
var ctx = repl.context;
ctx.Y = Y;
@@ -37,7 +35,16 @@ var load = function(url) {
});
};
-
+repl.defineCommand('debug', {
+ help: 'Toggle the YUI debug config option',
+ action: function() {
+ var d = !debug+'';
+ debug = !debug;
+ this.outputStream.write('Setting debug on the Y instance to: '.magenta + d.white + '\n');
+ this.context.Y.config.debug = debug;
+ this.displayPrompt();
+ }
+});
repl.defineCommand('import', {
help: 'Import a document into this context',
@@ -84,14 +91,38 @@ repl.defineCommand('io', {
on: {
complete: function(id, e) {
self.outputStream.write(' [done]\n'.white);
+ self.outputStream.write(' (' + (e.status + '').green + ' ' + e.statusText + '): Content-Type: "' + e.headers['content-type'].green + '"\n\n'.white);
var str;
try {
str = util.inspect(JSON.parse(e.responseText), false, Infinity, true);
} catch (e) {
- str = e.responseText
+ str = e.responseText;
}
self.outputStream.write(str);
- self.outputStream.write('\n');
+ self.outputStream.write('\n\n');
+ self.displayPrompt();
+ }
+ }
+ });
+ });
+ }
+});
+
+repl.defineCommand('headers', {
+ help: 'Make an IO request to the passed URL and only return the headers',
+ 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);
+ self.outputStream.write(' (' + (e.status + '').green + ' ' + e.statusText + '): Content-Type: "' + e.headers['content-type'].green + '"\n\n'.white);
+ var str = util.inspect(e.headers, false, Infinity, true);
+ self.outputStream.write(str);
+ self.outputStream.write('\n\n');
self.displayPrompt();
}
}
@@ -116,10 +147,14 @@ repl.defineCommand('yql', {
str = util.inspect(r, false, Infinity, true);
}
self.outputStream.write(str);
- self.outputStream.write('\n');
+ self.outputStream.write('\n\n');
self.displayPrompt();
});
});
}
});
+
+process.on('uncaughtException', function(e) {
+ Y.log(e.stack, 'error', 'repl');
+});
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "yui-repl",
"description": "YUI 3 Powered REPL",
- "version": "0.0.2",
+ "version": "0.0.3",
"author": "Dav Glass <davglass@gmail.com>",
"bugs": { "web": "http://github.com/davglass/yui-repl/issues" },
"os": [ "darwin", "linux" ],
Please sign in to comment.
Something went wrong with that request. Please try again.