From 774beceac3006e89286e0fc6c7d853fb5c18cbcf Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Wed, 2 Apr 2014 18:06:45 -0700 Subject: [PATCH] Template language. --- arvo/eyre.hoon | 4 +- arvo/hoon.hoon | 222 ++++++++++++++++++++++++++++++++- arvo/zuse.hoon | 38 +++--- try/syn/web/template/htmn.hoon | 32 +++++ try/tan/htmn/html.hoon | 2 +- 5 files changed, 269 insertions(+), 29 deletions(-) create mode 100644 try/syn/web/template/htmn.hoon diff --git a/arvo/eyre.hoon b/arvo/eyre.hoon index 1db54e7712..55e0788736 100644 --- a/arvo/eyre.hoon +++ b/arvo/eyre.hoon @@ -82,7 +82,7 @@ ^- httr ?- -.luv %mid [200 ~[content-type/(moon p.luv)] [~ q.luv]] - %ham [200 ~[content-type/'text/html'] [~ (tact (xmlt p.luv ~))]] + %ham [200 ~[content-type/'text/html'] [~ (tact (xmlt | p.luv ~))]] %raw p.luv %wan !! %zap :+ p.luv @@ -232,7 +232,7 @@ ++ hajj :: send %pr response |= [him=ship tus=path har=httr] ^+ +> - +>.$(mow :_(mow [wru [/a hen] [%want him [%r %pr tus] har]])) + +>.$(mow :_(mow [wru [/a /e hen] [%want him [%r %pr tus] har]])) :: ++ hare :: receive request |= [tus=path him=ship hor=*] diff --git a/arvo/hoon.hoon b/arvo/hoon.hoon index 92b0313eab..18b31b3f19 100644 --- a/arvo/hoon.hoon +++ b/arvo/hoon.hoon @@ -28,7 +28,14 @@ ++ axis ,@ :: tree address ++ also ,[p=term q=wing r=type] :: alias ++ base ?([%atom p=odor] %noun %cell %bean %null) :: -++ beer $|(@ [~ p=twig]) :: +++ beer $|(@ [~ p=twig]) :: simple embed +++ beet $| @ :: advanced embed + $% [%a p=twig] :: + [%b p=twig] :: + [%c p=twig] :: + [%d p=twig] :: + [%e p=twig q=(list tuna)] :: + == :: ++ bloq ,@ :: blockclass ++ calf ,[p=(map ,@ud wine) q=wine] :: ++ char ,@tD :: @@ -84,6 +91,13 @@ ++ line ,[p=[%leaf p=odor q=@] q=tile] :: ++ list |* a=_,* :: $|(~ [i=a t=(list a)]) :: +++ mane $|(@tas [@tas @tas]) :: XML name/space +++ mano ,[g=marx c=marl] :: normalized manx +++ manx $|(@tas [t=marx c=marl]) :: XML node +++ marl (list manx) :: XML node list +++ mars ,[t=[n=%$ a=[i=[n=%$ v=tape] t=~]] c=~] :: XML cdata +++ mart (list ,[n=mane v=tape]) :: XML attributes +++ marx $|(@tas [n=mane a=mart]) :: XML tag ++ metl ?(%gold %iron %zinc %lead) :: ++ odor ,@ta :: ++ tarp ,[d=@ud h=@ud m=@ud s=@ud f=(list ,@ux)] :: parsed time @@ -149,6 +163,14 @@ [1 p=term q=toga] :: deep toga [2 p=toga q=toga] :: cell toga == :: +++ tuna :: tagflow + $% [%a p=twig] :: plain text + [%b p=twig] :: single tag + [%c p=twig] :: simple list + [%d p=twig] :: dynamic list + [%e p=twig q=(list tuna)] :: element + [%f p=(list tuna)] :: subflow + == :: ++ twig $& [p=twig q=twig] :: $% :: [%$ p=axis] :: @@ -721,6 +743,15 @@ ?~ a b [i.a $(a t.a)] :: +++ welp :: perfect weld + =| [* *] + |% + +- $ + ?~ +<- + +<-(. +<+) + +<-(+ $(+<- +<->)) + -- +:: ++ wild :: concatenate |* [a=(list) b=(list)] => .(a ^.(homo a), b ^.(homo b)) @@ -5674,6 +5705,7 @@ ~|(%heal-core !!) (core ^$(sut p.sut, axe lat) q.sut) :: + [%face *] (face p.sut $(sut q.sut)) [%fork *] (fork $(sut p.sut) $(sut q.sut)) [%hold *] ?:((~(has in gil) sut) %void $(gil (~(put in gil) sut), sut repo)) @@ -6353,9 +6385,12 @@ => .(i.peh ?^(i.peh i.peh [%| p=0 q=i.peh])) ?- i.peh [& *] + =+ ^= sap ^- (unit term) + ?.(&(=(1 p.i.peh) ?=([%face *] sut)) ~ [~ p.sut]) =+ vas=(peek %rite p.i.peh) =+ gav=$(peh t.peh, sut vas, axe (peg axe p.i.peh)) - [p.gav (heal ~ p.i.peh q.gav)] + =+ heh=(heal ~ p.i.peh q.gav) + [p.gav ?~(sap heh (face u.sap heh))] :: [| *] =+ dob=`post`(need q:(fino p.i.peh %rite q.i.peh)) @@ -6540,6 +6575,184 @@ == == :: + ++ sabe !: :: beet to tuna + |= reb=(list beet) + ^- (list tuna) + =| [sim=(list ,@) tuz=(list tuna)] + |- ^- (list tuna) + ?~ reb + ?~(sim tuz [[%a %smdq (flop sim)] tuz]) + ?@ i.reb + $(reb t.reb, sim [i.reb sim]) + =+ zut=$(reb t.reb, sim ~) + ?~ sim [i.reb zut] + [[%a %smdq (flop sim)] i.reb zut] + :: + ++ saga :: tuna to twig + |= [lut=(list tuna)] !: + ^- twig + :- %cltr + |- ^- (list twig) + ?~ lut [[%dtzz %n ~] ~] + ?- -.i.lut + %a [[%clfs p.i.lut] $(lut t.lut)] + %b [p.i.lut $(lut t.lut)] + %c ^- (list twig) + :_ ~ + :+ %cndt `twig`[p.i.lut [%cltr $(lut t.lut)]] + ^- twig + :+ %tsbr `tile`[[%axil %noun] [%axil %noun]] + ^- twig + :- %brcn + ^- (map term foot) + :_ [~ ~] + :+ %$ %elm + ^- twig + :^ %wtsg `wing`[[%& 12] ~] + :+ %cnts + `wing`[[%& 12] ~] + ^- tram + :~ [[[%& 1] ~] [~ 13]] + == + :+ %cnts + `wing`[[%& 12] ~] + ^- tram + :~ :- [[%& 3] ~] + ^- twig + :+ %cnts [%$ ~] + ^- tram + :~ [[[%& 12] ~] [~ 25]] + == + == + %d [[%cnhp p.i.lut [%cltr $(lut t.lut)] ~] ~] + %e [[p.i.lut [%cltr $(lut q.i.lut)]] $(lut t.lut)] + %f $(lut (weld p.i.lut t.lut)) + == + :: + ++ said :: template language + |= tol=? !: + |% + ++ ape :: product twig + %- cook + :_ amp + |= tum=tuna ^- twig + ?: ?=([%e *] tum) + [p.tum (saga q.tum)] + (saga tum ~) + :: + ++ amp :: entry point + ;~(pfix sem ?:(tol bam bat)) + :: + ++ bam :: tall top + %+ knee *tuna |. ~+ + ;~ pose + (stag %f ;~(pfix (plus ace) pav)) + (stag %e ;~(plug hug nol)) + ;~(pfix tis (stag %f nol)) + ;~(pfix hep (stag %a ;~(pfix gap tall))) + ;~(pfix lus (stag %b ;~(pfix gap tall))) + ;~(pfix tar (stag %c ;~(pfix gap tall))) + ;~(pfix cen (stag %d ;~(pfix gap tall))) + == + :: + ++ bat :: wide outer top + %+ knee *tuna |. ~+ + ;~ pose + (stag %f nup) + (stag %f ped) + (stag %e ;~(plug hug lif)) + == + :: + ++ bet :: wide inner top + %+ knee *tuna |. ~+ + ;~ pose + bat + ;~(pfix hep (stag %a wide)) + ;~(pfix lus (stag %b wide)) + ;~(pfix tar (stag %c wide)) + ;~(pfix cen (stag %d wide)) + == + :: + ++ fry :: mane as twig + %+ cook + |= [a=@tas b=(unit ,@tas)] + ?~ b + [%dtzz %tas a] + [[%dtzz %tas a] [%dtzz %tas u.b]] + ;~(plug sym ;~(pose (stag ~ ;~(pfix fas sym)) (easy ~))) + :: + ++ hug :: wide twig + %+ cook |=(a=twig a) + ;~(plug fry ;~(pose jaw (easy [%dtzz %n ~]))) + :: + ++ jaw :: wide attributes + %+ ifix [pel per] + %+ stag %clsg + %+ more ;~(plug com ace) + ;~(plug fry ;~(pfix ace wide)) + :: + ++ lif :: wide elements + %+ cook |=(a=(list tuna) a) + ;~(pose ;~(pfix col pep) (easy ~)) + :: + ++ luf :: wide elements + %+ cook |=(a=(list tuna) a) + (star ;~(pfix ace bet)) + :: + ++ nol :: tall tail + ?> tol + %+ cook |=(a=(list tuna) a) + ;~ pose + (cold ~ sem) + ;~(pfix ;~(plug col ace) (cook |=(a=(list tuna) [[%f a] ~]) pav)) + (ifix [gap ;~(plug gap duz)] (more gap amp)) + == + :: + ++ nup :: wide quote + %+ cook |=(a=(list tuna) a) + (ifix [doq doq] pav) + :: + ++ ped + %+ cook |=(a=(list tuna) a) + (ifix [pel per] (more ace bet)) + :: + ++ pep :: wrapped tuna + %+ cook |=(a=(list tuna) a) + ;~ pose + ped + (ifix [pel per] (more ace bet)) + ;~ plug + bat + (easy ~) + == + == + :: + ++ pav :: wide/tall flow + %+ cook |=(a=(list beet) (sabe a)) + %- star + ;~ pose + ;~(pfix bas ;~(pose bas hep doq lus tar cen sem kel bix:ab)) + ;~(pfix hep (stag %a wop)) + ;~(pfix lus (stag %b wop)) + ;~(pfix tar (stag %c wop)) + ;~(pfix cen (stag %d wop)) + ;~(pfix sem (stag %e wot(tol |))) + ;~ pose + ?:(tol (shim 32 91) ;~(pose (shim 32 33) (shim 35 91))) + (shim 93 122) + (shim 124 126) + (shim 128 255) + == + (stag %a wop) + == + :: + ++ wop :: wide in brace + (ifix [kel ker] (stag %cltr (most ace wide))) + :: + ++ wot + (ifix [kel ker] ;~(plug hug luf)) + -- + :: ++ scat %+ knee *twig |. ~+ %- stew @@ -7165,8 +7378,9 @@ == == :: - ++ tall (knee *twig |.(~+((wart ;~(pose (norm &) long lute))))) - ++ wide (knee *twig |.(~+((wart ;~(pose (norm |) long))))) + ++ tall %+ knee *twig + |.(~+((wart ;~(pose (norm &) long lute ape:(said &))))) + ++ wide (knee *twig |.(~+((wart ;~(pose (norm |) long ape:(said |)))))) ++ hill (knee *tile |.(~+(;~(pose (noil |) toil)))) ++ howl (knee *tile |.(~+(;~(pose (noil &) toil)))) ++ toil diff --git a/arvo/zuse.hoon b/arvo/zuse.hoon index dc69404bd9..994df7a072 100644 --- a/arvo/zuse.hoon +++ b/arvo/zuse.hoon @@ -577,10 +577,11 @@ ^- tape ?~ tat rez =+ ryq=$(tat t.tat) - :(weld (xmln n.i.tat) "=\"" (xmle v.i.tat '"' ?~(t.tat ryq [' ' ryq]))) + :(weld (xmln n.i.tat) "=\"" (xmle | v.i.tat '"' ?~(t.tat ryq [' ' ryq]))) :: ++ xmle :: escape for xml - |= [tex=tape rez=tape] + |= [unq=? tex=tape rez=tape] + ?: unq (weld tex rez) =+ xet=`tape`(flop tex) |- ^- tape ?~ xet rez @@ -589,7 +590,7 @@ rez ?- i.xet 34 ['&' 'q' 'u' 'o' 't' ';' rez] 38 ['&' 'a' 'm' 'p' ';' rez] - 39 ['&' 'a' 'p' 'o' 's' ';' rez] + 39 ['&' '#' '3' '9' ';' rez] 60 ['&' 'l' 't' ';' rez] 62 ['&' 'g' 't' ';' rez] * [i.xet rez] @@ -601,24 +602,24 @@ ?@ man (trip man) (weld (trip -.man) `tape`[':' (trip +.man)]) :: -++ xmll :: nodes to tape - |= [lix=(list manx) rez=tape] - =+ xil=(flop lix) +++ xmll :: nodelist to tape + |= [unq=? lix=(list manx) rez=tape] |- ^- tape - ?~ xil rez - $(xil t.xil, rez (xmlt i.xil rez)) + ?~ lix rez + (xmlt unq i.lix $(lix t.lix)) :: ++ xmlt :: node to tape - |= [mex=manx rez=tape] + |= [unq=? mex=manx rez=tape] ^- tape => .(mex `mano`?^(mex mex [mex ~])) - ?: ?=([%$ [[%$ *] ~]] t.mex) - (xmle v.i.a.t.mex rez) - =+ man=`mane`?@(t.mex t.mex -.t.mex) + =. unq |(unq =(%script g.mex) =(%style g.mex)) + ?: ?=([%$ [[%$ *] ~]] g.mex) + (xmle unq v.i.a.g.mex rez) + =+ man=`mane`?@(g.mex g.mex -.g.mex) =+ tam=(xmln man) =+ end=:(weld "" rez) - =+ bod=['>' (xmll c.mex :(weld "" rez))] - =+ att=`mart`?@(t.mex ~ a.t.mex) + =+ bod=['>' (xmll unq c.mex :(weld "" rez))] + =+ att=`mart`?@(g.mex ~ a.g.mex) :- '<' %+ weld tam `_tam`?~(att bod [' ' (xmla att bod)]) @@ -2018,6 +2019,7 @@ ++ gram ,@uw :: physical datagram ++ gyro ,[p=@ud q=wire r=prod] :: live prompt ++ hand ,@uvH :: hash of code +++ hart ,[p=? q=(unit ,@ud) r=host] :: http sec/port/host ++ hate ,[p=purl q=@p r=moth] :: semi-cooked request ++ heir ,[p=@ud q=mess r=(unit love)] :: status/headers/data ++ hiss ,[p=purl q=moth] :: outbound request @@ -2025,7 +2027,6 @@ ++ hole ,@t :: session identity ++ hook path :: request origin ++ hoot ,[p=? q=? r=(unit ,@ud) s=host] :: secure/mapped/host -++ hart ,[p=? q=(unit ,@ud) r=host] :: http sec/port/host ++ hort ,[p=(unit ,@ud) q=host] :: http port/host ++ hose ,[p=(list tank) q=(unit vase) r=seam s=heir] :: http environment ++ host $%([& p=(list ,@t)] [| p=@if]) :: http host @@ -2086,14 +2087,7 @@ == :: ++ maki ,[p=@ta q=@ta r=@ta s=path] ++ mace (list ,[p=life q=ring]) :: private secrets -++ mane $|(@tas [@tas @tas]) :: XML name/space -++ mano ,[t=marx c=marl] :: normalized manx -++ manx $|(@tas [t=marx c=marl]) :: XML node -++ marl (list manx) :: XML node list -++ mars ,[t=[n=%$ a=[i=[n=%$ v=tape] t=~]] c=~] :: XML cdata -++ mart (list ,[n=mane v=tape]) :: XML attributes ++ marv ?(%da %tas %ud) :: release form -++ marx $|(@tas [n=mane a=mart]) :: XML tag ++ masu ,[p=ship q=disc r=moar s=moar] :: sync square ++ math (map ,@t (list ,@t)) :: semiparsed headers ++ meal :: payload diff --git a/try/syn/web/template/htmn.hoon b/try/syn/web/template/htmn.hoon new file mode 100644 index 0000000000..547f1256d3 --- /dev/null +++ b/try/syn/web/template/htmn.hoon @@ -0,0 +1,32 @@ +!: +:: Some uses of template syntax +:: +%- give +|= epic +^- manx +=+ lim=;li:"second ;{a(href "http://www.urbit.org") "link"} item" +=+ lum=;li:"third [owner: {(scow %p own)}] item" +=+ lom=;li:"fourth (;{i "italics"}) item" +=+ foo=`manx`i/;"foobar" +=+ lam=`(list manx)`[lim lum lom ~] +;html + ;head + ;title: Urbi et Burbi + == + ;body + ;p: Hello, world. + ;p: Behold a

aragraph with an embedded {"string"}. + ;p: Or an embedded ;{i "tag"}. + ;p: Or even a *{i/;"list" i/;" of" i/;" tags" ~}, + ;p: Sometimes %{|*(a=* [i/;"functionally " i/;"applied" a])}. + ;p: It's nice to just be able to use "quotes." + ;p + ; We are also very good at lists: + ;ul + ;li: first item + ;* lam + ;li: last item + == + == + == +== diff --git a/try/tan/htmn/html.hoon b/try/tan/htmn/html.hoon index 898f3f2571..ab2acdcc75 100644 --- a/try/tan/htmn/html.hoon +++ b/try/tan/htmn/html.hoon @@ -1,3 +1,3 @@ !: |= mex=manx -(crip (xmlt mex ~)) +(crip (xmlt | mex ~))