added schematized tree hook

This commit is contained in:
Anton Dyudin 2015-08-03 16:49:34 -07:00
parent bd9e281909
commit 6f1db73b7f
7 changed files with 221 additions and 0 deletions

39
lib/tree.hoon Normal file
View File

@ -0,0 +1,39 @@
/- tree-include
|%
++ baff |*([a=(unit) b=(trap)] ?^(a a *b))
++ find-in-tree
|* [paz=fist:jo fun=$+(* (unit))]
|= a=json ^+ *fun
%+ biff (paz a)
|* [b=(list json) c=*] ^+ *fun
%+ baff (fun c)
|.
?~ b ~
(baff ^^$(a i.b) |.(^$(b t.b)))
::
++ json-front
|= a=json ^- json
=- (fall `(unit json)`- ~)
%+ biff ((ot body/some ~):jo a)
%+ find-in-tree (ot c/(ar some) gn/so ga/(om so) ~):jo
|= [nom=span atr=(map span cord)] ^- (unit json)
?. (~(has by atr) 'urb:front') ~
?> ?=(%meta nom)
(biff (~(get by atr) %value) poja)
::
++ read-schem
=< (cook to-noun (cook to-tree apex))
|%
++ data $|(term [n=@ l=data r=data])
++ apex ;~(plug sym (star ;~(plug delim sym)))
++ delim ;~(pose (cold 0 dot) (cook lent (plus cab)))
++ to-noun |=(a=data ?@(a a [$(a l.a) $(a r.a)]))
++ to-tree
|= [acc=data a=(list ,[p=@u q=term])]
%+ roll a =< .(acc ^acc)
|= [[n=@u v=term] acc=data]
?@ acc [n acc v]
?: (gth n n.acc) [n acc v]
acc(r $(acc r.acc))
--
--

4
mar/tree-include.hoon Normal file
View File

@ -0,0 +1,4 @@
/- tree-include
|_ tree-include
++ grab |% ++ noun tree-include
-- --

46
pub/doc/tree.md Normal file
View File

@ -0,0 +1,46 @@
`:tree` is the web filesystem interface.
# Internals
somethins something coffeescript
## `/[desk]/tree/{path}.json`
tree/json.hook accepts a schema in light noun encoding¹
++ schema (dict ,[term $|(mark schema)])
++ dict |*(a=_,* $&([a (dict a)] a))
which is normalized and type-checked(request types are `%t` text, `%r` html-derived tree, and `%j` arbitrary json) to a `query` list of
- `[%kids query]`, the only recursive value, which executes for all subpaths
XX descent is only currently supported to a single level as a performance optimization
- `[%name %t]`, the node name
- `[%snip %r]`, a snippet, extracted via `react-snip-json`
- `[%head %r]`, the first header, extracted via `react-head-json`
- `[%body %r]`, the `react-json` body
- `[%meta %j]`, json frontmatter per the `mdy` mark definition
- `[%index %j]`, a search index generated from the first header of each file in a path below the request one (SLOW)
Per this specification, the current access points will be migrated:
- (json.hook)`""` to `body:'r' kids:{name:'t'}` `"?body.r__kids_name.t"`
- `"?kids"` to `kids:{name:'t' body:'r'}` `"?kids_name.t_body.r"`
- `"?snip"` to `kids:{name:'t' body:'r' head:'r' meta:'j'}` `"?kids_name.t_body.r"`
- `"?heads"` to `index:'j'` `"?index.j"`
¹In the examples,
=< (cook to-noun (cook to-tree apex))
|%
++ data $|(term [n=@ l=data r=data])
++ apex ;~(plug sym (star ;~(plug delim sym)))
++ delim ;~(pose (cold 0 dot) (cook lent (plus cab)))
++ to-noun |=(a=data ?@(a a [$(a l.a) $(a r.a)]))
++ to-tree
|= [acc=data a=(list ,[p=@u q=term])]
%+ roll a =< .(acc ^acc)
|= [[n=@u v=term] acc=data]
?@ acc [n acc v]
?: (gth n n.acc) [n acc v]
acc(r $(acc r.acc))
--
Curtis, this can be full coin %many if you wish.

