admin
login
%hawk
/lib/hawk/hoon
/- *hawk /+ html-utils, manx-utils |% ++ en-mime :: |= [=mite =cord] ^- mime [mite (as-octs:mimes:html cord)] :: :: path helpers :: ++ is-ancestor :: |= [elder=(list @t) younger=(list @t)] ^- flag |- ?~ elder %.y ?~ younger %.n ?. =(i.elder i.younger) %.n $(elder t.elder, younger t.younger) :: ++ ancestors :: |= pax=path ^- (list path) %- snip %+ turn (gulf 0 (lent pax)) |= n=@ (scag n pax) :: ++ leafs :: |= [prefix=path =file] ^- (set path) =/ paths ~(tah fu file) %- silt %+ murn paths |= p=path =/ is-leaf=(list path) %+ murn paths |= q=path ?. (is-ancestor p q) ~ `p ?. =(1 (lent is-leaf)) ~ `(welp prefix p) :: ++ longest :: |= paths=(set path) ^- (unit path) %- mole |. %+ snag 0 %+ sort ~(tap in paths) |= [a=path b=path] (gth (lent a) (lent b)) :: ++ relative :: |= [here=path up=@ud down=path] ^- path (welp (scag (sub (lent here) up) here) down) :: ++ peel-mask :: :: masks are path prefixes consisting of only flag dimes :: |= pax=path =/ out=(pair path path) [/ pax] ^+ out |- ?~ q.out out ?. ?| =(i.q.out ~..y) =(i.q.out ~..n) == out $(out [(snoc p.out i.q.out) t.q.out]) ++ split-inner :: :: split inner namespace from path if any :: |= pax=path ^- (pair path (unit path)) ?~ ind=(find [%$]~ pax) [pax ~] :- (scag u.ind pax) `(slag +(u.ind) pax) :: :: :: :: :: info multiplexing :: +$ plan (map path card) ++ plex-plan :: |= [root=path nif=info default-card=card] ^- plan =/ dimes=(list (trel path path dime)) %+ turn ~(tap iu nif) |= [pax=path dim=dime] =/ paths (split-path pax) [(welp root p.paths) q.paths dim] :: =| pan=plan |- ?~ dimes pan %= $ dimes t.dimes pan %+ ~(put by pan) p.i.dimes ^- card :: %+ ~(put of (~(gut by pan) p.i.dimes default-card)) q.i.dimes r.i.dimes == :: ++ split-path :: on empty symbol :: |= b=path ^- (pair path path) =| a=path |- ?~ b [/ a] =/ seg i.b ?~ seg [a t.b] $(a (snoc a seg), b t.b) :: :: :: :: file utils :: ++ fu |_ a=file :: :: descended engines :: ++ f |=(=path ~(. fu (dip path))) ++ m |=(=path ~(. iu (atr path))) ++ d |=(=path ~(. mx:html-utils data:(git path))) ++ dip |=(=path (~(dip of a) path)) :: ++ atr :: effective attriubutes (including inherited) :: |= pax=path ^- info =/ route=path / =| i=info |- =/ pag (git route) =/ dist (sub (lent pax) (lent route)) =/ met=(list (pair path dime)) :: metadata inherited from route %+ murn ::~(tap of meta:pag) %+ sort ~(tap of meta:pag) |= [a=[=path *] b=[=path *]] (aor path.b path.a) :: sort so that //X takes precedece over //~ |= [pix=path dim=dime] ^- (unit [path dime]) =/ split (split-inner pix) ?~ q.split ?. =(pax route) ~ `[p.split dim] ?: =(u.q.split /~) ?: =(pax route) ~ `[p.split dim] ?: =(u.q.split /[(scot %ud dist)]) `[p.split dim] ~ :: :: ?: =(pax route) (~(gas of i) met) %= $ route (scag +((lent route)) pax) i (~(gas of i) met) == :: ++ atr-old :: XX delete :: |= pax=path ^- info =/ route=path / =| i=info |- =/ pag (git route) =/ dist (sub (lent pax) (lent route)) =/ met %+ murn ~(tap of meta:pag) |= [pix=path dim=dime] ^- (unit [path dime]) =/ split (peel-mask pix) ?~ (lent p.split) `[q.split dim] ?. .= (scot %f %.y) (fong dist (scot %f %.n) p.split) ~ `[q.split dim] :: ?: =(pax route) (~(gas of i) met) %= $ route (scag +((lent route)) pax) i (~(gas of i) met) == :: :: :: root aliases :: ++ tip (git /) ++ top (got /) ++ met meta:tip ++ dat data:tip ++ mim `mime`code:tip ++ cod q.q.code:tip :: :: lookups :: ++ get |=(=path (~(get of a) path)) ++ git |=(=path (fall (get path) *page)) ++ got |=(=path ~|([%not-found path] (need (get path)))) ++ gut |=([=path =page] (fall (get path) page)) :: ++ has |=(=path !=(~ (get path))) :: :: transformations :: ++ tap ~(tap of a) ++ tah (turn tap |=([=path *] path)) ++ tax (turn tap |=([* =page] page)) :: :: transformations without root page :: ++ wap ~(tap of (~(del of a) /)) ++ wah (turn wap |=([=path *] path)) ++ wax (turn wap |=([* =page] page)) ++ kid :: list of populated direct sub-pages %+ murn wap |= [=path =page] ?. ?=([* ~] path) ~ `[path page] :: :: additions :: :: with deps ++ put |=([=path =page] (~(put of a) path page)) ++ gas |=(x=(list [path page]) (~(gas of a) x)) ++ pas :: prepended gas |= [pax=path x=(list [path page])] %- gas %+ turn x |= [pix=path =page] [(welp pax pix) page] -- :: :: :: :::: info functions :: ++ rend :: render :: |= =dime ?+ -.dime (scow dime) %t "{(trip +.dime)}" %ta "{(trip (wood +.dime))}" ::%tas "{(trip +.dime)}" == :: :: ++ rend-as :: render as :: |= [aura=term =dime] (rend aura +.dime) :: ++ print-dime :: render parse-able :: |= =dime %+ welp "{(trip -.dime)}/" ?+ -.dime (scow dime) %t "'{(trip +.dime)}'" %tas "'{(trip +.dime)}'" == :: ++ ix :: build info :: |= [fil=(unit dime) dir=(list (pair @ info))] ^- info [fil (malt dir)] :: ++ iy :: build info child :: |= [seg=term fil=(unit dime) dir=(list (pair @ info))] [seg (ix fil dir)] :: ++ il :: build info from list :: |= l=(list (pair path dime)) (~(gas of *info) l) :: ++ iu :: info utils |_ a=info :: :: descended engine :: ++ i |=(=path ~(. iu (dip path))) ++ dip |=(=path (~(dip of a) path)) :: :: lookups :: ++ reb |=(=path (~(get of a) path)) ++ rib |=(=path (fall (reb path) *dime)) ++ rob |=(=path ~|([%not-found path] (need (reb path)))) ++ rub |=([=path =dime] (fall (reb path) dime)) :: ++ has |=(=path !=(~ (reb path))) :: :: print lookups :: ++ peb |=(=path (bind (reb path) rend)) ++ pib |=(=path (rend (rib path))) ++ pob |=(=path (rend (rob path))) ++ pub |=([=path =dime] (rend (rub path dime))) :: :: casted print lookups :: ++ peb-as |=([=term =path] (bind (reb path) (cury rend-as term))) ++ pib-as |=([=term =path] (rend-as term (rib path))) ++ pob-as |=([=term =path] (rend-as term (rob path))) ++ pub-as |=([=term =path =dime] (rend-as term (rub path dime))) :: :: transformations :: ++ tap ~(tap of a) ++ tah (turn tap |=([=path *] path)) ++ tax (turn tap |=([* =dime] dime)) :: :: transformations without root dime :: ++ wap ~(tap of (~(del of a) /)) ++ wah (turn wap |=([=path *] path)) ++ wax (turn wap |=([* =dime] dime)) :: :: additions :: ++ put |=([=path =dime] (~(put of a) path dime)) ++ gas |=(x=(list [path dime]) (~(gas of a) x)) ++ pas :: prepended gas |= [pax=path x=(list [path dime])] %- gas %+ turn x |= [pix=path =dime] [(welp pax pix) dime] -- :: :: :: :: dime parser :: :: :: ++ fong :: fallen +mong :: |* [a=@ f=* b=(list)] ^+ ?>(?=(^ b) i.b) (fall (mong a b) f) :: ++ nth-or fong ++ mong :: mole'd +snag :: |* [a=@ b=(list)] ^+ ?>(?=(^ b) *(unit _i.b)) %- mole |. (snag a b) :: ++ snug :: soft snag :: |= [a=@ b=tape] ^- tape ?~ b "" ?: =(0 a) [i.b ~] $(b t.b, a (dec a)) ++ stub :: soft stab :: |= =cord ^- (unit path) %- mole |. (stab cord) :: :: :: parse cord to dime as :: ++ slow :: |= [=term =cord] ^- dime ?+ term [term cord] %t t/cord :: (scot %t cord) %f f/(fall (slaw %f cord) *?) %p p/(fall (slaw %p cord) *@p) %q q/(fall (slaw %q cord) *@q) %da da/(fall (slaw %da cord) *@da) %ud ud/(fall (slaw %ud cord) *@ud) %ux ux/(fall (slaw %ux cord) *@ux) %uv uv/(fall (slaw %uv cord) *@uv) %uw uw/(fall (slaw %uw cord) *@uw) == :: ++ pause :: |= [as=term =tape] ^- dime :- as =/ =cord (crip tape) (fall (slaw as cord) (fall (slaw as (cord-snip cord)) 0)) :: ++ nusk :: soft nuck. tape -> dime :: :: |= =tape ^- dime =/ =coin %+ fall (rust tape nuck:so) %+ fall (rust (snip tape) nuck:so) [%$ t/(crip tape)] ?+ -.coin ux/0 %$ p.coin == :: ++ cord-snip :: |= c=cord ^- cord =/ size (met 3 c) =/ news ?~ size 0 (dec size) (cut 3 [0 news] c) :: :: ++ dime-location :: cord to (pair aura path) :: |= =cord ^- (pair term path) :- %tas %- fall :_ ~[cord] %- mole |. %+ rash cord ;~(pfix fas (most fas urs:ab)) :: does not use +stab. this sucks! :: can't use +stab, because stab does not support the last segment :: being empty (unless i'm missing something). :: i need to support last segment being empty to to path :: multiplexing :: ++ dime-location-old :: |= =cord ^- (pair term path) ?~ y=(mole |.((stab cord))) ?~ x=(mole |.((stab (cat 3 '/' cord)))) [%tas ~(rent co %$ %t cord)^~] =/ tap (trip cord) =/ a (mole |.((stab (crip (slag 2 tap))))) ?: ?& !=((snug 0 tap) "/") =((snug 1 tap) "/") =((snug 2 tap) "/") !=(a ~) == [(crip (scag 1 tap)) (need a)] =/ b (mole |.((stab (crip (slag 3 tap))))) ?: ?& !=((snug 0 tap) "/") !=((snug 1 tap) "/") =((snug 2 tap) "/") =((snug 3 tap) "/") !=(b ~) == [(crip (scag 2 tap)) (need b)] =/ c (mole |.((stab (crip (slag 4 tap))))) ?: ?& !=((snug 0 tap) "/") !=((snug 1 tap) "/") !=((snug 2 tap) "/") =((snug 3 tap) "/") =((snug 4 tap) "/") !=(c ~) == [(crip (scag 3 tap)) (need c)] =/ d (mole |.((stab (crip (slag 5 tap))))) ?: ?& !=((snug 0 tap) "/") !=((snug 1 tap) "/") !=((snug 2 tap) "/") !=((snug 3 tap) "/") =((snug 4 tap) "/") =((snug 5 tap) "/") !=(d ~) == [(crip (scag 4 tap)) (need d)] [%tas u.x] [%tas u.y] :: :: :: marl utils :: ++ mq |% ++ add-class :: |= [class=tape r=marl] %+ turn r |= m=manx (~(prepend-class mx:html-utils m) (welp class " ")) :: ++ remove-class :: |= [class=tape r=marl] %+ turn r |= m=manx ^- manx %- ~(modify-class mx:html-utils m) |= * %- zing ^- (list tape) %+ join " " %+ skip (class-list m) |= =tape =(tape class) :: :: ++ class-list :: |= m=manx ^- (list tape) %- classes:parsers:html-utils (fall ~(get-class mx:html-utils m) "") :: ++ children :: |= r=marl ^- marl %- zing ^- (list marl) %+ turn r |= =manx c.manx ++ get-id :: |= [id=tape m=manx] ^- marl ?~ el=(~(gid mx:html-utils m) id) ~ [q.u.el ~] ++ first-id :: |= [id=tape r=marl] ^- marl %+ murn r |= m=manx ?~ el=(~(gid mx:html-utils m) id) ~ `q.u.el :: ++ first-tag :: |= [tag=mane r=marl] ^- marl %+ murn r |= m=manx ?~ el=(~(gag mx:html-utils m) tag) ~ `q.i.el :: ++ get-class :: |= [class=tape m=manx] ^- marl %+ turn %- ~(wic mx:html-utils m) |= [path =manx] ?^ (find ~[class] (class-list manx)) %.y %.n |= [path =manx] manx ++ first-class :: |= [class=tape r=marl] %+ murn r |= m=manx =/ el %- ~(wif mx:html-utils m) |= [path m=manx] ?^ (find ~[class] (class-list m)) %.y %.n ?~ el ~ `q.u.el ++ first-attribute :: |= [=mane =tape r=marl] %+ murn r |= m=manx =/ el %- ~(wif mx:html-utils m) |= [path m=manx] .= `tape (~(get by (malt a.g.m)) mane) ?~ el ~ `q.u.el ++ find-class :: |= [class=tape r=marl] ^- marl %- zing %+ turn r |= m=manx ^- marl %+ turn %- ~(wic mx:html-utils m) |= [path =manx] ?^ (find ~[class] (class-list manx)) %.y %.n |=([path =manx] manx) ++ as-tapes text-content ++ as-tape :: :: xx use cury here or something? |= r=marl ^- tape (zing (text-content r)) :: ++ as-cord :: |= r=marl ^- cord (crip (as-tape r)) :: ++ text-content :: |= r=marl ^- (list tape) %+ turn r |= =manx ~(all-text-content mx:html-utils manx) :: ++ attributes :: attributes of all that had :: |= [rib=term r=marl] ^- (list tape) %+ murn r |= =manx (get:~(at mx:html-utils manx) rib) :: ++ attribute :: attribute of first :: |= [rib=term r=marl] ^- (unit tape) (get:~(at mx:html-utils (nth-or 0 *manx r)) rib) :: ++ dimes :: |= [tapes=(list tape)] ^- (list dime) %+ turn tapes |= =tape =/ val (crip tape) =; =coin ?+ -.coin [%tas '%many and %blob unsupported'] %$ p.coin == %+ fall (slay val) [%$ %tas val] :: ++ dimes-as :: |= [=term tapes=(list tape)] ^- (list dime) %+ turn tapes |= =tape (pause term tape) ++ print-dimes :: |= dimes=(list dime) ^- (list tape) (turn dimes rend) -- ++ prepend-wall :: |= [front=tape wall=tape] ^- tape %- zing %+ join "\0a" %+ turn (scan wall (more (jest '\0a') (star ;~(less (jest '\0a') (shim 0 100.000.000))))) |= line=tape (welp front line) :: ++ print-sail :: |= [=manx i=@] ^- tape =/ tag ?@(n.g.manx (trip n.g.manx) (trip 'AAAAAAAA')) ::XX =/ ind (reap i ' ') =/ jnd (reap +(i) ' ') ?: =(n.g.manx %$) =/ t (~(gut by (malt a.g.manx)) %$ "") ?: =(0 (lent t)) ?: =(0 i) "" "{jnd};" ?: =(t "\0a") "" :: :: format text block with '; ' prefixed for each line =/ newline (jest '\0a') =/ char (star ;~(less newline prn)) =/ lines (fall (rust (trip (crip t)) (more newline char)) ~) %+ join '\0a' %+ murn lines |= =tape ?~ tape ~ `(crip "{ind}; {tape}") =/ is-text-node %+ levy c.manx |= kid=^manx =(n.g.kid %$) =/ kids=(list cord) ?: is-text-node :_ ~ %- crip ^- tape ;: welp "{jnd};+ ;/ %- trip\0a" "{jnd}'''\0a" (prepend-wall jnd `tape`~(all-text-content mx:html-utils manx)) "\0a{jnd}'''" == %+ turn c.manx |= kid=^manx (crip (print-sail kid +(i))) =* at ~(. by (malt a.g.manx)) =/ id ?~ ud=(get:at %id) "" (welp "#" u.ud) =/ class ?~ ud=(get:at %class) "" =/ cll (turn (scan u.ud (more ace (star ;~(less ace prn)))) crip) (welp "." (join '.' cll)) =/ other (~(del by (del:at %id)) %class) =/ ribs %+ turn ~(tap by other) |= [=mane =tape] =/ rib ?@(mane (trip mane) (trip 'AAAAAAAA')) :: XX (crip "{jnd}={rib} \"{tape}\"") =/ children ?: =(0 (lent c.manx)) "{jnd};* ~" (join '\0a' `(list cord)`kids) =/ attributes ?: =(0 ~(wyt by other)) "" (weld "\0a" (join '\0a' `(list cord)`ribs)) """ {ind};{tag}{id}{class}{attributes} {children} {ind}== """ :: --