]> gitweb.factorcode.org Git - factor.git/blob - extra/webapps/help/help.factor
webapps.help: need boilerplate for t:style support
[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 locals namespaces sequences unicode urls ;
8 IN: webapps.help
9
10 TUPLE: help-webapp < dispatcher ;
11
12 : links ( seq -- seq' )
13     [ swap <simple-link> ] { } assoc>map ;
14
15 :: <search-action> ( help-dir -- action )
16     <page-action>
17         [
18             "search" param [ unicode:blank? ] trim [
19                 help-dir [
20                     [ article-apropos links "articles" set-value ]
21                     [ word-apropos links "words" set-value ]
22                     [ vocab-apropos links "vocabs" set-value ] tri
23                 ] with-directory
24             ] unless-empty
25             help-navbar "navbar" set-value
26
27             { help-webapp "search" } <chloe-content>
28         ] >>display
29     <boilerplatee>
30         { help-webapp "search" } >>template ;
31
32 : help-url ( topic -- url )
33     topic>filename "$help-webapp/content/" prepend >url ;
34
35 : <main-action> ( -- action )
36     <action>
37         [ "handbook" >link help-url <redirect> ] >>display ;
38
39 :: <help-webapp> ( help-dir -- webapp )
40     help-webapp new-dispatcher
41         <main-action> <secure-only> "" add-responder
42         help-dir <search-action> <secure-only> "search" add-responder
43         help-dir <static> <secure-only> "content" add-responder ;
44
45 : run-help-webapp ( -- )
46     "docs" cache-file <help-webapp>
47         main-responder set-global
48     8080 httpd wait-for-server ;
49
50 MAIN: run-help-webapp