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 splitting unicode urls ;
10 TUPLE: help-webapp < dispatcher ;
12 : fixup-words ( title href -- title' href' )
14 dup ".html" ?tail drop "," split1-last nip dup ":" append
15 '[ " (" _ 3append ")" append _ ?head drop ] dip
18 : links ( apropos -- seq )
19 [ swap fixup-words <simple-link> ] { } assoc>map ;
21 : ?links ( has-links? apropos -- has-links? seq/f )
22 links [ f ] [ nip t swap ] if-empty ;
24 :: <search-action> ( help-dir -- action )
26 { help-webapp "search" } >>template
28 f "search" param [ unicode:blank? ] trim
29 dup "search" set-value [
31 [ article-apropos ?links "articles" set-value ]
32 [ word-apropos ?links "words" set-value ]
33 [ vocab-apropos ?links "vocabs" set-value ] tri
35 ] unless-empty not "empty" set-value
36 help-nav "nav" set-value
38 { help-webapp "search" } <chloe-content>
41 { help-webapp "help" } >>template ;
43 : help-url ( topic -- url )
44 topic>filename "$help-webapp/content/" prepend >url ;
46 : <main-action> ( -- action )
48 [ "handbook" >link help-url <redirect> ] >>display ;
50 :: <help-webapp> ( help-dir -- webapp )
51 help-webapp new-dispatcher
52 <main-action> <secure-only> "" add-responder
53 help-dir <search-action> <secure-only> "search" add-responder
54 help-dir <static> <secure-only> "content" add-responder ;
56 : run-help-webapp ( -- )
57 "docs" cache-file <help-webapp>
58 main-responder set-global
59 8080 httpd wait-for-server ;