factor/extra/webapps/help/help.factor

86 lines
2.0 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2005, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel furnace furnace.validator http.server.responders
help help.topics html splitting sequences words strings
quotations macros vocabs tools.browser combinators
arrays io.files ;
IN: webapps.help
: show-help ( topic -- )
serving-html
dup article-title [
[ help ] with-html-stream
] simple-html-document ;
2007-09-20 18:09:08 -04:00
: string>topic ( string -- topic )
" " split dup length 1 = [ first ] when ;
\ show-help {
{ "topic" "handbook" v-default string>topic }
} define-action
M: link browser-link-href
2007-10-15 16:44:40 -04:00
link-name
dup word? over f eq? or [
2007-09-20 18:09:08 -04:00
browser-link-href
] [
dup array? [ " " join ] when
[ show-help ] curry quot-link
] if ;
: show-word ( word vocab -- )
lookup show-help ;
\ show-word {
{ "word" "call" v-default }
2007-10-15 16:44:40 -04:00
{ "vocab" "kernel" v-default }
2007-09-20 18:09:08 -04:00
} define-action
2007-10-15 16:44:40 -04:00
M: f browser-link-href
drop \ f browser-link-href ;
2007-09-20 18:09:08 -04:00
M: word browser-link-href
dup word-name swap word-vocabulary
[ show-word ] 2curry quot-link ;
: show-vocab ( vocab -- )
f >vocab-link show-help ;
\ show-vocab {
{ "vocab" "kernel" v-default }
} define-action
M: vocab-spec browser-link-href
vocab-name [ show-vocab ] curry quot-link ;
: show-vocabs-tagged ( tag -- )
<vocab-tag> show-help ;
\ show-vocabs-tagged {
{ "tag" }
} define-action
M: vocab-tag browser-link-href
vocab-tag-name [ show-vocabs-tagged ] curry quot-link ;
: show-vocabs-by ( author -- )
<vocab-author> show-help ;
\ show-vocabs-by {
{ "author" }
} define-action
M: vocab-author browser-link-href
vocab-author-name [ show-vocabs-by ] curry quot-link ;
"help" "show-help" "extra/webapps/help" web-app
! Hard-coding for factorcode.org
PREDICATE: pathname resource-pathname
pathname-string "resource:" head? ;
M: resource-pathname browser-link-href
pathname-string
"resource:" ?head drop
2007-12-06 01:20:26 -05:00
"/responder/source/" swap append ;