factor/contrib/furnace/tools/browser.factor

83 lines
2.4 KiB
Factor
Raw Normal View History

! Copyright (C) 2004 Chris Double
! Copyright (C) 2004, 2006 Slava Pestov
2006-06-15 01:21:16 -04:00
! See http://factorcode.org/license.txt for BSD license.
IN: furnace:browser
2006-08-04 00:29:29 -04:00
USING: definitions hashtables help html httpd io kernel memory
namespaces prettyprint sequences words xml furnace arrays ;
2005-08-08 02:42:39 -04:00
: option ( current text -- )
#! Output the HTML option tag for the given text. If
#! it is equal to the current string, make the option selected.
<option tuck = [ "selected" =selected ] when option>
write
2006-06-15 01:21:16 -04:00
</option> ;
2005-08-08 02:42:39 -04:00
2006-06-15 01:21:16 -04:00
: options ( current seq -- ) [ option ] each-with ;
2005-02-14 17:19:09 -05:00
2006-06-15 01:21:16 -04:00
: list ( current seq name -- )
<select =name "width: 200px;" =style "20" =size
"JavaScript:document.getElementById('main').submit();" =onchange
select>
2006-06-15 01:21:16 -04:00
options
</select> ;
2005-02-14 17:19:09 -05:00
2006-06-15 01:21:16 -04:00
: current-vocab ( -- string )
"vocab" query-param [ "kernel" ] unless* ;
: current-word ( -- word )
"word" query-param "vocab" query-param lookup ;
: vocab-list ( vocab -- ) vocabs "vocab" list ;
2006-06-15 01:21:16 -04:00
: word-list ( word vocab -- )
[ lookup [ word-name ] [ f ] if* ] keep
vocab hash-keys natural-sort "word" list ;
2006-06-15 01:21:16 -04:00
: word-source ( -- )
#! Write the source for the given word from the vocab as HTML.
current-word [ see-help ] when* ;
2005-02-14 17:19:09 -05:00
: browser-body ( word vocab -- )
#! Write out the HTML for the body of the main browser page.
<table "100%" =width table>
<tr>
2006-01-21 03:23:14 -05:00
<th> "Vocabularies" write </th>
<th> "Words" write </th>
<th> "Documentation" write </th>
</tr>
<tr>
2006-06-15 01:21:16 -04:00
<td "top" =valign "width: 200px;" =style td>
dup vocab-list
2006-06-15 01:21:16 -04:00
</td>
<td "top" =valign "width: 200px;" =style td>
word-list
</td>
<td "top" =valign td> word-source </td>
</tr>
</table> ;
2005-08-08 02:42:39 -04:00
: browser-title ( word vocab -- str )
2dup lookup dup
[ 2nip summary ] [ drop nip "IN: " swap append ] if ;
2005-02-14 17:19:09 -05:00
: browse ( word vocab -- )
2006-06-15 01:21:16 -04:00
#! Display a Smalltalk like browser for exploring words.
2dup browser-title [
[
<form "main" =id "browse" =action "get" =method form>
browser-body
</form>
] with-html-stream
2006-06-15 01:21:16 -04:00
] html-document ;
\ browse {
{ "word" }
{ "vocab" "kernel" v-default }
} define-action
"browser" "browse" "contrib/furnace" web-app
M: word browser-link-href
dup word-name swap word-vocabulary \ browse
3array >quotation quot-link ;