6
sur/tree-include.hoon Normal file
View File

@ -0,0 +1,6 @@
|-
$: body=json
head=json
snip=json
meta=json
==

View File

@ -0,0 +1,7 @@
/+ tree
/= body /: /=== /% /react-json/
/= head /: /=== /% /react-head-json/
/= snip /: /=== /% /react-snip-json/
/= meta /: /=== /% /; json-front /react-snip-json/
^- tree-include
[body head snip meta]

52
tree/json.hook Normal file
View File

@ -0,0 +1,52 @@
::
/? 314
/= gas /$ fuel
/= ral /: /=== /% /react-json/
/= pal /: /===
/^ (map ,@ta json)
/% 2
/_ /react-json/
::
/= sal /: /===
/^ (map ,@ta json)
/% 2
/_ /react-snips-json/
::
::::
::
// /%%/util
::
[util=. +>]
::
!:
::::
::
^- json
=+ ~(. util gas)
:: .json?kids
?: (~(has by qix.gas) %kids)
%+ joba %kids
=. pal (~(del by pal) %md) :: XX haxor
=- [%a (turn (~(tap by pal)) -)]
|= [a=span b=json]
%- jobe :~
name/s/a
body/b
==
:: .json?snip
?: (~(has by qix.gas) %snip)
%+ joba %snip
=. sal (~(del by sal) %md) :: XX haxor
=- [%a (turn (~(tap by sal)) -)]
|= [a=span b=json]
=+ fon=(json-front b)
%- jobe :~
meta/fon
name/s/a
body/b
==
:: .json
%- jobe :~
kids/[%a (turn get-kids |=(a=span s/a))]
body/ral
==

67
tree/schem/json.hook Normal file
View File

@ -0,0 +1,67 @@
::
/? 314
/+ tree
/= gas /$ fuel
/= dat /^ tree-include
/: /===/tree-gen /%
/tree-include/
::
/= kid /^ (map span tree-include)
/: /===/tree-gen /% 2 /_
/tree-include/
!:
::::
::
|%
++ schema (dict ,[term $|(mark schema)])
++ dict |*(a=_,* $&([a (dict a)] a))
++ query
$% [%kids p=(list query)]
[%name %t]
[%snip %r]
[%head %r]
[%body %r]
[%meta %j]
==
++ to-queries
|= a=schema ^- (list query)
?@(-.a [(to-query a) ~] [(to-query -.a) $(a +.a)])
::
++ to-query
|= a=[term $|(mark schema)]
~| invalid-query/a
?+ -.a ;;(query a)
%kids [%kids (to-queries ?@(+.a !! +.a))]
==
++ from-type :: XX holding out for noun odors
|= a=$%([%t p=cord] [%r p=json] [%j p=json])
?- -.a
%t [%s p.a]
%r p.a
%j p.a
==
++ from-queries
|= [bem=beam quy=(list query)]
=< (jobe (turn quy .))
|= a=query
:- -.a
?- -.a
%name (from-type +.a ?^(s.bem i.s.bem q.bem))
%head (from-type +.a head.dat)
%snip (from-type +.a snip.dat)
%meta (from-type +.a meta.dat)
%body (from-type +.a body.dat)
%kids ?< (~(has by (mo p.a)) %kids) :: XX recursion?
=< a/(turn (~(tap by kid)) .)
|= [dir=span dak=tree-include]
^^$(quy p.a, s.bem [dir s.bem], dat dak, kid ~)
==
--
!:
::::
::
^- json
=+ ^= schem
=+ seh=(fall (~(get by qix.gas) 'q') 'body.r')
~|(bad-noun/seh ;;(schema (rash seh read-schem)))
(from-queries bem.gas(s but.gas) (to-queries schem))