1 ! Copyright (C) 2005, 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: arrays definitions errors generic graphs hashtables
5 io kernel namespaces prettyprint prettyprint-internals
11 TUPLE: article title content loc ;
13 TUPLE: no-article name ;
14 : no-article ( name -- * ) <no-article> throw ;
16 : article ( name -- article )
17 dup articles get hash [ ] [ no-article ] ?if ;
19 M: object article-title article article-title ;
20 M: object article-content article article-content ;
24 M: link article-title link-name article-title ;
25 M: link article-content link-name article-content ;
26 M: link summary "Link: " swap link-name unparse append ;
28 ! Special case: f help
29 M: f article-title drop \ f article-title ;
30 M: f article-content drop \ f article-content ;
32 : word-help ( word -- content ) "help" word-prop ;
34 : all-articles ( -- seq )
35 articles get hash-keys
36 all-words [ word-help ] subset append ;
38 GENERIC: elements* ( elt-type element -- )
40 : elements ( elt-type element -- seq ) [ elements* ] { } make ;
42 : collect-elements ( element seq -- elements )
46 1 tail [ dup set ] each
49 ] make-hash hash-keys ;
55 : children ( topic -- seq )
56 article-content { $subsection } collect-elements ;
58 : parents ( topic -- seq )
59 dup link? [ link-name ] when parent-graph get in-edges ;
61 : (doc-path) ( topic -- )
62 dup , parents [ word? not ] subset dup empty?
63 [ drop ] [ [ (doc-path) ] each ] if ;
65 : doc-path ( topic -- seq )
66 [ (doc-path) ] { } make 1 tail prune ;
68 : xref-article ( topic -- )
69 [ children ] parent-graph get add-vertex ;
71 : unxref-article ( topic -- )
72 [ children ] parent-graph get remove-vertex ;
75 all-articles [ children ] parent-graph get build-graph ;