IN: tools.browser
ARTICLE: "vocab-index" "Vocabulary index"
-{ $tags,authors }
+{ $tags }
+{ $authors }
{ $describe-vocab "" } ;
ARTICLE: "tools.browser" "Vocabulary browser"
"Getting and setting vocabulary meta-data:"
+{ $subsection vocab-file-contents }
+{ $subsection set-vocab-file-contents }
{ $subsection vocab-summary }
{ $subsection set-vocab-summary }
{ $subsection vocab-tags }
{ $subsection set-vocab-tags }
-{ $subsection add-vocab-tags } ;
+{ $subsection add-vocab-tags }
+"Global meta-data:"
+{ $subsection all-vocabs }
+{ $subsection all-vocabs-seq }
+{ $subsection all-tags }
+{ $subsection all-authors }
+"Because loading the above data is expensive, it is cached. The cache is flushed by the " { $vocab-link "vocabs.monitor" } " vocabulary. It can also be flushed manually when file system change monitors are not available:"
+{ $subsection reset-cache } ;
+
+HELP: vocab-file-contents
+{ $values { "vocab" "a vocabulary specifier" } { "name" string } { "seq" "a sequence of lines, or " { $link f } } }
+{ $description "Outputs the contents of the file named " { $snippet "name" } " from the vocabulary's directory, or " { $link f } " if the file does not exist." } ;
+
+HELP: set-vocab-file-contents
+{ $values { "seq" "a sequence of lines" } { "vocab" "a vocabulary specifier" } { "name" string } }
+{ $description "Stores a sequence of lines to the file named " { $snippet "name" } " from the vocabulary's directory." } ;
HELP: vocab-summary
{ $values { "vocab" "a vocabulary specifier" } { "summary" "a string or " { $link f } } }
-! Copyright (C) 2007 Slava Pestov.
+! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces splitting sequences io.files kernel assocs
words vocabs vocabs.loader definitions parser continuations
inspector debugger io io.styles io.streams.lines hashtables
sorting prettyprint source-files arrays combinators strings
system math.parser help.markup help.topics help.syntax
-help.stylesheet ;
+help.stylesheet memoize ;
IN: tools.browser
+MEMO: (vocab-file-contents) ( path -- lines )
+ ?resource-path dup exists?
+ [ <file-reader> lines ] [ drop f ] if ;
+
+: vocab-file-contents ( vocab name -- seq )
+ vocab-path+ dup [ (vocab-file-contents) ] when ;
+
+: set-vocab-file-contents ( seq vocab name -- )
+ dupd vocab-path+ [
+ ?resource-path
+ <file-writer> [ [ print ] each ] with-stream
+ ] [
+ "The " swap vocab-name
+ " vocabulary was not loaded from the file system"
+ 3append throw
+ ] ?if ;
+
: vocab-summary-path ( vocab -- string )
vocab-dir "summary.txt" path+ ;
dup [ "" vocabs-in-dir ] { } make
] { } map>assoc ;
-: all-vocabs-seq ( -- seq )
+MEMO: all-vocabs-seq ( -- seq )
all-vocabs values concat ;
: dangerous? ( name -- ? )
: $tagged-vocabs ( element -- )
first tagged vocabs. ;
-: all-tags ( vocabs -- seq ) [ vocab-tags ] map>set ;
+MEMO: all-tags ( -- seq )
+ all-vocabs-seq [ vocab-tags ] map>set ;
: $authored-vocabs ( element -- )
first authored vocabs. ;
-: all-authors ( vocabs -- seq ) [ vocab-authors ] map>set ;
+MEMO: all-authors ( -- seq )
+ all-vocabs-seq [ vocab-authors ] map>set ;
-: $tags,authors ( element -- )
- drop
- all-vocabs-seq
- "Tags" $heading
- dup all-tags tags.
- "Authors" $heading
- all-authors authors. ;
+: $tags ( element -- )
+ drop "Tags" $heading all-tags tags. ;
+
+: $authors ( element -- )
+ drop "Authors" $heading all-authors authors. ;
M: vocab-spec article-title vocab-name " vocabulary" append ;
M: vocab-author article-parent drop "vocab-index" ;
M: vocab-author summary article-title ;
+
+: reset-cache ( -- )
+ \ (vocab-file-contents) reset-memoized
+ \ all-vocabs-seq reset-memoized
+ \ all-authors reset-memoized
+ \ all-tags reset-memoized ;