2011-10-29 18:11:01 -04:00
|
|
|
! Copyright (C) 2008, 2011 Slava Pestov.
|
2008-06-06 19:57:37 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2014-09-25 15:37:46 -04:00
|
|
|
USING: accessors arrays assocs debugger fry help help.home
|
|
|
|
help.topics help.vocabs html html.streams io.directories
|
|
|
|
io.encodings.binary io.encodings.utf8 io.files io.files.temp
|
|
|
|
io.pathnames kernel make math.parser memoize namespaces
|
|
|
|
sequences serialize splitting tools.completion vocabs
|
|
|
|
vocabs.hierarchy words xml.syntax xml.writer ;
|
2009-05-16 17:54:02 -04:00
|
|
|
FROM: io.encodings.ascii => ascii ;
|
|
|
|
FROM: ascii => ascii? ;
|
2008-06-06 19:57:37 -04:00
|
|
|
IN: help.html
|
|
|
|
|
2011-12-04 16:46:13 -05:00
|
|
|
: escape-char ( ch -- )
|
|
|
|
dup ascii? [
|
|
|
|
dup H{
|
|
|
|
{ CHAR: " "__quo__" }
|
|
|
|
{ CHAR: * "__star__" }
|
|
|
|
{ CHAR: : "__colon__" }
|
|
|
|
{ CHAR: < "__lt__" }
|
|
|
|
{ CHAR: > "__gt__" }
|
|
|
|
{ CHAR: ? "__que__" }
|
|
|
|
{ CHAR: \\ "__back__" }
|
|
|
|
{ CHAR: | "__pipe__" }
|
|
|
|
{ CHAR: / "__slash__" }
|
|
|
|
{ CHAR: , "__comma__" }
|
|
|
|
{ CHAR: @ "__at__" }
|
|
|
|
{ CHAR: # "__hash__" }
|
|
|
|
{ CHAR: % "__percent__" }
|
|
|
|
} at [ % ] [ , ] ?if
|
|
|
|
] [ number>string "__" "__" surround % ] if ;
|
|
|
|
|
|
|
|
: escape-filename ( string -- filename )
|
|
|
|
[ [ escape-char ] each ] "" make ;
|
|
|
|
|
2008-09-29 05:10:20 -04:00
|
|
|
GENERIC: topic>filename* ( topic -- name prefix )
|
|
|
|
|
2008-09-29 20:43:59 -04:00
|
|
|
M: word topic>filename*
|
|
|
|
dup vocabulary>> [
|
|
|
|
[ name>> ] [ vocabulary>> ] bi 2array "word"
|
|
|
|
] [ drop f f ] if ;
|
|
|
|
|
|
|
|
M: link topic>filename* name>> dup [ "article" ] [ topic>filename* ] if ;
|
2008-09-29 05:10:20 -04:00
|
|
|
M: word-link topic>filename* name>> topic>filename* ;
|
|
|
|
M: vocab-spec topic>filename* vocab-name "vocab" ;
|
|
|
|
M: vocab-tag topic>filename* name>> "tag" ;
|
|
|
|
M: vocab-author topic>filename* name>> "author" ;
|
2008-09-29 20:43:59 -04:00
|
|
|
M: f topic>filename* drop \ f topic>filename* ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
|
|
|
: topic>filename ( topic -- filename )
|
2014-09-26 00:30:36 -04:00
|
|
|
topic>filename* [
|
2008-09-29 20:43:59 -04:00
|
|
|
[
|
|
|
|
% "-" %
|
2011-12-04 16:46:13 -05:00
|
|
|
dup array?
|
|
|
|
[ [ escape-filename ] map "," join ]
|
|
|
|
[ escape-filename ]
|
|
|
|
if % ".html" %
|
2008-09-29 20:43:59 -04:00
|
|
|
] "" make
|
2014-09-26 00:30:36 -04:00
|
|
|
] [ drop f ] if* ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
2009-01-31 21:44:30 -05:00
|
|
|
M: topic url-of topic>filename ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
2012-07-23 01:12:19 -04:00
|
|
|
M: pathname url-of
|
|
|
|
string>> "resource:" ?head [
|
|
|
|
"https://github.com/slavapestov/factor/blob/master/"
|
|
|
|
prepend
|
|
|
|
] [ drop f ] if ;
|
|
|
|
|
2011-10-14 01:09:30 -04:00
|
|
|
: help-stylesheet ( -- xml )
|
2009-02-15 20:53:21 -05:00
|
|
|
"vocab:help/html/stylesheet.css" ascii file-contents
|
2009-01-31 21:44:30 -05:00
|
|
|
[XML <style><-></style> XML] ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
2011-10-14 01:09:30 -04:00
|
|
|
: help-navbar ( -- xml )
|
2011-11-05 03:05:58 -04:00
|
|
|
"conventions" >link topic>filename
|
2011-10-14 01:09:30 -04:00
|
|
|
[XML
|
|
|
|
<div class="navbar">
|
|
|
|
<b> Factor Documentation </b> |
|
|
|
|
<a href="/">Home</a> |
|
2011-11-05 03:05:58 -04:00
|
|
|
<a href=<->>Glossary</a> |
|
2011-10-29 18:11:01 -04:00
|
|
|
<form method="get" action="/search" style="display:inline;">
|
2011-10-14 01:09:30 -04:00
|
|
|
<input name="search" type="text"/>
|
|
|
|
<button type="submit">Search</button>
|
|
|
|
</form>
|
|
|
|
<a href="http://factorcode.org" style="float:right; padding: 4px;">factorcode.org</a>
|
|
|
|
</div>
|
|
|
|
XML] ;
|
|
|
|
|
2009-01-31 21:44:30 -05:00
|
|
|
: help>html ( topic -- xml )
|
2011-10-14 01:09:30 -04:00
|
|
|
[ article-title " - Factor Documentation" append ]
|
2009-01-31 21:44:30 -05:00
|
|
|
[ drop help-stylesheet ]
|
2011-10-29 18:11:01 -04:00
|
|
|
[
|
|
|
|
[ help-navbar ]
|
|
|
|
[ [ print-topic ] with-html-writer ]
|
|
|
|
bi* append
|
|
|
|
] tri
|
|
|
|
simple-page ;
|
2011-09-29 15:10:27 -04:00
|
|
|
|
2009-01-31 21:44:30 -05:00
|
|
|
: generate-help-file ( topic -- )
|
|
|
|
dup topic>filename utf8 [ help>html write-xml ] with-file-writer ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
2009-07-06 05:35:00 -04:00
|
|
|
: all-vocabs-really ( -- seq )
|
2015-06-08 15:02:25 -04:00
|
|
|
all-disk-vocabs-recursive no-roots remove-redundant-prefixes
|
2015-05-12 21:50:34 -04:00
|
|
|
[ vocab-name "scratchpad" = ] reject ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
|
|
|
: all-topics ( -- topics )
|
|
|
|
[
|
2008-09-29 05:23:42 -04:00
|
|
|
articles get keys [ >link ] map %
|
|
|
|
all-words [ >link ] map %
|
|
|
|
all-authors [ <vocab-author> ] map %
|
2008-09-29 05:10:20 -04:00
|
|
|
all-tags [ <vocab-tag> ] map %
|
2008-09-29 05:23:42 -04:00
|
|
|
all-vocabs-really %
|
2008-09-29 05:10:20 -04:00
|
|
|
] { } make ;
|
|
|
|
|
|
|
|
: serialize-index ( index file -- )
|
2014-09-26 00:30:36 -04:00
|
|
|
binary [
|
|
|
|
[ [ topic>filename ] dip ] { } assoc-map-as serialize
|
|
|
|
] with-file-writer ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
2014-09-26 00:30:36 -04:00
|
|
|
: generate-article-index ( -- )
|
|
|
|
articles get [ [ >link ] [ article-title ] bi* ] assoc-map
|
|
|
|
"articles.idx" serialize-index ;
|
|
|
|
|
|
|
|
: generate-word-index ( -- )
|
|
|
|
all-words [ dup name>> ] { } map>assoc
|
|
|
|
"words.idx" serialize-index ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
2014-09-26 00:30:36 -04:00
|
|
|
: generate-vocab-index ( -- )
|
|
|
|
all-vocabs-really [ dup vocab-name ] { } map>assoc
|
|
|
|
"vocabs.idx" serialize-index ;
|
|
|
|
|
|
|
|
: generate-indices ( -- )
|
|
|
|
generate-article-index
|
|
|
|
generate-word-index
|
|
|
|
generate-vocab-index ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
2011-09-29 15:10:27 -04:00
|
|
|
: generate-help-files ( -- )
|
2012-07-19 16:55:34 -04:00
|
|
|
H{
|
|
|
|
{ recent-searches f }
|
|
|
|
{ recent-words f }
|
|
|
|
{ recent-articles f }
|
|
|
|
{ recent-vocabs f }
|
2014-09-26 00:30:36 -04:00
|
|
|
} [
|
|
|
|
all-topics [ '[ _ generate-help-file ] try ] each
|
|
|
|
] with-variables ;
|
2011-09-29 15:10:27 -04:00
|
|
|
|
2008-09-29 05:23:42 -04:00
|
|
|
: generate-help ( -- )
|
2012-03-31 17:49:43 -04:00
|
|
|
"docs" cache-file
|
2008-11-16 12:29:35 -05:00
|
|
|
[ make-directories ]
|
|
|
|
[
|
|
|
|
[
|
2008-09-29 05:23:42 -04:00
|
|
|
generate-indices
|
|
|
|
generate-help-files
|
|
|
|
] with-directory
|
2008-11-16 12:29:35 -05:00
|
|
|
] bi ;
|
2008-09-29 05:23:42 -04:00
|
|
|
|
2008-09-29 05:10:20 -04:00
|
|
|
MEMO: load-index ( name -- index )
|
|
|
|
binary file-contents bytes>object ;
|
|
|
|
|
|
|
|
: offline-apropos ( string index -- results )
|
2014-09-25 15:37:46 -04:00
|
|
|
load-index completions ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
|
|
|
: article-apropos ( string -- results )
|
2008-11-17 18:30:47 -05:00
|
|
|
"articles.idx" offline-apropos ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
|
|
|
: word-apropos ( string -- results )
|
2008-11-17 18:30:47 -05:00
|
|
|
"words.idx" offline-apropos ;
|
2008-09-29 05:10:20 -04:00
|
|
|
|
|
|
|
: vocab-apropos ( string -- results )
|
2008-11-17 18:30:47 -05:00
|
|
|
"vocabs.idx" offline-apropos ;
|