]> gitweb.factorcode.org Git - factor.git/blob - extra/webapps/help/help.factor
79c789ed02218eb891d3de54bbb78ee629f6397c
[factor.git] / extra / webapps / help / help.factor
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 ;
8 IN: webapps.help
9
10 TUPLE: help-webapp < dispatcher ;
11
12 : fixup-words ( title href -- title' href' )
13     dup "word-" head? [
14         dup ".html" ?tail drop "," split1-last nip dup ":" append
15         '[ " (" _ 3append ")" append _ ?head drop ] dip
16     ] when ;
17
18 : links ( apropos -- seq )
19     [ swap fixup-words <simple-link> ] { } assoc>map ;
20
21 : ?links ( has-links? apropos -- has-links? seq/f )
22     links [ f ] [ nip t swap ] if-empty ;
23
24 :: <search-action> ( help-dir -- action )
25     <page-action>
26         { help-webapp "search" } >>template
27         [
28             f "search" param [ unicode:blank? ] trim
29             dup "search" set-value [
30                 help-dir [
31                     [ article-apropos ?links "articles" set-value ]
32                     [ word-apropos ?links "words" set-value ]
33                     [ vocab-apropos ?links "vocabs" set-value ] tri
34                 ] with-directory
35             ] unless-empty not "empty" set-value
36             help-nav "nav" set-value
37
38             { help-webapp "search" } <chloe-content>
39         ] >>display
40     <boilerplate>
41         { help-webapp "help" } >>template ;
42
43 : help-url ( topic -- url )
44     topic>filename "$help-webapp/content/" prepend >url ;
45
46 : <main-action> ( -- action )
47     <action>
48         [ "handbook" >link help-url <redirect> ] >>display ;
49
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 ;
55
56 : run-help-webapp ( -- )
57     "docs" cache-file <help-webapp>
58         main-responder set-global
59     8080 httpd wait-for-server ;
60
61 MAIN: run-help-webapp