NB. J-WEB Some tools for generating HTML pages 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 environment variable QUERY_STRING query =: 3 : 0 if. 0 -: r =. getenv y. do. '' else. > ((<;. _2) &. >) ((, & '=') &. >) < ;. _2 r,'&' end. ) NB. Return value of 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. Perform Unix system call. system =: 2 !: 0 NB. An HTML page is defined to consist components of a header, y. (body) , trailer and footer. 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 header =: 0 : 0 Content-type: text/html Form Result header content
) footer =: 0 : 0 footer content
) trailer =: 0 : 0 trailer content
) page =: (header ; footer ; trailer) & page_helper NB. HTML generation functions NB. ht wrap HTML tag (x.) around y. NB. usage 'foo' ht 'tag' ==> foo NB. 'foo' ht 'tag';'options' ==> foo ht =: dyad define if. 32 = 3!:0 y. do. '<',(> 0{ y.),' ',(> 1{ y.),'>',x.,' 0{ y.),'>' else. '<',y.,'>',x.,'' end. )