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