Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ported dataeditor to Embeditor

  • Loading branch information...
commit 931c6a38fc437ac27d5716b229117e3c483e4ce5 1 parent 65cabcc
@derek authored
Showing with 48 additions and 45 deletions.
  1. +8 −10 README.md
  2. +9 −9 generator.php
  3. +31 −26 index.html
View
18 README.md
@@ -1,5 +1,5 @@
About
----------------
+---
YQL is awesome, but sometimes you don't need to use all the SQL-like features of it and you just want make an API service with JavaScript. **Executor to the rescue**. Think of it like the NoSQL version of YQL.
@@ -8,7 +8,7 @@ Executor is a web application that simply generates an [open datatable](http://w
The neat things with datatables is that once you have one complete, you now have an API service that you can pass dynamic data to via the querystring. Think the [REST URL](http://s89997654.onlinehome.us/screencaps/skitched-20110924-235709.jpg) YQL uses is too long and ugly? Use YQL's [Console](https://developer.yahoo.com/yql/console/) to create a query alias. So for example, here is an API service that searches YouTube, Justin.TV, Flickr, and Netflix for the specified term in the querystring, [http://query.yahooapis.com/v1/public/yql/derek/mediasearch?query=kittens](http://query.yahooapis.com/v1/public/yql/derek/mediasearch?query=kittens). The best part is, you don't thave to worry about hosting it. Let Yahoo worry about that.
Specifics
---------
+---
Within YQL, there's a little-known feature, the `<execute>` sub-element. Inside of `<execute>`, you can put whatever JavaScript you want to execute inside of YQL's [Rhino] engine. Yes, you heard me right, any JavaScript you want to pass in. It's pretty rad.
Inside of `<execute>`, you start with 2 global objects
@@ -39,17 +39,15 @@ Now, if you really want to take advantage of `<execute>` and earn some gold star
There are quite a few more methods, but those are the most commonly used ones.
-E4X
-------
-
-Just a special note: YQL makes use of E4X. So if the non-quotes XML elements looks a little funky to you, that is why. The awesome part about [E4X](http://en.wikipedia.org/wiki/ECMAScript_for_XML) is that you get XML natives in JavaScript. The awful part of E4X is that it means you are using XML inside of JavaScript. Read more into it if you are curious because a detailed explanation is well beyond the scope of this README.
-
-In short, E4X actually makes XML inside of JavaScript bearable, so don't freak out too much.
+Notes
+---
+ - Executor uses Ace.js, an awesome text editor from Mozilla. This would be useful to review -> [Ace Keyboard Shortcuts](https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts)
+ - YQL supports use of E4X. So if the non-quoted XML elements looks a little funky to you, that is why. The awesome part about [E4X](http://en.wikipedia.org/wiki/ECMAScript_for_XML) is that you get XML natives in JavaScript. The awful part of E4X is that it means you are using XML inside of JavaScript. Read more into it if you are curious because a detailed explanation is well beyond the scope of this README. In short, E4X actually makes XML inside of JavaScript bearable, so don't freak out too much.
Who/What/When/Where?
--------
+---
-This was hacked together in about 10 hours by [@derek](http://twitter.com/derek) at a Y! HackU event in Berkeley on Sept 23rd/24th 2011.
+This was hacked together by [@derek](http://twitter.com/derek) at a Y! HackU event in Berkeley on Sept 23rd/24th 2011.
View
18 generator.php
@@ -1,6 +1,4 @@
<?php
- header("content-type: application/json");
-
$js = stripslashes($_POST['text']);
$keys = explode(",", $_POST['keys']);
@@ -16,11 +14,10 @@
<select itemPath="" produces="XML">
<inputs>';
- if (count($keys)){
-
- foreach ($keys as $k) {
- $xml .= '<key id="' . $k . '" type="xs:string" paramType="variable" required="true" />';
- }
+ if (count($keys)) {
+ foreach ($keys as $k) {
+ $xml .= '<key id="' . $k . '" type="xs:string" paramType="variable" required="true" />';
+ }
}
$xml .='
@@ -35,8 +32,11 @@
</table>';
$filename = "tables/" . md5($xml) . ".xml";
-
- file_put_contents($filename, $xml);
+ if (!file_exists($filename)) {
+ file_put_contents($filename, $xml);
+ }
+
+ header("content-type: application/json");
echo json_encode(array(
"filename" => "http://derek.io/~/executor/" . $filename
View
57 index.html
@@ -6,6 +6,7 @@
<script src="ace-0.2.0/src/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="ace-0.2.0/src/mode-javascript.js" type="text/javascript" charset="utf-8"></script>
<script src="http://yui.yahooapis.com/3.4.0/build/yui/yui-min.js"></script>
+ <script src="http://embeditor.org/api.js"></script>
</head>
@@ -13,7 +14,7 @@
<div>Datatable: <input style="width:800px" type="text" id="datatable_url" value="http://derek.io/~/executor/tables/157df2900c8b79e3ee640767ab08cc07.xml" /> <input type="button" id="load_datatable" value="load"></div>
<div id="editor"></div>
- <div id="dataeditor"></div>
+ <iframe id="dataeditor" src="http://embeditor.org/?mode=javascript"></iframe>
<div id="output">
<input class="yui3-button yui3-button-color-blue" type="button" value="Execute" id="btn_get_url"/>
@@ -29,11 +30,10 @@
YUI().use("node", "io", "json", "yql", "attribute", "node-event-simulate", function(Y){
var editor = ace.edit("editor");
- var dataeditor = ace.edit("dataeditor");
+ var dataeditor = new Embeditor("dataeditor");
var JavaScriptMode = require("ace/mode/javascript").Mode;
editor.getSession().setMode(new JavaScriptMode());
- dataeditor.getSession().setMode(new JavaScriptMode());
// Listen for datatable load requests
Y.one("#load_datatable").on("click", function(){
@@ -46,20 +46,16 @@
var dataeditorOut = {};
if (!Y.Object.isEmpty(keys)) {
if (Y.Lang.isArray(keys)) {
-
- for (k in keys) {
- Y.log(keys[k]);
- dataeditorOut[keys[k].id] = "";
+ for (k in keys) {
+ dataeditorOut[keys[k].id] = (keys[k].default ? keys[k].default : "");
}
}
else {
-
- dataeditorOut[keys.id] = '';
+ dataeditorOut[keys.id] = (keys.default ? keys.default : "");
}
}
- /*
- */
- dataeditor.getSession().setValue(Y.JSON.stringify(dataeditorOut, null, 4));
+
+ dataeditor.setValue(Y.JSON.stringify(dataeditorOut, null, 4));
});
});
@@ -67,10 +63,17 @@
Y.one("#btn_get_url").on("click", function(){
var params = [];
- if (dataeditor.getSession().getValue().length > 2) {
- params = Y.JSON.parse(dataeditor.getSession().getValue());
- }
-
+ dataeditor.getValue(function(value){
+ if (value.length > 2) {
+ params = Y.JSON.parse(value);
+ }
+ generateDatatable(params);
+ });
+ });
+
+ Y.one("#load_datatable").simulate("click");
+
+ function generateDatatable(params){
Y.io("generator.php", {
method: "POST",
data: {
@@ -92,15 +95,15 @@
},
complete: function(a, b, c){
Y.log("io:complete");
-
+
var url = Y.JSON.parse(b.responseText).filename;
var query = "use '" + url + "' as datatable; SELECT * FROM datatable";
var size = Y.Object.size(params);
var j = 0;
var querystring = '';
-
+
Y.one("#datatable_url").set("value", url);
-
+
if (size > 0) {
for(var i in params) {
if (j === 0) {
@@ -115,29 +118,28 @@
}
}
query += ";";
-
+
var iframeURL = "https://query.yahooapis.com/v1/public/yql?diagnostics=true&q=" + encodeURIComponent(query) + querystring;
Y.one("#console_url").setContent(query).setAttribute("href", "http://developer.yahoo.com/yql/console/?q=" + encodeURIComponent(query));
Y.one("#results").setAttribute("src", iframeURL);
-
+
/*
var aliasQuery = "insert into yql.queries.query (name,query) values ('test123123','" + addslashes(query) + "')";
-
+
Y.YQL(aliasQuery, function(){
-
+
});
*/
}
}
})
- });
-
- Y.one("#load_datatable").simulate("click");
+ }
});
function addslashes(str) {
return str.replace(/\\/g, '\\\\').replace(/\'/g, '\\\'').replace(/\"/g, '\\"').replace(/\0/g, '\\0');
}
+
function stripslashes(str) {
return str.replace(/\\'/g, '\'').replace(/\\"/g, '"').replace(/\\0/g, '\\0').replace(/\\\\/g, '\\');
}
@@ -166,6 +168,9 @@
right:0;
top: 40px;
width:300px;
+
+ overflow: hidden;
+ border:none;
}
#editor, #dataeditor{
Please sign in to comment.
Something went wrong with that request. Please try again.