]> gitweb.factorcode.org Git - factor.git/blob - extra/webapps/help/help.factor
Merge branch 'master' into trees
[factor.git] / extra / webapps / help / help.factor
1 ! Copyright (C) 2005, 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel furnace furnace.validator http.server.responders
4        help help.topics html splitting sequences words strings 
5        quotations macros vocabs tools.browser combinators
6        arrays io.files ;
7 IN: webapps.help 
8
9 ! : string>topic ( string -- topic )
10     ! " " split dup length 1 = [ first ] when ;
11
12 : show-help ( topic -- )
13     serving-html
14     dup article-title [
15         [ help ] with-html-stream
16     ] simple-html-document ;
17
18 \ show-help {
19     { "topic" }
20 } define-action
21 \ show-help { { "topic" "handbook" } } default-values
22
23 M: link browser-link-href
24     link-name
25     dup word? over f eq? or [
26         browser-link-href
27     ] [
28         dup array? [ " " join ] when
29         [ show-help ] curry quot-link
30     ] if ;
31
32 : show-word ( word vocab -- )
33     lookup show-help ;
34
35 \ show-word {
36     { "word" }
37     { "vocab" }
38 } define-action
39 \ show-word { { "word" "call" } { "vocab" "kernel" } } default-values
40
41 M: f browser-link-href
42     drop \ f browser-link-href ;
43
44 M: word browser-link-href
45     dup word-name swap word-vocabulary
46     [ show-word ] 2curry quot-link ;
47
48 : show-vocab ( vocab -- )
49     f >vocab-link show-help ;
50
51 \ show-vocab {
52     { "vocab" }
53 } define-action
54
55 \ show-vocab { { "vocab" "kernel" } } default-values
56
57 M: vocab-spec browser-link-href
58     vocab-name [ show-vocab ] curry quot-link ;
59
60 : show-vocabs-tagged ( tag -- )
61     <vocab-tag> show-help ;
62
63 \ show-vocabs-tagged {
64     { "tag" }
65 } define-action
66
67 M: vocab-tag browser-link-href
68     vocab-tag-name [ show-vocabs-tagged ] curry quot-link ;
69
70 : show-vocabs-by ( author -- )
71     <vocab-author> show-help ;
72
73 \ show-vocabs-by {
74     { "author" }
75 } define-action
76
77 M: vocab-author browser-link-href
78     vocab-author-name [ show-vocabs-by ] curry quot-link ;
79
80 "help" "show-help" "extra/webapps/help" web-app
81
82 ! Hard-coding for factorcode.org
83 PREDICATE: pathname resource-pathname
84     pathname-string "resource:" head? ;
85
86 M: resource-pathname browser-link-href
87     pathname-string
88     "resource:" ?head drop
89     "/responder/source/" swap append ;