www_app 1.3.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/README.md +42 -24
- data/VERSION +1 -1
- data/bin/www_app +15 -4
- data/lib/public/vendor/hogan-3.0.2.min.js +5 -0
- data/lib/public/vendor/instruct_instruct_instruct.js +247 -0
- data/lib/public/vendor/jquery-2.1.3.min.js +4 -0
- data/lib/public/vendor/lodash.min.js +89 -0
- data/lib/public/www_app.js +885 -625
- data/lib/www_app/CSS.rb +310 -0
- data/lib/www_app/HTML.rb +219 -0
- data/lib/www_app/JavaScript.rb +51 -0
- data/lib/www_app/TO.rb +897 -0
- data/lib/www_app.rb +324 -945
- data/playground/config.ru +102 -0
- data/specs/client-side/index.html +1 -1
- data/specs/client-side/index.js +31 -379
- data/specs/lib/config.ru +60 -31
- data/specs/lib/helpers.rb +24 -2
- data/specs/server-side/0000-new.rb +1 -1
- data/specs/server-side/0001-underscore-double.rb +38 -0
- data/specs/server-side/0001-underscore.rb +73 -0
- data/specs/server-side/0010-attrs.rb +3 -4
- data/specs/server-side/0011-id.rb +5 -5
- data/specs/server-side/0020-tag.rb +2 -2
- data/specs/server-side/0020-tag_content.rb +1 -1
- data/specs/server-side/0021-body.rb +1 -1
- data/specs/server-side/0021-script.rb +66 -20
- data/specs/server-side/{0021-page_title.rb → 0021-title.rb} +5 -3
- data/specs/server-side/0030-mustache.rb +27 -20
- data/specs/server-side/0030-style.rb +64 -21
- data/specs/server-side/0040-css.rb +4 -4
- data/specs/server-side/0041-pseudo.rb +55 -0
- data/specs/server-side/0042-slash.rb +20 -0
- data/specs/server-side/0060-text.rb +26 -0
- metadata +18 -13
- data/lib/public/jquery-2.1.1.js +0 -4
- data/lib/public/underscore-1.7.0.js +0 -6
- data/lib/public/underscore-min.map +0 -1
- data/lib/public/underscore.string-2.3.0.js +0 -1
- data/lib/www_app/Clean.rb +0 -169
- data/lib/www_app/dsl.rb +0 -86
- data/lib/www_app/source.rb +0 -53
- data/specs/server-side/0050-on.rb +0 -64
- data/specs/server-side/0060-string.rb +0 -32
- /data/lib/public/{jquery.serialize-object.min.js → vendor/jquery.serialize-object.min.js} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e7383ea452317733e67495f005aba1de108db87
|
4
|
+
data.tar.gz: 95c124150efed8c21bd5125bc01045f22ebada67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a15da63cc2815f6d379452528f6d4e3b74a2bd4da1b7b3216731dfe1df92065f12df8381a73dfa015990da6c835ce4d1aaa387d346c1f4e9fc5566e7fc27c83
|
7
|
+
data.tar.gz: 178de31e0e686764030a17a30097a319fbab25f79173bf1e885a5dea9382aa5abf5e0dc7eb30f2c66ea0d9bd85e6873b63a3118502fe8d8b7900a9980d12d9ab
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -3,9 +3,15 @@
|
|
3
3
|
WWW\_App:
|
4
4
|
---------
|
5
5
|
|
6
|
-
|
7
|
-
It's not done yet.
|
6
|
+
Turn Ruby into HTML and CSS.
|
8
7
|
|
8
|
+
I was going to put a JS features,
|
9
|
+
but I found out that I don't need them
|
10
|
+
thanks to [Turu](https://github.com/da99/turu).
|
11
|
+
|
12
|
+
NOTE:
|
13
|
+
------------
|
14
|
+
This is not ready.
|
9
15
|
|
10
16
|
Ruby:
|
11
17
|
--------------
|
@@ -22,38 +28,54 @@ To Use:
|
|
22
28
|
WWW_App.new {
|
23
29
|
|
24
30
|
style {
|
31
|
+
a._link / a._visited / a._hover {
|
32
|
+
color '#f88'
|
33
|
+
}
|
34
|
+
|
25
35
|
a {
|
26
|
-
_link
|
27
|
-
|
28
|
-
_hover { color '#ccc' }
|
36
|
+
_link / _visited { color '#fff' }
|
37
|
+
_hover { color '#ccc' }
|
29
38
|
}
|
30
|
-
}
|
31
39
|
|
32
|
-
|
40
|
+
div.id(:main).__.div.^(:drowsy) / a.^(:excited)._link {
|
41
|
+
border '1px dashed grey'
|
42
|
+
div.^(:mon) / div.^(:tues) {
|
43
|
+
border '1px dashed weekday'
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
} # === style
|
48
|
+
|
49
|
+
div.id(:main).^(:css_class_name) {
|
33
50
|
|
34
51
|
border '1px solid #000'
|
35
52
|
background_color 'grey'
|
36
53
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
54
|
+
style {
|
55
|
+
a._link / a._visited {
|
56
|
+
color '#fig'
|
57
|
+
}
|
41
58
|
|
42
|
-
|
59
|
+
_.^(:scary) {
|
60
|
+
border '2px dotted red'
|
61
|
+
background_color 'white'
|
62
|
+
}
|
63
|
+
}
|
43
64
|
|
44
|
-
|
45
|
-
parent 'div'
|
46
|
-
add_class 'scary'
|
65
|
+
p { "I'm a paragraph." }
|
47
66
|
|
48
|
-
|
67
|
+
p {
|
68
|
+
text %^
|
69
|
+
I'm also
|
70
|
+
^.strip
|
71
|
+
br
|
72
|
+
text ' a paragraph.'
|
49
73
|
}
|
50
|
-
|
51
74
|
}
|
75
|
+
|
52
76
|
}.to_html
|
53
77
|
```
|
54
78
|
|
55
|
-
It generates the CSS, JS, and HTML.
|
56
|
-
|
57
79
|
Security:
|
58
80
|
-----------
|
59
81
|
|
@@ -84,11 +106,7 @@ More info at: [http://html5doctor.com/cite-and-blockquote-reloaded/](http://htm
|
|
84
106
|
because it turns out people do not want to create programs, they just want to customize them:
|
85
107
|
[https://www.youtube.com/watch?v=9nd9DwCdQR0#t=857](https://www.youtube.com/watch?v=9nd9DwCdQR0#t=857)
|
86
108
|
|
87
|
-
|
88
|
-
Fun fact:
|
89
|
-
-----
|
90
|
-
|
91
|
-
[JSON Applet](http://github.com/da99/json_applet) was changed to WWW\_Applet. WWW\_Applet was then changed to WWW\_App.
|
109
|
+
3) [JSON Applet](http://github.com/da99/json_applet) was changed to WWW\_Applet. WWW\_Applet was then changed to WWW\_App.
|
92
110
|
|
93
111
|
|
94
112
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
data/bin/www_app
CHANGED
@@ -3,24 +3,35 @@
|
|
3
3
|
#
|
4
4
|
#
|
5
5
|
|
6
|
+
require "fileutils"
|
7
|
+
|
6
8
|
case ARGV[0]
|
7
9
|
|
8
10
|
when "help"
|
9
11
|
|
10
12
|
puts %^
|
11
13
|
# ===================="
|
12
|
-
www_app help
|
13
|
-
www_app
|
14
|
+
www_app help
|
15
|
+
www_app Public
|
16
|
+
www_app upgrade_js
|
14
17
|
# ===================="
|
15
18
|
^
|
16
19
|
|
17
|
-
when
|
20
|
+
when 'Public'
|
21
|
+
gem = File.expand_path(File.dirname(__FILE__ ) + '/..')
|
22
|
+
source = gem + '/lib/public'
|
23
|
+
dest = "Public/www_app-#{File.read(gem + '/VERSION').strip}"
|
24
|
+
FileUtils.mkdir_p dest
|
25
|
+
FileUtils.rm_r Dir.glob('Public/www_app-*.*.*'), :secure=>true
|
26
|
+
FileUtils.copy_entry source, dest
|
27
|
+
puts "=== Copied files into: #{dest}"
|
28
|
+
|
29
|
+
when "upgrade_js"
|
18
30
|
|
19
31
|
fail "
|
20
32
|
Must automate downloading of LATEST (security reason)
|
21
33
|
underscore, jquery, etc.
|
22
34
|
"
|
23
|
-
require "fileutils"
|
24
35
|
args = ARGV.dup
|
25
36
|
|
26
37
|
applet_file = File.join File.dirname(File.dirname(__FILE__)), "lib/www_app.js"
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/**
|
2
|
+
* @preserve Copyright 2012 Twitter, Inc.
|
3
|
+
* @license http://www.apache.org/licenses/LICENSE-2.0.txt
|
4
|
+
*/
|
5
|
+
var Hogan={};!function(t){function n(t,n,e){var i;return n&&"object"==typeof n&&(void 0!==n[t]?i=n[t]:e&&n.get&&"function"==typeof n.get&&(i=n.get(t))),i}function e(t,n,e,i,r,s){function a(){}function o(){}a.prototype=t,o.prototype=t.subs;var u,c=new a;c.subs=new o,c.subsText={},c.buf="",i=i||{},c.stackSubs=i,c.subsText=s;for(u in n)i[u]||(i[u]=n[u]);for(u in i)c.subs[u]=i[u];r=r||{},c.stackPartials=r;for(u in e)r[u]||(r[u]=e[u]);for(u in r)c.partials[u]=r[u];return c}function i(t){return String(null===t||void 0===t?"":t)}function r(t){return t=i(t),l.test(t)?t.replace(s,"&").replace(a,"<").replace(o,">").replace(u,"'").replace(c,"""):t}t.Template=function(t,n,e,i){t=t||{},this.r=t.code||this.r,this.c=e,this.options=i||{},this.text=n||"",this.partials=t.partials||{},this.subs=t.subs||{},this.buf=""},t.Template.prototype={r:function(){return""},v:r,t:i,render:function(t,n,e){return this.ri([t],n||{},e)},ri:function(t,n,e){return this.r(t,n,e)},ep:function(t,n){var i=this.partials[t],r=n[i.name];if(i.instance&&i.base==r)return i.instance;if("string"==typeof r){if(!this.c)throw new Error("No compiler available.");r=this.c.compile(r,this.options)}if(!r)return null;if(this.partials[t].base=r,i.subs){n.stackText||(n.stackText={});for(key in i.subs)n.stackText[key]||(n.stackText[key]=void 0!==this.activeSub&&n.stackText[this.activeSub]?n.stackText[this.activeSub]:this.text);r=e(r,i.subs,i.partials,this.stackSubs,this.stackPartials,n.stackText)}return this.partials[t].instance=r,r},rp:function(t,n,e,i){var r=this.ep(t,e);return r?r.ri(n,e,i):""},rs:function(t,n,e){var i=t[t.length-1];if(!f(i))return void e(t,n,this);for(var r=0;r<i.length;r++)t.push(i[r]),e(t,n,this),t.pop()},s:function(t,n,e,i,r,s,a){var o;return f(t)&&0===t.length?!1:("function"==typeof t&&(t=this.ms(t,n,e,i,r,s,a)),o=!!t,!i&&o&&n&&n.push("object"==typeof t?t:n[n.length-1]),o)},d:function(t,e,i,r){var s,a=t.split("."),o=this.f(a[0],e,i,r),u=this.options.modelGet,c=null;if("."===t&&f(e[e.length-2]))o=e[e.length-1];else for(var l=1;l<a.length;l++)s=n(a[l],o,u),void 0!==s?(c=o,o=s):o="";return r&&!o?!1:(r||"function"!=typeof o||(e.push(c),o=this.mv(o,e,i),e.pop()),o)},f:function(t,e,i,r){for(var s=!1,a=null,o=!1,u=this.options.modelGet,c=e.length-1;c>=0;c--)if(a=e[c],s=n(t,a,u),void 0!==s){o=!0;break}return o?(r||"function"!=typeof s||(s=this.mv(s,e,i)),s):r?!1:""},ls:function(t,n,e,r,s){var a=this.options.delimiters;return this.options.delimiters=s,this.b(this.ct(i(t.call(n,r)),n,e)),this.options.delimiters=a,!1},ct:function(t,n,e){if(this.options.disableLambda)throw new Error("Lambda features disabled.");return this.c.compile(t,this.options).render(n,e)},b:function(t){this.buf+=t},fl:function(){var t=this.buf;return this.buf="",t},ms:function(t,n,e,i,r,s,a){var o,u=n[n.length-1],c=t.call(u);return"function"==typeof c?i?!0:(o=this.activeSub&&this.subsText&&this.subsText[this.activeSub]?this.subsText[this.activeSub]:this.text,this.ls(c,u,e,o.substring(r,s),a)):c},mv:function(t,n,e){var r=n[n.length-1],s=t.call(r);return"function"==typeof s?this.ct(i(s.call(r)),r,e):s},sub:function(t,n,e,i){var r=this.subs[t];r&&(this.activeSub=t,r(n,e,this,i),this.activeSub=!1)}};var s=/&/g,a=/</g,o=/>/g,u=/\'/g,c=/\"/g,l=/[&<>\"\']/,f=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}}("undefined"!=typeof exports?exports:Hogan),function(t){function n(t){"}"===t.n.substr(t.n.length-1)&&(t.n=t.n.substring(0,t.n.length-1))}function e(t){return t.trim?t.trim():t.replace(/^\s*|\s*$/g,"")}function i(t,n,e){if(n.charAt(e)!=t.charAt(0))return!1;for(var i=1,r=t.length;r>i;i++)if(n.charAt(e+i)!=t.charAt(i))return!1;return!0}function r(n,e,i,o){var u=[],c=null,l=null,f=null;for(l=i[i.length-1];n.length>0;){if(f=n.shift(),l&&"<"==l.tag&&!(f.tag in k))throw new Error("Illegal content in < super tag.");if(t.tags[f.tag]<=t.tags.$||s(f,o))i.push(f),f.nodes=r(n,f.tag,i,o);else{if("/"==f.tag){if(0===i.length)throw new Error("Closing tag without opener: /"+f.n);if(c=i.pop(),f.n!=c.n&&!a(f.n,c.n,o))throw new Error("Nesting error: "+c.n+" vs. "+f.n);return c.end=f.i,u}"\n"==f.tag&&(f.last=0==n.length||"\n"==n[0].tag)}u.push(f)}if(i.length>0)throw new Error("missing closing tag: "+i.pop().n);return u}function s(t,n){for(var e=0,i=n.length;i>e;e++)if(n[e].o==t.n)return t.tag="#",!0}function a(t,n,e){for(var i=0,r=e.length;r>i;i++)if(e[i].c==t&&e[i].o==n)return!0}function o(t){var n=[];for(var e in t)n.push('"'+c(e)+'": function(c,p,t,i) {'+t[e]+"}");return"{ "+n.join(",")+" }"}function u(t){var n=[];for(var e in t.partials)n.push('"'+c(e)+'":{name:"'+c(t.partials[e].name)+'", '+u(t.partials[e])+"}");return"partials: {"+n.join(",")+"}, subs: "+o(t.subs)}function c(t){return t.replace(m,"\\\\").replace(v,'\\"').replace(b,"\\n").replace(d,"\\r").replace(x,"\\u2028").replace(w,"\\u2029")}function l(t){return~t.indexOf(".")?"d":"f"}function f(t,n){var e="<"+(n.prefix||""),i=e+t.n+y++;return n.partials[i]={name:t.n,partials:{}},n.code+='t.b(t.rp("'+c(i)+'",c,p,"'+(t.indent||"")+'"));',i}function h(t,n){n.code+="t.b(t.t(t."+l(t.n)+'("'+c(t.n)+'",c,p,0)));'}function p(t){return"t.b("+t+");"}var g=/\S/,v=/\"/g,b=/\n/g,d=/\r/g,m=/\\/g,x=/\u2028/,w=/\u2029/;t.tags={"#":1,"^":2,"<":3,$:4,"/":5,"!":6,">":7,"=":8,_v:9,"{":10,"&":11,_t:12},t.scan=function(r,s){function a(){m.length>0&&(x.push({tag:"_t",text:new String(m)}),m="")}function o(){for(var n=!0,e=y;e<x.length;e++)if(n=t.tags[x[e].tag]<t.tags._v||"_t"==x[e].tag&&null===x[e].text.match(g),!n)return!1;return n}function u(t,n){if(a(),t&&o())for(var e,i=y;i<x.length;i++)x[i].text&&((e=x[i+1])&&">"==e.tag&&(e.indent=x[i].text.toString()),x.splice(i,1));else n||x.push({tag:"\n"});w=!1,y=x.length}function c(t,n){var i="="+S,r=t.indexOf(i,n),s=e(t.substring(t.indexOf("=",n)+1,r)).split(" ");return T=s[0],S=s[s.length-1],r+i.length-1}var l=r.length,f=0,h=1,p=2,v=f,b=null,d=null,m="",x=[],w=!1,k=0,y=0,T="{{",S="}}";for(s&&(s=s.split(" "),T=s[0],S=s[1]),k=0;l>k;k++)v==f?i(T,r,k)?(--k,a(),v=h):"\n"==r.charAt(k)?u(w):m+=r.charAt(k):v==h?(k+=T.length-1,d=t.tags[r.charAt(k+1)],b=d?r.charAt(k+1):"_v","="==b?(k=c(r,k),v=f):(d&&k++,v=p),w=k):i(S,r,k)?(x.push({tag:b,n:e(m),otag:T,ctag:S,i:"/"==b?w-T.length:k+S.length}),m="",k+=S.length-1,v=f,"{"==b&&("}}"==S?k++:n(x[x.length-1]))):m+=r.charAt(k);return u(w,!0),x};var k={_t:!0,"\n":!0,$:!0,"/":!0};t.stringify=function(n){return"{code: function (c,p,i) { "+t.wrapMain(n.code)+" },"+u(n)+"}"};var y=0;t.generate=function(n,e,i){y=0;var r={code:"",subs:{},partials:{}};return t.walk(n,r),i.asString?this.stringify(r,e,i):this.makeTemplate(r,e,i)},t.wrapMain=function(t){return'var t=this;t.b(i=i||"");'+t+"return t.fl();"},t.template=t.Template,t.makeTemplate=function(t,n,e){var i=this.makePartials(t);return i.code=new Function("c","p","i",this.wrapMain(t.code)),new this.template(i,n,this,e)},t.makePartials=function(t){var n,e={subs:{},partials:t.partials,name:t.name};for(n in e.partials)e.partials[n]=this.makePartials(e.partials[n]);for(n in t.subs)e.subs[n]=new Function("c","p","t","i",t.subs[n]);return e},t.codegen={"#":function(n,e){e.code+="if(t.s(t."+l(n.n)+'("'+c(n.n)+'",c,p,1),c,p,0,'+n.i+","+n.end+',"'+n.otag+" "+n.ctag+'")){t.rs(c,p,function(c,p,t){',t.walk(n.nodes,e),e.code+="});c.pop();}"},"^":function(n,e){e.code+="if(!t.s(t."+l(n.n)+'("'+c(n.n)+'",c,p,1),c,p,1,0,0,"")){',t.walk(n.nodes,e),e.code+="};"},">":f,"<":function(n,e){var i={partials:{},code:"",subs:{},inPartial:!0};t.walk(n.nodes,i);var r=e.partials[f(n,e)];r.subs=i.subs,r.partials=i.partials},$:function(n,e){var i={subs:{},code:"",partials:e.partials,prefix:n.n};t.walk(n.nodes,i),e.subs[n.n]=i.code,e.inPartial||(e.code+='t.sub("'+c(n.n)+'",c,p,i);')},"\n":function(t,n){n.code+=p('"\\n"'+(t.last?"":" + i"))},_v:function(t,n){n.code+="t.b(t.v(t."+l(t.n)+'("'+c(t.n)+'",c,p,0)));'},_t:function(t,n){n.code+=p('"'+c(t.text)+'"')},"{":h,"&":h},t.walk=function(n,e){for(var i,r=0,s=n.length;s>r;r++)i=t.codegen[n[r].tag],i&&i(n[r],e);return e},t.parse=function(t,n,e){return e=e||{},r(t,"",[],e.sectionTags||[])},t.cache={},t.cacheKey=function(t,n){return[t,!!n.asString,!!n.disableLambda,n.delimiters,!!n.modelGet].join("||")},t.compile=function(n,e){e=e||{};var i=t.cacheKey(n,e),r=this.cache[i];if(r){var s=r.partials;for(var a in s)delete s[a].instance;return r}return r=this.generate(this.parse(this.scan(n,e.delimiters),n,e),n,e),this.cache[i]=r}}("undefined"!=typeof exports?exports:Hogan);
|
@@ -0,0 +1,247 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
/* jshint undef: true, unused: true */
|
4
|
+
/* global _ */
|
5
|
+
|
6
|
+
var instruct_instruct_instruct = function (funcs) {
|
7
|
+
this.funcs = _.merge(instruct_instruct_instruct.base, funcs);
|
8
|
+
this.stack = null;
|
9
|
+
return this;
|
10
|
+
};
|
11
|
+
|
12
|
+
|
13
|
+
// === Scope
|
14
|
+
(function () {
|
15
|
+
var I = instruct_instruct_instruct;
|
16
|
+
var jquery_proxy = $('body');
|
17
|
+
|
18
|
+
function log() {
|
19
|
+
if (window.console)
|
20
|
+
console['log'].apply(console, arguments);
|
21
|
+
}
|
22
|
+
|
23
|
+
function is_numeric(val) {
|
24
|
+
return _.isNumber(val) && !_.isNaN(val);
|
25
|
+
}
|
26
|
+
|
27
|
+
function concat() {
|
28
|
+
var args = _.toArray(arguments);
|
29
|
+
var base = _.first(args);
|
30
|
+
var arrs = _.rest(args);
|
31
|
+
_.each(arrs, function (v) {
|
32
|
+
_.each(v, function (val) {
|
33
|
+
base.push(val);
|
34
|
+
});
|
35
|
+
});
|
36
|
+
return base;
|
37
|
+
}
|
38
|
+
|
39
|
+
function inspect(o) {
|
40
|
+
return '(' + typeof(o) + ') "' + o + '"' ;
|
41
|
+
}
|
42
|
+
|
43
|
+
instruct_instruct_instruct.base = {
|
44
|
+
'add to stack': function (iii) {
|
45
|
+
concat(iii.stack, iii.shift('all'));
|
46
|
+
},
|
47
|
+
'$': function (iii) {
|
48
|
+
var args = iii.shift('all');
|
49
|
+
if (_.isEmpty(args))
|
50
|
+
return $(iii.pop('string'));
|
51
|
+
else
|
52
|
+
return $.apply($, args);
|
53
|
+
},
|
54
|
+
'array': function (iii) {
|
55
|
+
return iii.shift('all');
|
56
|
+
},
|
57
|
+
"or": function (iii) {
|
58
|
+
var left = iii.pop('boolean');
|
59
|
+
if (left)
|
60
|
+
return true;
|
61
|
+
return iii.shift('boolean');
|
62
|
+
},
|
63
|
+
'and': function (iii) {
|
64
|
+
var left = iii.pop('boolean');
|
65
|
+
if (left)
|
66
|
+
return left === iii.shift('boolean');
|
67
|
+
else
|
68
|
+
return false;
|
69
|
+
},
|
70
|
+
'if true': function (iii) {
|
71
|
+
var left = iii.pop('boolean');
|
72
|
+
if (!left)
|
73
|
+
return left;
|
74
|
+
iii.shift('all');
|
75
|
+
return left;
|
76
|
+
},
|
77
|
+
'if false': function (iii) {
|
78
|
+
var left = iii.pop('boolean');
|
79
|
+
if (left)
|
80
|
+
return left;
|
81
|
+
iii.shift('all');
|
82
|
+
return left;
|
83
|
+
},
|
84
|
+
'less or equal': function (iii) {
|
85
|
+
var left = iii.pop('number');
|
86
|
+
var right = iii.shift('number');
|
87
|
+
return left <= right;
|
88
|
+
},
|
89
|
+
'bigger or equal': function (iii) {
|
90
|
+
var left = iii.pop('number');
|
91
|
+
var right = iii.shift('number');
|
92
|
+
return left >= right;
|
93
|
+
},
|
94
|
+
'bigger': function (iii) {
|
95
|
+
return iii.pop('number') > iii.shift('number');
|
96
|
+
},
|
97
|
+
'less': function (iii) {
|
98
|
+
return iii.pop('number') < iii.shift('number');
|
99
|
+
},
|
100
|
+
'equal': function (iii) {
|
101
|
+
var left = iii.pop();
|
102
|
+
var right = iii.shift();
|
103
|
+
var l_type = typeof(left);
|
104
|
+
var r_type = typeof(right);
|
105
|
+
|
106
|
+
if (l_type !== r_type)
|
107
|
+
throw new Error("Type mis-match: " + inspect(left) + ' !== ' + inspect(right));
|
108
|
+
return left === right;
|
109
|
+
}
|
110
|
+
};
|
111
|
+
|
112
|
+
I.prototype.spawn = function () {
|
113
|
+
var funcs = _.clone(this.funcs);
|
114
|
+
return new instruct_instruct_instruct(funcs);
|
115
|
+
}; // function
|
116
|
+
|
117
|
+
I.prototype.run = function (raw_code) {
|
118
|
+
var self = this;
|
119
|
+
var left = [];
|
120
|
+
var code = _.clone(raw_code);
|
121
|
+
var o = null;
|
122
|
+
var last_o = null;
|
123
|
+
var func_name = null;
|
124
|
+
var result = null;
|
125
|
+
var jquery = null;
|
126
|
+
|
127
|
+
var env = {
|
128
|
+
stack: left,
|
129
|
+
run_args : function () {
|
130
|
+
if (!_.isUndefined(this.raw_args))
|
131
|
+
this.args = self.spawn().run(this.raw_args).stack;
|
132
|
+
this.raw_args = undefined;
|
133
|
+
|
134
|
+
return this.args;
|
135
|
+
},
|
136
|
+
|
137
|
+
pop: function (type) {
|
138
|
+
var val;
|
139
|
+
var is_empty = _.isEmpty(left);
|
140
|
+
|
141
|
+
if (is_empty) {
|
142
|
+
if (type)
|
143
|
+
throw new Error("Left Stack underflow while popping for " + type + '.');
|
144
|
+
else
|
145
|
+
throw new Error("Left Stack underflow while popping.");
|
146
|
+
}
|
147
|
+
|
148
|
+
val = left.pop();
|
149
|
+
|
150
|
+
switch (type) {
|
151
|
+
case 'number':
|
152
|
+
if (!is_numeric(val))
|
153
|
+
throw new Error("Left Stack popped value is not a number: " + inspect(val));
|
154
|
+
break;
|
155
|
+
|
156
|
+
case 'string':
|
157
|
+
if (!_.isString(val))
|
158
|
+
throw new Error("Left Stack popped value is not a string: " + inspect(val));
|
159
|
+
break;
|
160
|
+
|
161
|
+
case 'boolean':
|
162
|
+
if (!_.isBoolean(val))
|
163
|
+
throw new Error("Left Stack popped value is not a boolean: " + inspect(val));
|
164
|
+
break;
|
165
|
+
|
166
|
+
default:
|
167
|
+
if (type !== undefined)
|
168
|
+
throw new Error("Unknown type for .pop(): " + inspect(type));
|
169
|
+
} // === switch
|
170
|
+
|
171
|
+
return val;
|
172
|
+
},
|
173
|
+
|
174
|
+
shift: function (type) {
|
175
|
+
this.run_args();
|
176
|
+
if (type === 'all') {
|
177
|
+
var vals = this.args;
|
178
|
+
this.args = [];
|
179
|
+
return vals;
|
180
|
+
}
|
181
|
+
|
182
|
+
if (_.isEmpty(this.args)) {
|
183
|
+
if (type)
|
184
|
+
throw new Error("Argument Stack underflow while shifting for " + type + ".");
|
185
|
+
else
|
186
|
+
throw new Error("Argument Stack underflow.");
|
187
|
+
}
|
188
|
+
|
189
|
+
var val = this.args.shift();
|
190
|
+
|
191
|
+
switch (type) {
|
192
|
+
case 'number':
|
193
|
+
if (!is_numeric(val))
|
194
|
+
throw new Error("Argument Stack shifted value is not a number: " + inspect(val));
|
195
|
+
break;
|
196
|
+
case 'string':
|
197
|
+
if (!_.isString(val))
|
198
|
+
throw new Error("Argument Stack shifted value is not a string: " + inspect(val));
|
199
|
+
break;
|
200
|
+
case 'boolean':
|
201
|
+
if (!_.isBoolean(val))
|
202
|
+
throw new Error("Argument Stack shifted value is not a boolean: " + inspect(val));
|
203
|
+
break;
|
204
|
+
|
205
|
+
default:
|
206
|
+
if (type !== undefined)
|
207
|
+
throw new Error("Unknown type for .shift(): " + inspect(type));
|
208
|
+
} // === switch
|
209
|
+
|
210
|
+
return val;
|
211
|
+
}
|
212
|
+
};
|
213
|
+
|
214
|
+
while (!_.isEmpty(code)) {
|
215
|
+
o = code.shift();
|
216
|
+
if (_.isString(o) || is_numeric(o) || _.isBoolean(o)) {
|
217
|
+
left.push(o);
|
218
|
+
} else if (_.isArray(o)) {
|
219
|
+
if (!_.isString(last_o)) {
|
220
|
+
throw new Error('Invalid data type for function name: ' + inspect(last_o));
|
221
|
+
}
|
222
|
+
env.raw_args = o;
|
223
|
+
func_name = left.pop();
|
224
|
+
if (!this.funcs[func_name]) {
|
225
|
+
if (!jquery_proxy[func_name])
|
226
|
+
throw new Error("Func not found: " + func_name);
|
227
|
+
jquery = _.last(left)[func_name] ? left.pop() : $(env.pop('string'));
|
228
|
+
result = jquery[func_name].apply(jquery, env.shift('all'));
|
229
|
+
} else {
|
230
|
+
result = this.funcs[func_name](env);
|
231
|
+
}
|
232
|
+
if (result !== undefined)
|
233
|
+
left.unshift( result );
|
234
|
+
} else {
|
235
|
+
throw new Error("Invalid data type: " + inspect(o));
|
236
|
+
}
|
237
|
+
|
238
|
+
last_o = o;
|
239
|
+
} // === while i < size
|
240
|
+
|
241
|
+
return {
|
242
|
+
code: raw_code,
|
243
|
+
stack: left
|
244
|
+
};
|
245
|
+
}; // function run
|
246
|
+
|
247
|
+
})(); // === scope
|