From 3a64d50e8a5df04d2192d5f57623c46f0f795b64 Mon Sep 17 00:00:00 2001 From: Anton Dyudin Date: Fri, 17 Jul 2015 14:34:58 -0700 Subject: [PATCH] added js urb.util.basepath, generalized tree frontent to work under aliases, proof-of-concept blog/{hymn,json}.hook pointing at tree/pub/blog --- arvo/zuse.hoon | 10 +++---- blog/hymn.hook | 2 ++ blog/json.hook | 2 ++ lib/urb.js | 52 +++++++++++++++++++++++++++---------- pub/blog/~2015.7.16.md | 1 + pub/blog/~2015.7.17.md | 1 + pub/tree/src/js/main.coffee | 7 +++-- pub/tree/src/js/main.js | 6 ++--- tree/hymn.hook | 1 + 9 files changed, 56 insertions(+), 26 deletions(-) create mode 100644 blog/hymn.hook create mode 100644 blog/json.hook create mode 100644 pub/blog/~2015.7.16.md create mode 100644 pub/blog/~2015.7.17.md diff --git a/arvo/zuse.hoon b/arvo/zuse.hoon index a60b5bfd3a..f6f70f6c93 100644 --- a/arvo/zuse.hoon +++ b/arvo/zuse.hoon @@ -1108,13 +1108,13 @@ [~ ~] ?^ t.rax [p.pok [ire q.pok]]:[pok=$(rax t.rax) ire=i.rax] - =+ ^- raf=(like tape) - %. [1^1 (flop (trip i.rax))] - ;~(sfix (star ;~(less dot next)) dot) + =+ ^- raf=(like term) + => |=(a=@ ((sand %tas) (crip (flop (trip a))))) + (;~(sfix (sear . sym) dot) [1^1 (flop (trip i.rax))]) ?~ q.raf [~ [i.rax ~]] - =+ `[ext=tape [@ @] fyl=tape]`u.q.raf - :- ?:(=(~ ext) ~ [~ (crip (flop ext))]) + =+ `[ext=term [@ @] fyl=tape]`u.q.raf + :- `ext ?:(=(~ fyl) ~ [(crip (flop fyl)) ~]) :: ++ fuel :: parse fcgi diff --git a/blog/hymn.hook b/blog/hymn.hook new file mode 100644 index 0000000000..83c7922618 --- /dev/null +++ b/blog/hymn.hook @@ -0,0 +1,2 @@ +/: /%%%/tree/pub/blog /% /hymn/ +-< diff --git a/blog/json.hook b/blog/json.hook new file mode 100644 index 0000000000..93678cb230 --- /dev/null +++ b/blog/json.hook @@ -0,0 +1,2 @@ +/: /%%%/tree/pub/blog /% /json/ +-< diff --git a/lib/urb.js b/lib/urb.js index 68615b2b9c..10a5aa1f4b 100644 --- a/lib/urb.js +++ b/lib/urb.js @@ -127,7 +127,7 @@ window.urb.poll = function(params) { } } - dely = params.dely ? params.dely : $this.dely + dely = params.dely || $this.dely if(err) dely = dely+Math.ceil(dely*.02) @@ -187,11 +187,11 @@ window.urb.send = function(params,cb) { var url, $this - params.ship = params.ship ? params.ship : this.ship - params.appl = params.appl ? params.appl : this.appl - params.mark = params.mark ? params.mark : "json" - params.xyro = params.data ? params.data : {} - params.wire = params.wire ? params.wire : "/" + params.ship = params.ship || this.ship + params.appl = params.appl || this.appl + params.mark = params.mark || "json" + params.xyro = params.data || {} + params.wire = params.wire || "/" url = ["to",params.appl,params.mark] @@ -221,10 +221,10 @@ window.urb.bind = function(path, cb){ // or bind(path, params, cb, nicecb?) params.path = path if(params.path[0] !== "/") params.path = "/"+params.path - params.ship = params.ship ? params.ship : this.ship - params.appl = params.appl ? params.appl : this.appl - params.mark = params.mark ? params.mark : "json" - params.wire = params.wire ? params.wire : params.path + params.ship = params.ship || this.ship + params.appl = params.appl || this.appl + params.mark = params.mark || "json" + params.wire = params.wire || params.path if(typeof path != "string") throw new Error("You must specify a string path for urb.bind.") @@ -252,9 +252,9 @@ window.urb.bind = function(path, cb){ // or bind(path, params, cb, nicecb?) window.urb.unsubscribe = function(params,cb) { if(!params) throw new Error("You must supply params to urb.unsubscribe.") - params.ship = params.ship ? params.ship : this.ship - params.appl = params.appl ? params.appl : this.appl - params.wire = params.wire ? params.wire : params.path + params.ship = params.ship || this.ship + params.appl = params.appl || this.appl + params.wire = params.wire || params.path if(!params.path) throw new Error("You must specify a path for urb.unsubscribe.") if(!params.appl) throw new Error("You must specify an appl for urb.unsubscribe.") @@ -292,5 +292,31 @@ window.urb.util = { '.' + pad(2, dat.getUTCMinutes()) + '.' + pad(2, dat.getUTCSeconds()) + '..' + pad(4, mils) + }, + basepath: function(spur, pathname){ + spur = spur || '' + pathname = pathname || window.location.pathname + if(pathname[0] == '/') pathname = pathname.slice(1) + pathname = pathname.split("/") + + var pref, pred, prec, base = "" + while(base += "/"+(pref = pathname.shift()), pathname.length>0){ + if(pref[0] !== '~') break; + if(pref === "~~") continue; + base += "/"+(pred = pathname.shift()) + if(/[a-z\-]+/.test(pref.slice(1))){ + base += "/"+(prec = pathname.shift()) + if(prec == null) throw "Bad basepath." + break; + } + if(pref !== "~") throw "Bad basepath /"+pref + if(pred === "as"){ + base += "/"+(prec = pathname.shift()) + if(prec == null) throw "Bad basepath." + continue; + } + throw "Bad basepath /~/"+pred + } + return base+spur } } diff --git a/pub/blog/~2015.7.16.md b/pub/blog/~2015.7.16.md new file mode 100644 index 0000000000..1664a9f463 --- /dev/null +++ b/pub/blog/~2015.7.16.md @@ -0,0 +1 @@ +# Post 1 diff --git a/pub/blog/~2015.7.17.md b/pub/blog/~2015.7.17.md new file mode 100644 index 0000000000..60ac35d4f1 --- /dev/null +++ b/pub/blog/~2015.7.17.md @@ -0,0 +1 @@ +# Post 2 diff --git a/pub/tree/src/js/main.coffee b/pub/tree/src/js/main.coffee index 9d4513a0d7..77974098ce 100644 --- a/pub/tree/src/js/main.coffee +++ b/pub/tree/src/js/main.coffee @@ -15,10 +15,9 @@ $ -> components = {kids:kids,list:list,lost:lost, codemirror:codemirror} - window.tree._basepath = window.location.pathname - window.tree._basepath = window.tree._basepath.split "/" - window.tree._basepath = window.tree._basepath.slice 0,window.tree._basepath.indexOf("tree")+1 - window.tree._basepath = window.tree._basepath.join "/" + window.tree._basepath = window.urb.util.basepath("/") + window.tree._basepath += + (window.location.pathname.replace window.tree._basepath, "").split("/")[0] window.tree.basepath = (path) -> if path[0] isnt "/" then path = "/"+path window.tree._basepath + path diff --git a/pub/tree/src/js/main.js b/pub/tree/src/js/main.js index 273a9b534a..d7e77bf3dc 100644 --- a/pub/tree/src/js/main.js +++ b/pub/tree/src/js/main.js @@ -651,10 +651,8 @@ $(function() { lost: lost, codemirror: codemirror }; - window.tree._basepath = window.location.pathname; - window.tree._basepath = window.tree._basepath.split("/"); - window.tree._basepath = window.tree._basepath.slice(0, window.tree._basepath.indexOf("tree") + 1); - window.tree._basepath = window.tree._basepath.join("/"); + window.tree._basepath = window.urb.util.basepath("/"); + window.tree._basepath += (window.location.pathname.replace(window.tree._basepath, "")).split("/")[0]; window.tree.basepath = function(path) { if (path[0] !== "/") { path = "/" + path; diff --git a/tree/hymn.hook b/tree/hymn.hook index 0230385206..b406366c9a 100644 --- a/tree/hymn.hook +++ b/tree/hymn.hook @@ -26,6 +26,7 @@ ;script(type "text/javascript", src "//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"); ;script(type "text/javascript", src "//cdnjs.cloudflare.com/ajax/libs/react/0.12.2/react.js"); ;script(type "text/javascript", src "//cdnjs.cloudflare.com/ajax/libs/codemirror/4.3.0/codemirror.js"); + ;script(type "text/javascript", src "/{dez}/lib/urb.js"); ;script(type "text/javascript", src "/{dez}/lib/syntax/hoon.js"); ;script(type "text/javascript", src "/{dez}/pub/tree/src/js/main.js"); ::;script(type "text/javascript", src "http://localhost:8000/docs/pub/tree/src/js/main.js");