]> gitweb.factorcode.org Git - factor.git/blob - extra/webapps/help/help.factor
webapps.help: Load the navbar from a Factor word instead of hardcoding it into the...
[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             help-navbar "navbar" set-value
29
30             { help-webapp "search" } <chloe-content>
31         ] >>display ;
32
33 : help-url ( topic -- url )
34     topic>filename "$help-webapp/content/" prepend >url ;
35
36 : <main-action> ( -- action )
37     <action>
38         [ "handbook" >link help-url <redirect> ] >>display ;
39
40 :: <help-webapp> ( help-dir -- webapp )
41     help-webapp new-dispatcher
42         <main-action> "" add-responder
43         help-dir <search-action> "search" add-responder
44         help-dir <static> "content" add-responder
45         "resource:basis/definitions/icons/" <static> "icons" add-responder ;
46
47 : run-help-webapp ( -- )
48     "resource:temp/docs" <help-webapp>
49         main-responder set-global
50     8080 httpd drop ;
51
52 MAIN: run-help-webapp