tools.browser now uses io.monitor

db4
Slava Pestov 2008-02-05 18:55:10 -06:00
parent 551b3a42a1
commit 18403d15fa
5 changed files with 71 additions and 14 deletions

22
extra/tools/browser/browser-docs.factor Normal file → Executable file
View File

@ -2,16 +2,34 @@ USING: help.markup help.syntax io strings ;
IN: tools.browser IN: tools.browser
ARTICLE: "vocab-index" "Vocabulary index" ARTICLE: "vocab-index" "Vocabulary index"
{ $tags,authors } { $tags }
{ $authors }
{ $describe-vocab "" } ; { $describe-vocab "" } ;
ARTICLE: "tools.browser" "Vocabulary browser" ARTICLE: "tools.browser" "Vocabulary browser"
"Getting and setting vocabulary meta-data:" "Getting and setting vocabulary meta-data:"
{ $subsection vocab-file-contents }
{ $subsection set-vocab-file-contents }
{ $subsection vocab-summary } { $subsection vocab-summary }
{ $subsection set-vocab-summary } { $subsection set-vocab-summary }
{ $subsection vocab-tags } { $subsection vocab-tags }
{ $subsection set-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 HELP: vocab-summary
{ $values { "vocab" "a vocabulary specifier" } { "summary" "a string or " { $link f } } } { $values { "vocab" "a vocabulary specifier" } { "summary" "a string or " { $link f } } }

View File

@ -1,13 +1,30 @@
! Copyright (C) 2007 Slava Pestov. ! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: namespaces splitting sequences io.files kernel assocs USING: namespaces splitting sequences io.files kernel assocs
words vocabs vocabs.loader definitions parser continuations words vocabs vocabs.loader definitions parser continuations
inspector debugger io io.styles io.streams.lines hashtables inspector debugger io io.styles io.streams.lines hashtables
sorting prettyprint source-files arrays combinators strings sorting prettyprint source-files arrays combinators strings
system math.parser help.markup help.topics help.syntax system math.parser help.markup help.topics help.syntax
help.stylesheet ; help.stylesheet memoize ;
IN: tools.browser 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-summary-path ( vocab -- string )
vocab-dir "summary.txt" path+ ; vocab-dir "summary.txt" path+ ;
@ -86,7 +103,7 @@ M: vocab-link summary vocab-summary ;
dup [ "" vocabs-in-dir ] { } make dup [ "" vocabs-in-dir ] { } make
] { } map>assoc ; ] { } map>assoc ;
: all-vocabs-seq ( -- seq ) MEMO: all-vocabs-seq ( -- seq )
all-vocabs values concat ; all-vocabs values concat ;
: dangerous? ( name -- ? ) : dangerous? ( name -- ? )
@ -288,20 +305,20 @@ C: <vocab-author> vocab-author
: $tagged-vocabs ( element -- ) : $tagged-vocabs ( element -- )
first tagged vocabs. ; 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 -- ) : $authored-vocabs ( element -- )
first authored vocabs. ; 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 -- ) : $tags ( element -- )
drop drop "Tags" $heading all-tags tags. ;
all-vocabs-seq
"Tags" $heading : $authors ( element -- )
dup all-tags tags. drop "Authors" $heading all-authors authors. ;
"Authors" $heading
all-authors authors. ;
M: vocab-spec article-title vocab-name " vocabulary" append ; M: vocab-spec article-title vocab-name " vocabulary" append ;
@ -339,3 +356,9 @@ M: vocab-author article-content
M: vocab-author article-parent drop "vocab-index" ; M: vocab-author article-parent drop "vocab-index" ;
M: vocab-author summary article-title ; 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 ;

View File

@ -0,0 +1 @@
Slava Pestov

View File

@ -0,0 +1,14 @@
USING: threads io.files io.monitors init kernel tools.browser ;
IN: vocabs.monitor
! Use file system change monitoring to flush the tags/authors
! cache
: update-thread ( monitor -- )
dup next-change 2drop reset-cache update-thread ;
: start-update-thread
[
"" resource-path t <monitor> update-thread
] in-thread ;
[ start-update-thread ] "tools.browser" add-init-hook

View File

@ -0,0 +1 @@
Use io.monitors to clear tools.browser authors/tags/summary cache