1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel combinators vocabs vocabs.loader
4 tools.vocabs io io.files io.styles help.markup help.stylesheet
5 sequences assocs help.topics namespaces prettyprint words
6 sorting definitions arrays summary sets generic ;
7 IN: tools.vocabs.browser
9 : vocab-status-string ( vocab -- string )
11 { [ dup not ] [ drop "" ] }
12 { [ dup vocab-main ] [ drop "[Runnable]" ] }
16 : write-status ( vocab -- )
17 vocab vocab-status-string write ;
21 dup [ write-status ] with-cell
22 dup [ ($link) ] with-cell
23 [ vocab-summary write ] with-cell
26 : vocab-headings. ( -- )
28 [ "State" write ] with-cell
29 [ "Vocabulary" write ] with-cell
30 [ "Summary" write ] with-cell
33 : root-heading. ( root -- )
34 [ "Children from " prepend ] [ "Children" ] if*
37 : vocabs. ( assoc -- )
43 standard-table-style [
44 vocab-headings. [ vocab. ] each
49 : describe-summary ( vocab -- )
51 "Summary" $heading print-element
54 TUPLE: vocab-tag name ;
56 INSTANCE: vocab-tag topic
58 C: <vocab-tag> vocab-tag
60 : tags. ( seq -- ) [ <vocab-tag> ] map $links ;
62 : describe-tags ( vocab -- )
67 TUPLE: vocab-author name ;
69 INSTANCE: vocab-author topic
71 C: <vocab-author> vocab-author
73 : authors. ( seq -- ) [ <vocab-author> ] map $links ;
75 : describe-authors ( vocab -- )
76 vocab-authors f like [
77 "Authors" $heading authors.
80 : describe-help ( vocab -- )
82 "Documentation" $heading ($link)
85 : describe-children ( vocab -- )
86 vocab-name all-child-vocabs vocabs. ;
88 : describe-files ( vocab -- )
89 vocab-files [ <pathname> ] map [
100 : describe-words ( vocab -- )
106 : vocab-xref ( vocab quot -- vocabs )
107 >r dup vocab-name swap words [ generic? not ] filter r> map
108 [ [ word? ] filter [ vocabulary>> ] map ] gather natural-sort
111 : vocab-uses ( vocab -- vocabs ) [ uses ] vocab-xref ;
113 : vocab-usage ( vocab -- vocabs ) [ usage ] vocab-xref ;
115 : describe-uses ( vocab -- )
121 : describe-usage ( vocab -- )
127 : $describe-vocab ( element -- )
129 dup describe-children
130 dup find-vocab-root [
143 : keyed-vocabs ( str quot -- seq )
146 [ >r 2dup r> swap call member? ] filter
148 ] assoc-map 2nip ; inline
150 : tagged ( tag -- assoc )
151 [ vocab-tags ] keyed-vocabs ;
153 : authored ( author -- assoc )
154 [ vocab-authors ] keyed-vocabs ;
156 : $tagged-vocabs ( element -- )
157 first tagged vocabs. ;
159 : $authored-vocabs ( element -- )
160 first authored vocabs. ;
162 : $tags ( element -- )
163 drop "Tags" $heading all-tags tags. ;
165 : $authors ( element -- )
166 drop "Authors" $heading all-authors authors. ;
168 INSTANCE: vocab topic
170 INSTANCE: vocab-link topic
172 M: vocab-spec article-title vocab-name " vocabulary" append ;
174 M: vocab-spec article-name vocab-name ;
176 M: vocab-spec article-content
177 vocab-name \ $describe-vocab swap 2array ;
179 M: vocab-spec article-parent drop "vocab-index" ;
183 M: vocab-tag article-title
184 name>> "Vocabularies tagged ``" swap "''" 3append ;
186 M: vocab-tag article-name name>> ;
188 M: vocab-tag article-content
189 \ $tagged-vocabs swap name>> 2array ;
191 M: vocab-tag article-parent drop "vocab-index" ;
193 M: vocab-tag summary article-title ;
195 M: vocab-author >link ;
197 M: vocab-author article-title
198 name>> "Vocabularies by " prepend ;
200 M: vocab-author article-name name>> ;
202 M: vocab-author article-content
203 \ $authored-vocabs swap name>> 2array ;
205 M: vocab-author article-parent drop "vocab-index" ;
207 M: vocab-author summary article-title ;