]> gitweb.factorcode.org Git - factor.git/blob - extra/webapps/help/help.factor
webapps.help: whoops, caused it to search for ``f``
[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 unicode urls ;
8 IN: webapps.help
9
10 TUPLE: help-webapp < dispatcher ;
11
12 : links ( apropos -- seq )
13     [ swap <simple-link> ] { } assoc>map ;
14
15 : ?links ( has-links? apropos -- has-links? seq )
16     links [ empty? not or ] keep ;
17
18 :: <search-action> ( help-dir -- action )
19     <page-action>
20         { help-webapp "search" } >>template
21         [
22             "search" param [ unicode:blank? ] trim [
23                 f swap help-dir [
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
28             ] unless-empty
29             help-navbar "navbar" set-value
30
31             { help-webapp "search" } <chloe-content>
32         ] >>display
33     <boilerplate>
34         { help-webapp "help" } >>template ;
35
36 : help-url ( topic -- url )
37     topic>filename "$help-webapp/content/" prepend >url ;
38
39 : <main-action> ( -- action )
40     <action>
41         [ "handbook" >link help-url <redirect> ] >>display ;
42
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 ;
48
49 : run-help-webapp ( -- )
50     "docs" cache-file <help-webapp>
51         main-responder set-global
52     8080 httpd wait-for-server ;
53
54 MAIN: run-help-webapp