#!/usr/local/bin/jconsole NB. J-WEB Some tools for generating HTML pages NB. Support for legacy args 9!:49 [ 1 NB. When using CGI scripts, the form "get" method sets the environment variable NB. QUERY_STRING to indicate arguments passed to the CGI script. NB. & separates field-value pairs; = separates each field and value. NB. query NB. Build a boxed table of field-value pairs from the CGI environment variable QUERY_STRING query =: 3 : 0 if. 0 -: r =. getenv y. do. '' else. > ((<;. _2) &. >) ((, & '=') &. >) < ;. _2 r,'&' end. ) NB. get_field NB. Return the value of a named field. get_field_helper =: 4 : ' > 1 { ((, 1 {. " 1 x.) i. < ,y.) { x.' NB. field-value pairs are passed to get_field by Currying get_field_helper. get_field =: (query 'QUERY_STRING') & get_field_helper NB. system NB. Perform Unix system call. NB. system will provide all sorts of security issues if its NB. arguments are not carefully checked. system =: 2 !: 0 NB. An HTML page is defined to consist of components header, y. (body) , trailer and footer. NB. page NB. Output html page page_helper =: 4 : 0 stdout > 0 { x. stdout y. stdout > 1 { x. stdout > 2 { x. exit 0 ) NB. J db of HTML page components NB. These components are provided in stub form below for testing purposes. header =: 0 : 0 Content-type: text/html Form Result header content
) footer =: 0 : 0 footer content
) trailer =: 0 : 0 trailer content
) NB. page components (header, footer, trailer) are passed to page by Currying page_helper. page =: (header ; footer ; trailer) & page_helper NB. HTML generation functions NB. ht NB. wrap HTML tag (y.) around x. NB. usage 'tag' ht 'foo' ==> foo NB. ('tag';'options') ht 'foo' ==> foo ht =: dyad define if. 32 = 3!:0 x. do. '<',(> 0{ x.),' ',(> 1{ x.),'>',y.,' 0{ x.),'>' else. '<',x.,'>',y.,'' end. ) NB. par and others NB. by Currying ht par =: 'p' & ht pre =: 'pre' & ht li =: 'li' & ht list =: li &. > http =: 'http://' & , &. > NB. Test args url =: 'www.cs.trinity.edu';'www.trinity.edu';'www.jsoftware';'www.google.com' page > list http url