]> gitweb.factorcode.org Git - factor.git/blob - extra/fuel/help/help.factor
a1a6bb2344365e5b20a404001b702a07d0ae5606
[factor.git] / extra / fuel / help / help.factor
1 ! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs combinators combinators.short-circuit fry
4 fuel.eval help help.crossref help.markup help.markup.private help.topics io
5 io.streams.string kernel make namespaces parser prettyprint sequences summary
6 help.vocabs vocabs vocabs.loader vocabs.hierarchy vocabs.metadata
7 vocabs.parser words see listener sets ;
8 FROM: vocabs.hierarchy => child-vocabs ;
9 IN: fuel.help
10
11 <PRIVATE
12
13 : fuel-find-word ( name -- word/f )
14     { [ search ] [ '[ name>> _ = ] all-words swap find nip ] } 1|| ;
15
16 : fuel-value-str ( word -- str )
17     [ pprint-short ] with-string-writer ; inline
18
19 : fuel-definition-str ( word -- str )
20     [ see ] with-string-writer ; inline
21
22 : fuel-methods-str ( word -- str )
23     methods [ f ] [
24         [ [ see nl ] each ] with-string-writer
25     ] if-empty ; inline
26
27 : fuel-related-words ( word -- seq )
28     dup "related" word-prop remove ; inline
29
30 : fuel-parent-topics ( word -- seq )
31     help-path [ dup article-title swap 2array ] map ; inline
32
33 SYMBOLS: $doc-path $next-link $prev-link ;
34
35 : next/prev-link ( link link-symbol -- 3arr )
36     swap [ name>> ] [ [ link-long-text ] with-string-writer ] bi 3array ;
37
38 : (fuel-word-element) ( word -- element )
39     \ article swap dup article-title swap
40     [
41         {
42             [ \ $vocabulary swap vocabulary>> 2array , ]
43             [
44                 >link
45                 [ prev-article [ \ $prev-link next/prev-link , ] when* ]
46                 [ next-article [ \ $next-link next/prev-link , ] when* ] bi
47             ]
48             [ fuel-parent-topics [ \ $doc-path prefix , ] unless-empty ]
49             [ word-help % ]
50             [ fuel-related-words [ \ $related swap 2array , ] unless-empty ]
51             [ get-global [ \ $value swap fuel-value-str 2array , ] when* ]
52             [ \ $definition swap fuel-definition-str 2array , ]
53             [ fuel-methods-str [ \ $methods swap 2array , ] when* ]
54         } cleave
55     ] { } make 3array ;
56
57 : fuel-vocab-help-row ( vocab -- element )
58     [ vocab-name ] [ summary ] bi 2array ;
59
60 : fuel-vocab-help-root-heading ( root -- element )
61     [ "Children from " prepend ] [ "Other children" ] if* \ $heading swap 2array ;
62
63 SYMBOL: vocab-list
64 SYMBOL: describe-words
65
66 : fuel-vocab-help-table ( vocabs -- element )
67     [ fuel-vocab-help-row ] map vocab-list prefix ;
68
69 : fuel-vocab-list ( assoc -- seq )
70     [
71         [ drop f ] [
72             [ fuel-vocab-help-root-heading ]
73             [ fuel-vocab-help-table ] bi*
74             [ 2array ] [ drop f ] if*
75         ] if-empty
76     ] { } assoc>map sift ;
77
78 : fuel-vocab-children-help ( name -- element )
79     child-vocabs fuel-vocab-list ; inline
80
81 : fuel-vocab-describe-words ( name -- element )
82     [ words. ] with-string-writer \ describe-words swap 2array ; inline
83
84 : (fuel-vocab-element) ( name -- element )
85     dup require \ article swap dup >vocab-link
86     [
87         {
88             [ vocab-authors [ \ $authors prefix , ] when* ]
89             [ vocab-tags [ \ $tags prefix , ] when* ]
90             [ summary [ { $heading "Summary" } swap 2array , ] when* ]
91             [ drop \ $nl , ]
92             [ vocab-help [ lookup-article content>> % ] when* ]
93             [ name>> fuel-vocab-describe-words , ]
94             [ name>> fuel-vocab-children-help % ]
95         } cleave
96     ] { } make 3array ;
97
98 PRIVATE>
99
100 : (fuel-word-help) ( name -- elem )
101     fuel-find-word [
102         [ auto-use? on (fuel-word-element) ] with-scope
103     ] [ f ] if* ;
104
105 : (fuel-word-synopsis) ( word usings -- str/f )
106     [
107         [ lookup-vocab ] filter interactive-vocabs [ append ] change
108         fuel-find-word [ synopsis ] [ f ] if*
109     ] with-scope ;
110
111 : (fuel-word-def) ( name -- str )
112     fuel-find-word [ [ def>> pprint ] with-string-writer ] [ f ] if* ; inline
113
114 : (fuel-vocab-summary) ( name -- str ) >vocab-link summary ; inline
115
116 : (fuel-vocab-help) ( name -- str )
117     dup empty? [ fuel-vocab-children-help ] [ (fuel-vocab-element) ] if ;
118
119 : (fuel-get-vocabs/author) ( author -- element )
120     [ "Vocabularies by " prepend \ $heading swap 2array ]
121     [ authored fuel-vocab-list ] bi 2array ;
122
123 : (fuel-get-vocabs/tag) ( tag -- element )
124     [ "Vocabularies tagged " prepend \ $heading swap 2array ]
125     [ tagged fuel-vocab-list ] bi 2array ;
126
127 : format-index ( seq -- seq )
128     [ [ >link name>> ] [ article-title ] bi 2array \ $subsection prefix ] map ;