]> gitweb.factorcode.org Git - factor.git/blob - extra/webapps/help/help.factor
webapps.help: Change webapps.help search from post to get. Fixes #343.
[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 db.sqlite furnace.actions furnace.alloy
4 furnace.redirection help.html help.topics html.components
5 html.forms html.templates.chloe http.server
6 http.server.dispatchers http.server.static io.directories
7 io.files kernel locals namespaces sequences unicode.categories
8 urls ;
9 IN: webapps.help
10
11 TUPLE: help-webapp < dispatcher ;
12
13 M: result link-title title>> ;
14
15 M: result link-href href>> ;
16
17 :: <search-action> ( help-dir -- action )
18     <page-action>
19         { help-webapp "search" } >>template
20         [
21             "search" param [ blank? ] trim [
22                 help-dir [
23                     [ article-apropos "articles" set-value ]
24                     [ word-apropos "words" set-value ]
25                     [ vocab-apropos "vocabs" set-value ] tri
26                 ] with-directory
27             ] unless-empty
28
29             { help-webapp "search" } <chloe-content>
30         ] >>display ;
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> "" add-responder
42         help-dir <search-action> "search" add-responder
43         help-dir <static> "content" add-responder
44         "resource:basis/definitions/icons/" <static> "icons" add-responder ;
45
46 : run-help-webapp ( -- )
47     "resource:temp/docs" <help-webapp>
48         main-responder set-global
49     8080 httpd drop ;
50
51 MAIN: run-help-webapp