]> gitweb.factorcode.org Git - factor.git/commitdiff
tools.browser now uses io.monitor
authorSlava Pestov <slava@factorcode.org>
Wed, 6 Feb 2008 00:55:10 +0000 (18:55 -0600)
committerSlava Pestov <slava@factorcode.org>
Wed, 6 Feb 2008 00:55:10 +0000 (18:55 -0600)
extra/tools/browser/browser-docs.factor [changed mode: 0644->0755]
extra/tools/browser/browser.factor
extra/vocabs/monitor/authors.txt [new file with mode: 0644]
extra/vocabs/monitor/monitor.factor [new file with mode: 0755]
extra/vocabs/monitor/summary.txt [new file with mode: 0644]

old mode 100644 (file)
new mode 100755 (executable)
index db0e594..28bef58
@@ -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 } } }
index dabc37e5de1621486c538cbfa1697f7e2bbbcbab..7aefbc8aaa1a9cb59b7a0397c54b90bbbfdfd776 100755 (executable)
@@ -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 ;
diff --git a/extra/vocabs/monitor/authors.txt b/extra/vocabs/monitor/authors.txt
new file mode 100644 (file)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/extra/vocabs/monitor/monitor.factor b/extra/vocabs/monitor/monitor.factor
new file mode 100755 (executable)
index 0000000..24aa8b1
--- /dev/null
@@ -0,0 +1,14 @@
+USING: threads io.files io.monitors init kernel tools.browser ;\r
+IN: vocabs.monitor\r
+\r
+! Use file system change monitoring to flush the tags/authors\r
+! cache\r
+: update-thread ( monitor -- )\r
+    dup next-change 2drop reset-cache update-thread ;\r
+\r
+: start-update-thread\r
+    [\r
+        "" resource-path t <monitor> update-thread\r
+    ] in-thread ;\r
+\r
+[ start-update-thread ] "tools.browser" add-init-hook\r
diff --git a/extra/vocabs/monitor/summary.txt b/extra/vocabs/monitor/summary.txt
new file mode 100644 (file)
index 0000000..27c0d38
--- /dev/null
@@ -0,0 +1 @@
+Use io.monitors to clear tools.browser authors/tags/summary cache