1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs furnace.actions furnace.boilerplate
4 furnace.redirection help.html help.topics html.components
5 html.forms http.server http.server.dispatchers
6 http.server.static io.directories io.files.temp io.servers
7 kernel locals namespaces sequences unicode urls ;
10 TUPLE: help-webapp < dispatcher ;
12 : links ( seq -- seq' )
13 [ swap "content/" prepend <simple-link> ] { } assoc>map ;
15 :: <search-action> ( help-dir -- action )
17 { help-webapp "search" } >>template
19 "search" param [ unicode:blank? ] trim [
21 [ article-apropos links "articles" set-value ]
22 [ word-apropos links "words" set-value ]
23 [ vocab-apropos links "vocabs" set-value ] tri
26 help-navbar "navbar" set-value
28 { help-webapp "search" } <chloe-content>
31 { help-webapp "help" } >>template ;
33 : help-url ( topic -- url )
34 topic>filename "$help-webapp/content/" prepend >url ;
36 : <main-action> ( -- action )
38 [ "handbook" >link help-url <redirect> ] >>display ;
40 :: <help-webapp> ( help-dir -- webapp )
41 help-webapp new-dispatcher
42 <main-action> <secure-only> "" add-responder
43 help-dir <search-action> <secure-only> "search" add-responder
44 help-dir <static> <secure-only> "content" add-responder ;
46 : run-help-webapp ( -- )
47 "docs" cache-file <help-webapp>
48 main-responder set-global
49 8080 httpd wait-for-server ;