factor/contrib/httpd/browser-responder.factor

68 lines
2.1 KiB
Factor
Raw Normal View History

2005-02-14 17:19:09 -05:00
! Copyright (C) 2004 Chris Double.
2006-06-15 01:21:16 -04:00
! See http://factorcode.org/license.txt for BSD license.
2005-02-14 17:19:09 -05:00
IN: browser-responder
2006-08-04 00:29:29 -04:00
USING: definitions hashtables help html httpd io kernel memory
namespaces prettyprint sequences words xml ;
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.
2006-06-15 01:21:16 -04:00
<option tuck = [ "yes" =selected ] when option>
chars>entities write
</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 "document.forms.main.submit()" =onchange select>
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 ( -- )
current-vocab vocabs "vocab" list ;
: word-list ( -- )
current-word [ word-name ] [ f ] if*
current-vocab vocab hash-keys natural-sort "word" list ;
: word-source ( -- )
#! Write the source for the given word from the vocab as HTML.
2006-06-17 03:51:06 -04:00
current-word [ [ see-help ] with-html-stream ] when* ;
2005-02-14 17:19:09 -05:00
2006-06-15 01:21:16 -04:00
: browser-body ( -- )
#! 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>
vocab-list
</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 ( -- str )
2006-06-15 01:21:16 -04:00
current-word
2006-08-25 21:29:23 -04:00
[ summary ] [ "IN: " current-vocab append ] if* ;
2005-02-14 17:19:09 -05:00
2005-08-08 02:42:39 -04:00
: browser-responder ( -- )
2006-06-15 01:21:16 -04:00
#! Display a Smalltalk like browser for exploring words.
serving-html browser-title [
2006-06-15 01:21:16 -04:00
<form "main" =name "" =action "get" =method form>
browser-body
</form>
] html-document ;