1 ! Copyright (C) 2009 Jose Antonio Ortega Ruiz.
2 ! See http://factorcode.org/license.txt for BSD license.
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 ;
13 MEMO: fuel-find-word ( name -- word/f )
14 [ [ name>> ] dip = ] curry all-words swap filter
15 dup empty? not [ first ] [ drop f ] if ;
17 : fuel-value-str ( word -- str )
18 [ pprint-short ] with-string-writer ; inline
20 : fuel-definition-str ( word -- str )
21 [ see ] with-string-writer ; inline
23 : fuel-methods-str ( word -- str )
24 methods dup empty? not [
25 [ [ see nl ] each ] with-string-writer
26 ] [ drop f ] if ; inline
28 : fuel-related-words ( word -- seq )
29 dup "related" word-prop remove ; inline
31 : fuel-parent-topics ( word -- seq )
32 help-path [ dup article-title swap 2array ] map ; inline
34 : (fuel-word-element) ( word -- element )
35 \ article swap dup article-title swap
38 [ fuel-parent-topics [ \ $doc-path prefix , ] unless-empty ]
39 [ \ $vocabulary swap vocabulary>> 2array , ]
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* ]
48 : fuel-vocab-help-row ( vocab -- element )
49 [ vocab-status-string ] [ vocab-name ] [ summary ] tri 3array ;
51 : fuel-vocab-help-root-heading ( root -- element )
52 [ "Children from " prepend ] [ "Other children" ] if* \ $heading swap 2array ;
56 : fuel-vocab-help-table ( vocabs -- element )
57 [ fuel-vocab-help-row ] map vocab-list prefix ;
59 : fuel-vocab-list ( assoc -- seq )
62 [ fuel-vocab-help-root-heading ]
63 [ fuel-vocab-help-table ] bi*
64 [ 2array ] [ drop f ] if*
66 ] { } assoc>map [ ] filter ;
68 : fuel-vocab-children-help ( name -- element )
69 all-child-vocabs fuel-vocab-list ; inline
71 : fuel-vocab-describe-words ( name -- element )
72 [ describe-words ] with-string-writer \ describe-words swap 2array ; inline
74 : (fuel-vocab-element) ( name -- element )
75 dup require \ article swap dup >vocab-link
78 [ vocab-authors [ \ $authors prefix , ] when* ]
79 [ vocab-tags [ \ $tags prefix , ] when* ]
80 [ summary [ { $heading "Summary" } swap 2array , ] when* ]
82 [ vocab-help [ article content>> % ] when* ]
83 [ name>> fuel-vocab-describe-words , ]
84 [ name>> fuel-vocab-children-help % ]
90 : (fuel-word-help) ( name -- elem )
91 fuel-find-word [ [ auto-use? on (fuel-word-element) ] with-scope ] [ f ] if* ;
93 : (fuel-word-see) ( word -- elem )
94 [ name>> \ article swap ]
95 [ [ see ] with-string-writer \ $code swap 2array ] bi 3array ; inline
97 : (fuel-word-def) ( name -- str )
98 fuel-find-word [ [ def>> pprint ] with-string-writer ] [ f ] if* ; inline
100 : (fuel-vocab-summary) ( name -- str ) >vocab-link summary ; inline
102 : (fuel-vocab-help) ( name -- str )
103 dup empty? [ fuel-vocab-children-help ] [ (fuel-vocab-element) ] if ;
105 MEMO: (fuel-get-vocabs/author) ( author -- element )
106 [ "Vocabularies by " prepend \ $heading swap 2array ]
107 [ authored fuel-vocab-list ] bi 2array ;
109 MEMO: (fuel-get-vocabs/tag) ( tag -- element )
110 [ "Vocabularies tagged " prepend \ $heading swap 2array ]
111 [ tagged fuel-vocab-list ] bi 2array ;
113 : format-index ( seq -- seq )
114 [ [ >link name>> ] [ article-title ] bi 2array \ $subsection prefix ] map ;