]> gitweb.factorcode.org Git - factor.git/blob - extra/fuel/help/help.factor
Merge branch 'master' into experimental
[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 memoize
6 namespaces parser prettyprint sequences summary tools.vocabs
7 tools.vocabs.browser vocabs vocabs.loader words ;
8
9 IN: fuel.help
10
11 <PRIVATE
12
13 MEMO: 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 : (fuel-word-element) ( word -- element )
35     \ article swap dup article-title swap
36     [
37         {
38             [ fuel-parent-topics [ \ $doc-path prefix , ] unless-empty ]
39             [ \ $vocabulary swap vocabulary>> 2array , ]
40             [ word-help % ]
41             [ fuel-related-words [ \ $related swap 2array , ] unless-empty ]
42             [ get-global [ \ $value swap fuel-value-str 2array , ] when* ]
43             [ \ $definition swap fuel-definition-str 2array , ]
44             [ fuel-methods-str [ \ $methods swap 2array , ] when* ]
45         } cleave
46     ] { } make 3array ;
47
48 : fuel-vocab-help-row ( vocab -- element )
49     [ vocab-status-string ] [ vocab-name ] [ summary ] tri 3array ;
50
51 : fuel-vocab-help-root-heading ( root -- element )
52     [ "Children from " prepend ] [ "Other children" ] if* \ $heading swap 2array ;
53
54 SYMBOL: vocab-list
55
56 : fuel-vocab-help-table ( vocabs -- element )
57     [ fuel-vocab-help-row ] map vocab-list prefix ;
58
59 : fuel-vocab-list ( assoc -- seq )
60     [
61         [ drop f ] [
62             [ fuel-vocab-help-root-heading ]
63             [ fuel-vocab-help-table ] bi*
64             [ 2array ] [ drop f ] if*
65         ] if-empty
66     ] { } assoc>map [  ] filter ;
67
68 : fuel-vocab-children-help ( name -- element )
69     all-child-vocabs fuel-vocab-list ; inline
70
71 : fuel-vocab-describe-words ( name -- element )
72     [ describe-words ] with-string-writer \ describe-words swap 2array ; inline
73
74 : (fuel-vocab-element) ( name -- element )
75     dup require \ article swap dup >vocab-link
76     [
77         {
78             [ vocab-authors [ \ $authors prefix , ] when* ]
79             [ vocab-tags [ \ $tags prefix , ] when* ]
80             [ summary [ { $heading "Summary" } swap 2array , ] when* ]
81             [ drop \ $nl , ]
82             [ vocab-help [ article content>> % ] when* ]
83             [ name>> fuel-vocab-describe-words , ]
84             [ name>> fuel-vocab-children-help % ]
85         } cleave
86     ] { } make 3array ;
87
88 PRIVATE>
89
90 : (fuel-word-help) ( name -- elem )
91     fuel-find-word [ [ auto-use? on (fuel-word-element) ] with-scope ] [ f ] if* ;
92
93 : (fuel-word-see) ( word -- elem )
94     [ name>> \ article swap ]
95     [ [ see ] with-string-writer \ $code swap 2array ] bi 3array ; inline
96
97 : (fuel-word-def) ( name -- str )
98     fuel-find-word [ [ def>> pprint ] with-string-writer ] [ f ] if* ; inline
99
100 : (fuel-vocab-summary) ( name -- str ) >vocab-link summary ; inline
101
102 : (fuel-vocab-help) ( name -- str )
103     dup empty? [ fuel-vocab-children-help ] [ (fuel-vocab-element) ] if ;
104
105 MEMO: (fuel-get-vocabs/author) ( author -- element )
106     [ "Vocabularies by " prepend \ $heading swap 2array ]
107     [ authored fuel-vocab-list ] bi 2array ;
108
109 MEMO: (fuel-get-vocabs/tag) ( tag -- element )
110     [ "Vocabularies tagged " prepend \ $heading swap 2array ]
111     [ tagged fuel-vocab-list ] bi 2array ;
112
113 : format-index ( seq -- seq )
114     [ [ >link name>> ] [ article-title ] bi 2array \ $subsection prefix ] map ;