tools.browser now uses io.monitor
parent
551b3a42a1
commit
18403d15fa
|
@ -2,16 +2,34 @@ USING: help.markup help.syntax io strings ;
|
|||
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 } } }
|
||||
|
|
|
@ -1,13 +1,30 @@
|
|||
! 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+ ;
|
||||
|
||||
|
@ -86,7 +103,7 @@ M: vocab-link summary vocab-summary ;
|
|||
dup [ "" vocabs-in-dir ] { } make
|
||||
] { } map>assoc ;
|
||||
|
||||
: all-vocabs-seq ( -- seq )
|
||||
MEMO: all-vocabs-seq ( -- seq )
|
||||
all-vocabs values concat ;
|
||||
|
||||
: dangerous? ( name -- ? )
|
||||
|
@ -288,20 +305,20 @@ C: <vocab-author> vocab-author
|
|||
: $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 ;
|
||||
|
||||
|
@ -339,3 +356,9 @@ M: vocab-author article-content
|
|||
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 ;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Slava Pestov
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
Use io.monitors to clear tools.browser authors/tags/summary cache
|
Loading…
Reference in New Issue