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 namespaces sequences unicode urls ;
10 TUPLE: help-webapp < dispatcher ;
12 : links ( apropos -- seq )
13 [ swap <simple-link> ] { } assoc>map ;
15 : ?links ( has-links? apropos -- has-links? seq )
16 links [ empty? not or ] keep ;
18 :: <search-action> ( help-dir -- action )
20 { help-webapp "search" } >>template
22 "search" param [ unicode:blank? ] trim [
24 [ article-apropos ?links "articles" set-value ]
25 [ word-apropos ?links "words" set-value ]
26 [ vocab-apropos ?links "vocabs" set-value ] tri
27 ] with-directory not "empty" set-value
29 help-navbar "navbar" set-value
31 { help-webapp "search" } <chloe-content>
34 { help-webapp "help" } >>template ;
36 : help-url ( topic -- url )
37 topic>filename "$help-webapp/content/" prepend >url ;
39 : <main-action> ( -- action )
41 [ "handbook" >link help-url <redirect> ] >>display ;
43 :: <help-webapp> ( help-dir -- webapp )
44 help-webapp new-dispatcher
45 <main-action> <secure-only> "" add-responder
46 help-dir <search-action> <secure-only> "search" add-responder
47 help-dir <static> <secure-only> "content" add-responder ;
49 : run-help-webapp ( -- )
50 "docs" cache-file <help-webapp>
51 main-responder set-global
52 8080 httpd wait-for-server ;