]> 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 : show-help ( topic -- )
10     serving-html
11     dup article-title [
12         [ help ] with-html-stream
13     ] simple-html-document ;
14
15 : string>topic ( string -- topic )
16     " " split dup length 1 = [ first ] when ;
17
18 \ show-help {
19     { "topic" "handbook" v-default string>topic }
20 } define-action
21
22 M: link browser-link-href
23     link-name
24     dup word? over f eq? or [
25         browser-link-href
26     ] [
27         dup array? [ " " join ] when
28         [ show-help ] curry quot-link
29     ] if ;
30
31 : show-word ( word vocab -- )
32     lookup show-help ;
33
34 \ show-word {
35     { "word" "call" v-default }
36     { "vocab" "kernel" v-default }
37 } define-action
38
39 M: f browser-link-href
40     drop \ f browser-link-href ;
41
42 M: word browser-link-href
43     dup word-name swap word-vocabulary
44     [ show-word ] 2curry quot-link ;
45
46 : show-vocab ( vocab -- )
47     f >vocab-link show-help ;
48
49 \ show-vocab {
50     { "vocab" "kernel" v-default }
51 } define-action
52
53 M: vocab-spec browser-link-href
54     vocab-name [ show-vocab ] curry quot-link ;
55
56 : show-vocabs-tagged ( tag -- )
57     <vocab-tag> show-help ;
58
59 \ show-vocabs-tagged {
60     { "tag" }
61 } define-action
62
63 M: vocab-tag browser-link-href
64     vocab-tag-name [ show-vocabs-tagged ] curry quot-link ;
65
66 : show-vocabs-by ( author -- )
67     <vocab-author> show-help ;
68
69 \ show-vocabs-by {
70     { "author" }
71 } define-action
72
73 M: vocab-author browser-link-href
74     vocab-author-name [ show-vocabs-by ] curry quot-link ;
75
76 "help" "show-help" "extra/webapps/help" web-app
77
78 ! Hard-coding for factorcode.org
79 PREDICATE: pathname resource-pathname
80     pathname-string "resource:" head? ;
81
82 M: resource-pathname browser-link-href
83     pathname-string
84     "resource:" ?head drop
85     "/responder/source/" swap append ;