Index: xotcl/library/lib/htmllib.xotcl =================================================================== diff -u -rf7894d9be99a8da3a04218abcdb9bd46b6d625c8 -r435b41481fb51bf000ebe736d8574fefbeec1710 --- xotcl/library/lib/htmllib.xotcl (.../htmllib.xotcl) (revision f7894d9be99a8da3a04218abcdb9bd46b6d625c8) +++ xotcl/library/lib/htmllib.xotcl (.../htmllib.xotcl) (revision 435b41481fb51bf000ebe736d8574fefbeec1710) @@ -1,4 +1,4 @@ -## $Header: /home/neumann/cvs/xotcl/xotcl/library/lib/htmllib.xotcl,v 1.1 2004/05/23 22:50:39 neumann Exp $ +## $Header: /home/neumann/cvs/xotcl/xotcl/library/lib/htmllib.xotcl,v 1.2 2005/09/09 21:07:23 neumann Exp $ # # htmllib.xotcl @@ -36,636 +36,642 @@ # package provide xotcl::htmllib 0.1 - package require XOTcl +namespace eval ::xotcl::htmllib { + namespace import ::xotcl::* -@ @File { - description { - This package provides the class HtmlBuilder, which can be used to - generate HTML documents, or a part of a document. + @ @File { + description { + This package provides the class HtmlBuilder, which can be used to + generate HTML documents, or a part of a document. + } + authors { + Antti Salonen, as@fishpool.fi + } + date { + $Date: 2005/09/09 21:07:23 $ + } } - authors { - Antti Salonen, as@fishpool.fi + + # + # the compressed parameter means that minimal HTML page are created + # i.e. that space indentation is turned off + # + Class HtmlBuilder -parameter { + {compressed 0} } - date { - $Date: 2004/05/23 22:50:39 $ - } -} - -# -# the compressed parameter means that minimal HTML page are created -# i.e. that space indentation is turned off -# -Class HtmlBuilder -parameter { - {compressed 0} -} -## The constructor. -## -## The HtmlBuilder object has two instance variables. The document Tcl list -## contains the document as a list of strings. The document is stored as a list -## rather than a single string to allow further indentation of the whole -## document when necessary. -## The indentLevel variable is the level of indentation, which is generally -## increased for the contents of any HTML element that may contain block-level -## elements. Typical examples would be } + return + } -## startListItem - start an LI element -## Optional arguments: -## Common HTML arguments + ## startListItem - start an LI element + ## Optional arguments: + ## Common HTML arguments -HtmlBuilder instproc startListItem {args} { - set attributes [HtmlBuilder parseArguments $args [list] [list]] - my addStringIncr "" - return -} + HtmlBuilder instproc startListItem {args} { + set attributes [HtmlBuilder parseArguments $args [list] [list]] + my addStringIncr "" + return + } -## endListItem - end an LI element + ## endListItem - end an LI element -HtmlBuilder instproc endListItem {} { - my addStringDecr {} - return -} + HtmlBuilder instproc endListItem {} { + my addStringDecr {} + return + } -## add a simple list item -HtmlBuilder instproc addListItem {content} { - my startListItem - my addString $content - my endListItem -} + ## add a simple list item + HtmlBuilder instproc addListItem {content} { + my startListItem + my addString $content + my endListItem + } -## startTable - start a TABLE element. Note that if the -border argument isn't -## used, by default the table are created with borders (). + ## startTable - start a TABLE element. Note that if the -border argument isn't + ## used, by default the table are created with borders (
). -## Optional arguments: -## -border pixels -## -cellpadding length -## -cellspacing length -## -summary text -## -width length -## -bgcolor color spec -## Common HTML arguments + ## Optional arguments: + ## -border pixels + ## -cellpadding length + ## -cellspacing length + ## -summary text + ## -width length + ## -bgcolor color spec + ## Common HTML arguments -HtmlBuilder instproc startTable {args} { - set attributes [HtmlBuilder parseArguments $args \ - [list "BORDER" "CELLPADDING" "CELLSPACING" "SUMMARY" \ - "WIDTH" "BGCOLOR"] [list]] - if {[lsearch $args "-border"] == -1} { - append attributes " BORDER" + HtmlBuilder instproc startTable {args} { + set attributes [HtmlBuilder parseArguments $args \ + [list "BORDER" "CELLPADDING" "CELLSPACING" "SUMMARY" \ + "WIDTH" "BGCOLOR"] [list]] + if {[lsearch $args "-border"] == -1} { + append attributes " BORDER" + } + my addStringIncr "" + return } - my addStringIncr "" - return -} -## endTable - end a TABLE element + ## endTable - end a TABLE element -HtmlBuilder instproc endTable {} { - my addStringDecr {
} - return -} + HtmlBuilder instproc endTable {} { + my addStringDecr {} + return + } -## startTableRow - start a TR element -## Optional arguments: -## Common HTML arguments -HtmlBuilder instproc startTableRow {args} { - set attributes [HtmlBuilder parseArguments $args [list "VALIGN"] [list]] - my addStringIncr "" - return -} + ## startTableRow - start a TR element + ## Optional arguments: + ## Common HTML arguments + HtmlBuilder instproc startTableRow {args} { + set attributes [HtmlBuilder parseArguments $args [list "VALIGN"] [list]] + my addStringIncr "" + return + } -## endTableRow - end a TR element + ## endTableRow - end a TR element -HtmlBuilder instproc endTableRow {} { - my addStringDecr {} - return -} + HtmlBuilder instproc endTableRow {} { + my addStringDecr {} + return + } -## startTableCell - start a TD element -## Optional arguments: -## -colspan number -## -rowspan number -## -align left|center|right|justify|char -## -valign top|middle|bottom|baseline -## -bgcolor -## -width -## Common HTML arguments + ## startTableCell - start a TD element + ## Optional arguments: + ## -colspan number + ## -rowspan number + ## -align left|center|right|justify|char + ## -valign top|middle|bottom|baseline + ## -bgcolor + ## -width + ## Common HTML arguments -HtmlBuilder instproc startTableCell {args} { - set attributes [HtmlBuilder parseArguments $args \ - [list "COLSPAN" "ROWSPAN" "ALIGN" "VALIGN" \ - "BGCOLOR" "WIDTH"] [list]] - my addStringIncr "" - return -} + HtmlBuilder instproc startTableCell {args} { + set attributes [HtmlBuilder parseArguments $args \ + [list "COLSPAN" "ROWSPAN" "ALIGN" "VALIGN" \ + "BGCOLOR" "WIDTH"] [list]] + my addStringIncr "" + return + } -## endTableCell - end a TD element + ## endTableCell - end a TD element -HtmlBuilder instproc endTableCell {} { - my addStringDecr {} - return -} + HtmlBuilder instproc endTableCell {} { + my addStringDecr {} + return + } -# -# add a simple table cell which just contains a string -# -HtmlBuilder instproc addTableCell {{string ""} args} { - eval my startTableCell $args - my addString $string - my endTableCell -} + # + # add a simple table cell which just contains a string + # + HtmlBuilder instproc addTableCell {{string ""} args} { + eval my startTableCell $args + my addString $string + my endTableCell + } -## startTableHeaderCell - start a TH element -## Optional arguments: -## -colspan number -## -rowspan number -## -align left|center|right|justify|char -## -valign top|middle|bottom|baseline -## Common HTML arguments + ## startTableHeaderCell - start a TH element + ## Optional arguments: + ## -colspan number + ## -rowspan number + ## -align left|center|right|justify|char + ## -valign top|middle|bottom|baseline + ## Common HTML arguments -HtmlBuilder instproc startTableHeaderCell {args} { - set attributes [HtmlBuilder parseArguments $args \ - [list "COLSPAN" "ROWSPAN" "ALIGN" "VALIGN"] [list]] - my addStringIncr "" - return -} + HtmlBuilder instproc startTableHeaderCell {args} { + set attributes [HtmlBuilder parseArguments $args \ + [list "COLSPAN" "ROWSPAN" "ALIGN" "VALIGN"] [list]] + my addStringIncr "" + return + } -## endTableHeaderCell - end a TH element + ## endTableHeaderCell - end a TH element -HtmlBuilder instproc endTableHeaderCell {} { - my addStringDecr {} - return -} + HtmlBuilder instproc endTableHeaderCell {} { + my addStringDecr {} + return + } -## startForm - start a FORM element -## Required arguments: -## -action URI -## Optional arguments: -## -method get|post -## Common HTML arguments + ## startForm - start a FORM element + ## Required arguments: + ## -action URI + ## Optional arguments: + ## -method get|post + ## Common HTML arguments -HtmlBuilder instproc startForm {args} { - set attributes [HtmlBuilder parseArguments $args \ - [list "ACTION" "METHOD" "ENCTYPE"] [list]] - my addStringIncr "" - return -} + HtmlBuilder instproc startForm {args} { + set attributes [HtmlBuilder parseArguments $args \ + [list "ACTION" "METHOD" "ENCTYPE"] [list]] + my addStringIncr "" + return + } -## endForm - end a FORM element + ## endForm - end a FORM element -HtmlBuilder instproc endForm {} { - my addStringDecr {} - return -} + HtmlBuilder instproc endForm {} { + my addStringDecr {} + return + } -## addInput - add in INPUT element -## Required arguments: -## -type -## -name -## Optional arguments: -## -value -## -size -## -maxlength -## -checked -## Common HTML arguments - -HtmlBuilder instproc addInput {args} { - set attributes [HtmlBuilder parseArguments $args \ - [list "TYPE" "NAME" "VALUE" "SIZE" "MAXLENGTH"] \ - [list "CHECKED"]] - my addString "" - return -} + ## addInput - add in INPUT element + ## Required arguments: + ## -type + ## -name + ## Optional arguments: + ## -value + ## -size + ## -maxlength + ## -checked + ## Common HTML arguments + + HtmlBuilder instproc addInput {args} { + set attributes [HtmlBuilder parseArguments $args \ + [list "TYPE" "NAME" "VALUE" "SIZE" "MAXLENGTH"] \ + [list "CHECKED"]] + my addString "" + return + } -## addTextArea - start a TEXTAREA element -## First parameter: value - Default value of the text area -## Required arguments: -## -rows -## -cols -## Optional arguments: -## -name -## Common HTML Arguments + ## addTextArea - start a TEXTAREA element + ## First parameter: value - Default value of the text area + ## Required arguments: + ## -rows + ## -cols + ## Optional arguments: + ## -name + ## Common HTML Arguments -HtmlBuilder instproc addTextArea {value args} { - set attributes [HtmlBuilder parseArguments $args \ - [list "ROWS" "COLS" "NAME"] [list]] - my addString "$value" - return -} + HtmlBuilder instproc addTextArea {value args} { + set attributes [HtmlBuilder parseArguments $args \ + [list "ROWS" "COLS" "NAME"] [list]] + my addString "$value" + return + } -## startOptionSelector - start a SELECT element -## Optional arguments: -## -name -## -size -## -multiple -## Common HTML arguments + ## startOptionSelector - start a SELECT element + ## Optional arguments: + ## -name + ## -size + ## -multiple + ## Common HTML arguments -HtmlBuilder instproc startOptionSelector {args} { - set attributes [HtmlBuilder parseArguments $args \ - [list "NAME" "SIZE"] [list "MULTIPLE"]] - my addStringIncr "" - return -} + HtmlBuilder instproc startOptionSelector {args} { + set attributes [HtmlBuilder parseArguments $args \ + [list "NAME" "SIZE"] [list "MULTIPLE"]] + my addStringIncr "" + return + } -## endOptionSelector - end a SELECT element + ## endOptionSelector - end a SELECT element -HtmlBuilder instproc endOptionSelector {} { - my addStringDecr "" - return -} + HtmlBuilder instproc endOptionSelector {} { + my addStringDecr "" + return + } -## startOption - start an OPTION element -## Optional arguments: -## -value -## -selected -## Common HTML arguments + ## startOption - start an OPTION element + ## Optional arguments: + ## -value + ## -selected + ## Common HTML arguments -HtmlBuilder instproc startOption {args} { - set attributes [HtmlBuilder parseArguments $args \ - [list "VALUE"] [list "SELECTED"]] - my addStringIncr "" - return -} + HtmlBuilder instproc startOption {args} { + set attributes [HtmlBuilder parseArguments $args \ + [list "VALUE"] [list "SELECTED"]] + my addStringIncr "" + return + } -## endOption - end an OPTION element + ## endOption - end an OPTION element -HtmlBuilder instproc endOption {} { - my addStringDecr "" - return -} + HtmlBuilder instproc endOption {} { + my addStringDecr "" + return + } -## addImage - add an IMG element -## Required arguments: -## -src -## -alt -## -align (deprecated in HTML 4.0) -## Optional arguments: -## Common HTML arguments + ## addImage - add an IMG element + ## Required arguments: + ## -src + ## -alt + ## -align (deprecated in HTML 4.0) + ## Optional arguments: + ## Common HTML arguments -HtmlBuilder instproc addImage {args} { - set attributes [HtmlBuilder parseArguments $args \ - [list "SRC" "ALT" "ALIGN"] [list]] - my addString "" - return -} + HtmlBuilder instproc addImage {args} { + set attributes [HtmlBuilder parseArguments $args \ + [list "SRC" "ALT" "ALIGN"] [list]] + my addString "" + return + } -## startBlock - start a DIV element (a generic block-level container) -## Optional arguments: -## Common HTML attributes + ## startBlock - start a DIV element (a generic block-level container) + ## Optional arguments: + ## Common HTML attributes -HtmlBuilder instproc startBlock {args} { - set attributes [HtmlBuilder parseArguments $args [list] [list]] - my addStringIncr "" - return -} + HtmlBuilder instproc startBlock {args} { + set attributes [HtmlBuilder parseArguments $args [list] [list]] + my addStringIncr "" + return + } -## endBlock - end a DIV element + ## endBlock - end a DIV element -HtmlBuilder instproc endBlock {} { - my addStringDecr "" - return -} + HtmlBuilder instproc endBlock {} { + my addStringDecr "" + return + } -## addHorizontalRule - add an HR element -## Optional arguments: -## Common HTML arguments + ## addHorizontalRule - add an HR element + ## Optional arguments: + ## Common HTML arguments -HtmlBuilder instproc addHorizontalRule {args} { - set attributes [HtmlBuilder parseArguments $args [list] [list]] - my addString "" - return + HtmlBuilder instproc addHorizontalRule {args} { + set attributes [HtmlBuilder parseArguments $args [list] [list]] + my addString "" + return + } + + namespace export HtmlBuilder } + +namespace import ::xotcl::htmllib::*