module CGI::HtmlExtension
def a(href = "") # :yield:
# => "Example"
a("HREF" => "http://www.example.com", "TARGET" => "_top") { "Example" }
# => "Example"
a("http://www.example.com") { "Example" }
block passed in.
The body of the element is the string returned by the no-argument
the element's attributes.
for the HREF attribute, or it can be a hash of
+href+ can either be a string, giving the URL
Generate an Anchor element as a string.
def a(href = "") # :yield: attributes = if href.kind_of?(String) { "HREF" => href } else href end super(attributes) end
def base(href = "") # :yield:
# => "
base("http://www.example.com/cgi")
The passed-in no-argument block is ignored.
attribute, or it can be a has of the element's attributes.
+href+ can either by a string, giving the base URL for the HREF
Generate a Document Base URI element as a String.
def base(href = "") # :yield: attributes = if href.kind_of?(String) { "HREF" => href } else href end super(attributes) end
def blockquote(cite = {}) # :yield:
#=> "
Foo!
blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
The body is provided by the passed-in no-argument block
or it can be omitted, in which case the element has no attributes.
the quoted text, or a hash, giving all attributes of the element,
+cite+ can either be a string, give the URI for the source of
Generate a BlockQuote element as a string.
def blockquote(cite = {}) # :yield: attributes = if cite.kind_of?(String) { "CITE" => cite } else cite end super(attributes) end
def caption(align = {}) # :yield:
# =>
caption("left") { "Capital Cities" }
The body of the element is provided by the passed-in no-argument block.
all the attributes of the element. Or it can be omitted.
(one of top, bottom, left, or right). It can be a hash of
+align+ can be a string, giving the alignment of the caption
Generate a Table Caption element as a string.
def caption(align = {}) # :yield: attributes = if align.kind_of?(String) { "ALIGN" => align } else align end super(attributes) end
def checkbox(name = "", value = nil, checked = nil)
checkbox("name", "value", true)
# = checkbox("NAME" => "name", "VALUE" => "value")
checkbox("name", "value")
# = checkbox("NAME" => "name")
checkbox("name")
Alternatively, the attributes can be specified as a hash.
if true, the CHECKED attribute will be included in the element.
+name+, +value+, and +checked+. +checked+ is a boolean value;
The attributes of the element can be specified as three arguments,
Generate a Checkbox Input element as a string.
def checkbox(name = "", value = nil, checked = nil) attributes = if name.kind_of?(String) { "TYPE" => "checkbox", "NAME" => name, "VALUE" => value, "CHECKED" => checked } else name["TYPE"] = "checkbox" name end input(attributes) end
def checkbox_group(name = "", *values)
checkbox_group("NAME" => "name",
"VALUES" => [["foo"], ["bar", true], "baz"])
checkbox_group("NAME" => "name",
"VALUES" => ["foo", "bar", "baz"])
checkbox_group("NAME" => "name",
# Baz
# Bar
# Foo
checkbox_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
# baz
# bar
# foo
checkbox_group("name", ["foo"], ["bar", true], "baz")
# baz
# bar
# foo
checkbox_group("name", "foo", "bar", "baz")
(defaults to false).
to the same as the label), or the boolean checked element
array, by omitting either the value element (defaults
Each value can also be specified as a two-element
checkbox is CHECKED.
label; and the third is a boolean specifying whether this
The first element is the VALUE attribute; the second is the
Each value can also be specified as a three-element array.
same effect.
for that checkbox. A single-element array has the
as the value of the VALUE attribute and as the label
can be specified as a String, which will be used both
There will be one checkbox for each value. Each value
Each checkbox is followed by a label.
The checkboxes will all have the same +name+ attribute.
Generate a sequence of checkbox elements, as a String.
def checkbox_group(name = "", *values) if name.kind_of?(Hash) values = name["VALUES"] name = name["NAME"] end values.collect{|value| if value.kind_of?(String) checkbox(name, value) + value else if value[-1] == true || value[-1] == false checkbox(name, value[0], value[-1]) + value[-2] else checkbox(name, value[0]) + value[-1] end end }.join end
def file_field(name = "", size = 20, maxlength = nil)
file_field("NAME" => "name", "SIZE" => 40)
#
file_field("name", 40, 100)
#
file_field("name", 40)
#
file_field("name")
See #multipart_form() for forms that include file uploads.
Alternatively, the attributes can be specified as a hash.
of the file's _name_, not of the file's _contents_.
+name+, +size+, and +maxlength+. +maxlength+ is the maximum length
The attributes of the element can be specified as three arguments,
Generate an File Upload Input element as a string.
def file_field(name = "", size = 20, maxlength = nil) attributes = if name.kind_of?(String) { "TYPE" => "file", "NAME" => name, "SIZE" => size.to_s } else name["TYPE"] = "file" name end attributes["MAXLENGTH"] = maxlength.to_s if maxlength input(attributes) end
def form(method = "post", action = script_name, enctype = "application/x-www-form-urlencoded")
form("METHOD" => "post", "ENCTYPE" => "enctype") { "string" }
#
form("get", "url") { "string" }
#
form("get") { "string" }
#
form{ "string" }
See also #multipart_form() for forms that include file uploads.
Alternatively, the attributes can be specified as a hash.
defaults to "application/x-www-form-urlencoded".
+action+ defaults to the current CGI script name. +enctype+
+method+ should be either "get" or "post", and defaults to the latter.
Generate a Form element as a string.
def form(method = "post", action = script_name, enctype = "application/x-www-form-urlencoded") attributes = if method.kind_of?(String) { "METHOD" => method, "ACTION" => action, "ENCTYPE" => enctype } else unless method.has_key?("METHOD") method["METHOD"] = "post" end unless method.has_key?("ENCTYPE") method["ENCTYPE"] = enctype end method end if block_given? body = yield else body = "" end if @output_hidden body << @output_hidden.collect{|k,v| "<INPUT TYPE=\"HIDDEN\" NAME=\"#{k}\" VALUE=\"#{v}\">" }.join end super(attributes){body} end
def hidden(name = "", value = nil)
hidden("NAME" => "name", "VALUE" => "reset", "ID" => "foo")
#
hidden("name", "value")
#
hidden("name")
Alternatively, the attributes can be specified as a hash.
+name+ and +value+.
The attributes of the element can be specified as two arguments,
Generate a Hidden Input element as a string.
def hidden(name = "", value = nil) attributes = if name.kind_of?(String) { "TYPE" => "hidden", "NAME" => name, "VALUE" => value } else name["TYPE"] = "hidden" name end input(attributes) end
def html(attributes = {}) # :yield:
html(if $VERBOSE then "PRETTY" end) { "HTML string" }
# = html("PRETTY" => " ") { "" }
html("PRETTY") { "" }
#