| Module | CGI::HtmlExtension |
| In: |
lib/cgi.rb
|
Generate an Anchor element as a string.
href can either be a string, giving the URL for the HREF attribute, or it can be a hash of the element‘s attributes.
The body of the element is the string returned by the no-argument block passed in.
a("http://www.example.com") { "Example" }
# => "<A HREF=\"http://www.example.com\">Example</A>"
a("HREF" => "http://www.example.com", "TARGET" => "_top") { "Example" }
# => "<A HREF=\"http://www.example.com\" TARGET=\"_top\">Example</A>"
# File lib/cgi.rb, line 1315
1315: def a(href = "") # :yield:
1316: attributes = if href.kind_of?(String)
1317: { "HREF" => href }
1318: else
1319: href
1320: end
1321: if block_given?
1322: super(attributes){ yield }
1323: else
1324: super(attributes)
1325: end
1326: end
Generate a Document Base URI element as a String.
href can either by a string, giving the base URL for the HREF attribute, or it can be a has of the element‘s attributes.
The passed-in no-argument block is ignored.
base("http://www.example.com/cgi")
# => "<BASE HREF=\"http://www.example.com/cgi\">"
# File lib/cgi.rb, line 1337
1337: def base(href = "") # :yield:
1338: attributes = if href.kind_of?(String)
1339: { "HREF" => href }
1340: else
1341: href
1342: end
1343: if block_given?
1344: super(attributes){ yield }
1345: else
1346: super(attributes)
1347: end
1348: end
Generate a BlockQuote element as a string.
cite can either be a string, give the URI for the source of the quoted text, or a hash, giving all attributes of the element, or it can be omitted, in which case the element has no attributes.
The body is provided by the passed-in no-argument block
blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
#=> "<BLOCKQUOTE CITE=\"http://www.example.com/quotes/foo.html\">Foo!</BLOCKQUOTE>
# File lib/cgi.rb, line 1360
1360: def blockquote(cite = nil) # :yield:
1361: attributes = if cite.kind_of?(String)
1362: { "CITE" => cite }
1363: else
1364: cite or ""
1365: end
1366: if block_given?
1367: super(attributes){ yield }
1368: else
1369: super(attributes)
1370: end
1371: end
Generate a Table Caption element as a string.
align can be a string, giving the alignment of the caption (one of top, bottom, left, or right). It can be a hash of all the attributes of the element. Or it can be omitted.
The body of the element is provided by the passed-in no-argument block.
caption("left") { "Capital Cities" }
# => <CAPTION ALIGN=\"left\">Capital Cities</CAPTION>
# File lib/cgi.rb, line 1384
1384: def caption(align = nil) # :yield:
1385: attributes = if align.kind_of?(String)
1386: { "ALIGN" => align }
1387: else
1388: align or ""
1389: end
1390: if block_given?
1391: super(attributes){ yield }
1392: else
1393: super(attributes)
1394: end
1395: end
Generate a Checkbox Input element as a string.
The attributes of the element can be specified as three arguments, name, value, and checked. checked is a boolean value; if true, the CHECKED attribute will be included in the element.
Alternatively, the attributes can be specified as a hash.
checkbox("name")
# = checkbox("NAME" => "name")
checkbox("name", "value")
# = checkbox("NAME" => "name", "VALUE" => "value")
checkbox("name", "value", true)
# = checkbox("NAME" => "name", "VALUE" => "value", "CHECKED" => true)
# File lib/cgi.rb, line 1414
1414: def checkbox(name = "", value = nil, checked = nil)
1415: attributes = if name.kind_of?(String)
1416: { "TYPE" => "checkbox", "NAME" => name,
1417: "VALUE" => value, "CHECKED" => checked }
1418: else
1419: name["TYPE"] = "checkbox"
1420: name
1421: end
1422: input(attributes)
1423: end
Generate a sequence of checkbox elements, as a String.
The checkboxes will all have the same name attribute. Each checkbox is followed by a label. There will be one checkbox for each value. Each value can be specified as a String, which will be used both as the value of the VALUE attribute and as the label for that checkbox. A single-element array has the same effect.
Each value can also be specified as a three-element array. The first element is the VALUE attribute; the second is the label; and the third is a boolean specifying whether this checkbox is CHECKED.
Each value can also be specified as a two-element array, by omitting either the value element (defaults to the same as the label), or the boolean checked element (defaults to false).
checkbox_group("name", "foo", "bar", "baz")
# <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
# <INPUT TYPE="checkbox" NAME="name" VALUE="bar">bar
# <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
checkbox_group("name", ["foo"], ["bar", true], "baz")
# <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
# <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="bar">bar
# <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
checkbox_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
# <INPUT TYPE="checkbox" NAME="name" VALUE="1">Foo
# <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="2">Bar
# <INPUT TYPE="checkbox" NAME="name" VALUE="Baz">Baz
checkbox_group("NAME" => "name",
"VALUES" => ["foo", "bar", "baz"])
checkbox_group("NAME" => "name",
"VALUES" => [["foo"], ["bar", true], "baz"])
checkbox_group("NAME" => "name",
"VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
# File lib/cgi.rb, line 1468
1468: def checkbox_group(name = "", *values)
1469: if name.kind_of?(Hash)
1470: values = name["VALUES"]
1471: name = name["NAME"]
1472: end
1473: values.collect{|value|
1474: if value.kind_of?(String)
1475: checkbox(name, value) + value
1476: else
1477: if value[value.size - 1] == true
1478: checkbox(name, value[0], true) +
1479: value[value.size - 2]
1480: else
1481: checkbox(name, value[0]) +
1482: value[value.size - 1]
1483: end
1484: end
1485: }.to_s
1486: end
Generate an File Upload Input element as a string.
The attributes of the element can be specified as three arguments, name, size, and maxlength. maxlength is the maximum length of the file‘s name, not of the file‘s contents.
Alternatively, the attributes can be specified as a hash.
See multipart_form() for forms that include file uploads.
file_field("name")
# <INPUT TYPE="file" NAME="name" SIZE="20">
file_field("name", 40)
# <INPUT TYPE="file" NAME="name" SIZE="40">
file_field("name", 40, 100)
# <INPUT TYPE="file" NAME="name" SIZE="40" MAXLENGTH="100">
file_field("NAME" => "name", "SIZE" => 40)
# <INPUT TYPE="file" NAME="name" SIZE="40">
# File lib/cgi.rb, line 1510
1510: def file_field(name = "", size = 20, maxlength = nil)
1511: attributes = if name.kind_of?(String)
1512: { "TYPE" => "file", "NAME" => name,
1513: "SIZE" => size.to_s }
1514: else
1515: name["TYPE"] = "file"
1516: name
1517: end
1518: attributes["MAXLENGTH"] = maxlength.to_s if maxlength
1519: input(attributes)
1520: end
Generate a Form element as a string.
method should be either "get" or "post", and defaults to the latter. action defaults to the current CGI script name. enctype defaults to "application/x-www-form-urlencoded".
Alternatively, the attributes can be specified as a hash.
See also multipart_form() for forms that include file uploads.
form{ "string" }
# <FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
form("get") { "string" }
# <FORM METHOD="get" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
form("get", "url") { "string" }
# <FORM METHOD="get" ACTION="url" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
form("METHOD" => "post", "ENCTYPE" => "enctype") { "string" }
# <FORM METHOD="post" ENCTYPE="enctype">string</FORM>
# File lib/cgi.rb, line 1544
1544: def form(method = "post", action = script_name, enctype = "application/x-www-form-urlencoded")
1545: attributes = if method.kind_of?(String)
1546: { "METHOD" => method, "ACTION" => action,
1547: "ENCTYPE" => enctype }
1548: else
1549: unless method.has_key?("METHOD")
1550: method["METHOD"] = "post"
1551: end
1552: unless method.has_key?("ENCTYPE")
1553: method["ENCTYPE"] = enctype
1554: end
1555: method
1556: end
1557: if block_given?
1558: body = yield
1559: else
1560: body = ""
1561: end
1562: if @output_hidden
1563: body += @output_hidden.collect{|k,v|
1564: "<INPUT TYPE=\"HIDDEN\" NAME=\"#{k}\" VALUE=\"#{v}\">"
1565: }.to_s
1566: end
1567: super(attributes){body}
1568: end
Generate a Hidden Input element as a string.
The attributes of the element can be specified as two arguments, name and value.
Alternatively, the attributes can be specified as a hash.
hidden("name")
# <INPUT TYPE="hidden" NAME="name">
hidden("name", "value")
# <INPUT TYPE="hidden" NAME="name" VALUE="value">
hidden("NAME" => "name", "VALUE" => "reset", "ID" => "foo")
# <INPUT TYPE="hidden" NAME="name" VALUE="value" ID="foo">
# File lib/cgi.rb, line 1585
1585: def hidden(name = "", value = nil)
1586: attributes = if name.kind_of?(String)
1587: { "TYPE" => "hidden", "NAME" => name, "VALUE" => value }
1588: else
1589: name["TYPE"] = "hidden"
1590: name
1591: end
1592: input(attributes)
1593: end
Generate a top-level HTML element as a string.
The attributes of the element are specified as a hash. The pseudo-attribute "PRETTY" can be used to specify that the generated HTML string should be indented. "PRETTY" can also be specified as a string as the sole argument to this method. The pseudo-attribute "DOCTYPE", if given, is used as the leading DOCTYPE SGML tag; it should include the entire text of this tag, including angle brackets.
The body of the html element is supplied as a block.
html{ "string" }
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML>string</HTML>
html("LANG" => "ja") { "string" }
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML LANG="ja">string</HTML>
html("DOCTYPE" => false) { "string" }
# <HTML>string</HTML>
html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">') { "string" }
# <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>string</HTML>
html("PRETTY" => " ") { "<BODY></BODY>" }
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
# <HTML>
# <BODY>
# </BODY>
# </HTML>
html("PRETTY" => "\t") { "<BODY></BODY>" }
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
# <HTML>
# <BODY>
# </BODY>
# </HTML>
html("PRETTY") { "<BODY></BODY>" }
# = html("PRETTY" => " ") { "<BODY></BODY>" }
html(if $VERBOSE then "PRETTY" end) { "HTML string" }
# File lib/cgi.rb, line 1637
1637: def html(attributes = {}) # :yield:
1638: if nil == attributes
1639: attributes = {}
1640: elsif "PRETTY" == attributes
1641: attributes = { "PRETTY" => true }
1642: end
1643: pretty = attributes.delete("PRETTY")
1644: pretty = " " if true == pretty
1645: buf = ""
1646:
1647: if attributes.has_key?("DOCTYPE")
1648: if attributes["DOCTYPE"]
1649: buf += attributes.delete("DOCTYPE")
1650: else
1651: attributes.delete("DOCTYPE")
1652: end
1653: else
1654: buf += doctype
1655: end
1656:
1657: if block_given?
1658: buf += super(attributes){ yield }
1659: else
1660: buf += super(attributes)
1661: end
1662:
1663: if pretty
1664: CGI::pretty(buf, pretty)
1665: else
1666: buf
1667: end
1668:
1669: end
Generate an Image Button Input element as a string.
src is the URL of the image to use for the button. name is the input name. alt is the alternative text for the image.
Alternatively, the attributes can be specified as a hash.
image_button("url")
# <INPUT TYPE="image" SRC="url">
image_button("url", "name", "string")
# <INPUT TYPE="image" SRC="url" NAME="name" ALT="string">
image_button("SRC" => "url", "ATL" => "strng")
# <INPUT TYPE="image" SRC="url" ALT="string">
# File lib/cgi.rb, line 1686
1686: def image_button(src = "", name = nil, alt = nil)
1687: attributes = if src.kind_of?(String)
1688: { "TYPE" => "image", "SRC" => src, "NAME" => name,
1689: "ALT" => alt }
1690: else
1691: src["TYPE"] = "image"
1692: src["SRC"] ||= ""
1693: src
1694: end
1695: input(attributes)
1696: end
Generate an Image element as a string.
src is the URL of the image. alt is the alternative text for the image. width is the width of the image, and height is its height.
Alternatively, the attributes can be specified as a hash.
img("src", "alt", 100, 50)
# <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
img("SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50)
# <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
# File lib/cgi.rb, line 1712
1712: def img(src = "", alt = "", width = nil, height = nil)
1713: attributes = if src.kind_of?(String)
1714: { "SRC" => src, "ALT" => alt }
1715: else
1716: src
1717: end
1718: attributes["WIDTH"] = width.to_s if width
1719: attributes["HEIGHT"] = height.to_s if height
1720: super(attributes)
1721: end
Generate a Form element with multipart encoding as a String.
Multipart encoding is used for forms that include file uploads.
action is the action to perform. enctype is the encoding type, which defaults to "multipart/form-data".
Alternatively, the attributes can be specified as a hash.
multipart_form{ "string" }
# <FORM METHOD="post" ENCTYPE="multipart/form-data">string</FORM>
multipart_form("url") { "string" }
# <FORM METHOD="post" ACTION="url" ENCTYPE="multipart/form-data">string</FORM>
# File lib/cgi.rb, line 1738
1738: def multipart_form(action = nil, enctype = "multipart/form-data")
1739: attributes = if action == nil
1740: { "METHOD" => "post", "ENCTYPE" => enctype }
1741: elsif action.kind_of?(String)
1742: { "METHOD" => "post", "ACTION" => action,
1743: "ENCTYPE" => enctype }
1744: else
1745: unless action.has_key?("METHOD")
1746: action["METHOD"] = "post"
1747: end
1748: unless action.has_key?("ENCTYPE")
1749: action["ENCTYPE"] = enctype
1750: end
1751: action
1752: end
1753: if block_given?
1754: form(attributes){ yield }
1755: else
1756: form(attributes)
1757: end
1758: end
Generate a Password Input element as a string.
name is the name of the input field. value is its default value. size is the size of the input field display. maxlength is the maximum length of the inputted password.
Alternatively, attributes can be specified as a hash.
password_field("name")
# <INPUT TYPE="password" NAME="name" SIZE="40">
password_field("name", "value")
# <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="40">
password_field("password", "value", 80, 200)
# <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
password_field("NAME" => "name", "VALUE" => "value")
# <INPUT TYPE="password" NAME="name" VALUE="value">
# File lib/cgi.rb, line 1780
1780: def password_field(name = "", value = nil, size = 40, maxlength = nil)
1781: attributes = if name.kind_of?(String)
1782: { "TYPE" => "password", "NAME" => name,
1783: "VALUE" => value, "SIZE" => size.to_s }
1784: else
1785: name["TYPE"] = "password"
1786: name
1787: end
1788: attributes["MAXLENGTH"] = maxlength.to_s if maxlength
1789: input(attributes)
1790: end
Generate a Select element as a string.
name is the name of the element. The values are the options that can be selected from the Select menu. Each value can be a String or a one, two, or three-element Array. If a String or a one-element Array, this is both the value of that option and the text displayed for it. If a three-element Array, the elements are the option value, displayed text, and a boolean value specifying whether this option starts as selected. The two-element version omits either the option value (defaults to the same as the display text) or the boolean selected specifier (defaults to false).
The attributes and options can also be specified as a hash. In this case, options are specified as an array of values as described above, with the hash key of "VALUES".
popup_menu("name", "foo", "bar", "baz")
# <SELECT NAME="name">
# <OPTION VALUE="foo">foo</OPTION>
# <OPTION VALUE="bar">bar</OPTION>
# <OPTION VALUE="baz">baz</OPTION>
# </SELECT>
popup_menu("name", ["foo"], ["bar", true], "baz")
# <SELECT NAME="name">
# <OPTION VALUE="foo">foo</OPTION>
# <OPTION VALUE="bar" SELECTED>bar</OPTION>
# <OPTION VALUE="baz">baz</OPTION>
# </SELECT>
popup_menu("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
# <SELECT NAME="name">
# <OPTION VALUE="1">Foo</OPTION>
# <OPTION SELECTED VALUE="2">Bar</OPTION>
# <OPTION VALUE="Baz">Baz</OPTION>
# </SELECT>
popup_menu("NAME" => "name", "SIZE" => 2, "MULTIPLE" => true,
"VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
# <SELECT NAME="name" MULTIPLE SIZE="2">
# <OPTION VALUE="1">Foo</OPTION>
# <OPTION SELECTED VALUE="2">Bar</OPTION>
# <OPTION VALUE="Baz">Baz</OPTION>
# </SELECT>
# File lib/cgi.rb, line 1835
1835: def popup_menu(name = "", *values)
1836:
1837: if name.kind_of?(Hash)
1838: values = name["VALUES"]
1839: size = name["SIZE"].to_s if name["SIZE"]
1840: multiple = name["MULTIPLE"]
1841: name = name["NAME"]
1842: else
1843: size = nil
1844: multiple = nil
1845: end
1846:
1847: select({ "NAME" => name, "SIZE" => size,
1848: "MULTIPLE" => multiple }){
1849: values.collect{|value|
1850: if value.kind_of?(String)
1851: option({ "VALUE" => value }){ value }
1852: else
1853: if value[value.size - 1] == true
1854: option({ "VALUE" => value[0], "SELECTED" => true }){
1855: value[value.size - 2]
1856: }
1857: else
1858: option({ "VALUE" => value[0] }){
1859: value[value.size - 1]
1860: }
1861: end
1862: end
1863: }.to_s
1864: }
1865:
1866: end
Generates a radio-button Input element.
name is the name of the input field. value is the value of the field if checked. checked specifies whether the field starts off checked.
Alternatively, the attributes can be specified as a hash.
radio_button("name", "value")
# <INPUT TYPE="radio" NAME="name" VALUE="value">
radio_button("name", "value", true)
# <INPUT TYPE="radio" NAME="name" VALUE="value" CHECKED>
radio_button("NAME" => "name", "VALUE" => "value", "ID" => "foo")
# <INPUT TYPE="radio" NAME="name" VALUE="value" ID="foo">
# File lib/cgi.rb, line 1884
1884: def radio_button(name = "", value = nil, checked = nil)
1885: attributes = if name.kind_of?(String)
1886: { "TYPE" => "radio", "NAME" => name,
1887: "VALUE" => value, "CHECKED" => checked }
1888: else
1889: name["TYPE"] = "radio"
1890: name
1891: end
1892: input(attributes)
1893: end
Generate a sequence of radio button Input elements, as a String.
This works the same as checkbox_group(). However, it is not valid to have more than one radiobutton in a group checked.
radio_group("name", "foo", "bar", "baz")
# <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
# <INPUT TYPE="radio" NAME="name" VALUE="bar">bar
# <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
radio_group("name", ["foo"], ["bar", true], "baz")
# <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
# <INPUT TYPE="radio" CHECKED NAME="name" VALUE="bar">bar
# <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
radio_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
# <INPUT TYPE="radio" NAME="name" VALUE="1">Foo
# <INPUT TYPE="radio" CHECKED NAME="name" VALUE="2">Bar
# <INPUT TYPE="radio" NAME="name" VALUE="Baz">Baz
radio_group("NAME" => "name",
"VALUES" => ["foo", "bar", "baz"])
radio_group("NAME" => "name",
"VALUES" => [["foo"], ["bar", true], "baz"])
radio_group("NAME" => "name",
"VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
# File lib/cgi.rb, line 1923
1923: def radio_group(name = "", *values)
1924: if name.kind_of?(Hash)
1925: values = name["VALUES"]
1926: name = name["NAME"]
1927: end
1928: values.collect{|value|
1929: if value.kind_of?(String)
1930: radio_button(name, value) + value
1931: else
1932: if value[value.size - 1] == true
1933: radio_button(name, value[0], true) +
1934: value[value.size - 2]
1935: else
1936: radio_button(name, value[0]) +
1937: value[value.size - 1]
1938: end
1939: end
1940: }.to_s
1941: end
Generate a reset button Input element, as a String.
This resets the values on a form to their initial values. value is the text displayed on the button. name is the name of this button.
Alternatively, the attributes can be specified as a hash.
reset
# <INPUT TYPE="reset">
reset("reset")
# <INPUT TYPE="reset" VALUE="reset">
reset("VALUE" => "reset", "ID" => "foo")
# <INPUT TYPE="reset" VALUE="reset" ID="foo">
# File lib/cgi.rb, line 1958
1958: def reset(value = nil, name = nil)
1959: attributes = if (not value) or value.kind_of?(String)
1960: { "TYPE" => "reset", "VALUE" => value, "NAME" => name }
1961: else
1962: value["TYPE"] = "reset"
1963: value
1964: end
1965: input(attributes)
1966: end
Generate a submit button Input element, as a String.
value is the text to display on the button. name is the name of the input.
Alternatively, the attributes can be specified as a hash.
submit
# <INPUT TYPE="submit">
submit("ok")
# <INPUT TYPE="submit" VALUE="ok">
submit("ok", "button1")
# <INPUT TYPE="submit" VALUE="ok" NAME="button1">
submit("VALUE" => "ok", "NAME" => "button1", "ID" => "foo")
# <INPUT TYPE="submit" VALUE="ok" NAME="button1" ID="foo">
# File lib/cgi.rb, line 1988
1988: def submit(value = nil, name = nil)
1989: attributes = if (not value) or value.kind_of?(String)
1990: { "TYPE" => "submit", "VALUE" => value, "NAME" => name }
1991: else
1992: value["TYPE"] = "submit"
1993: value
1994: end
1995: input(attributes)
1996: end
Generate a text field Input element, as a String.
name is the name of the input field. value is its initial value. size is the size of the input area. maxlength is the maximum length of input accepted.
Alternatively, the attributes can be specified as a hash.
text_field("name")
# <INPUT TYPE="text" NAME="name" SIZE="40">
text_field("name", "value")
# <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="40">
text_field("name", "value", 80)
# <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80">
text_field("name", "value", 80, 200)
# <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
text_field("NAME" => "name", "VALUE" => "value")
# <INPUT TYPE="text" NAME="name" VALUE="value">
# File lib/cgi.rb, line 2020
2020: def text_field(name = "", value = nil, size = 40, maxlength = nil)
2021: attributes = if name.kind_of?(String)
2022: { "TYPE" => "text", "NAME" => name, "VALUE" => value,
2023: "SIZE" => size.to_s }
2024: else
2025: name["TYPE"] = "text"
2026: name
2027: end
2028: attributes["MAXLENGTH"] = maxlength.to_s if maxlength
2029: input(attributes)
2030: end
Generate a TextArea element, as a String.
name is the name of the textarea. cols is the number of columns and rows is the number of rows in the display.
Alternatively, the attributes can be specified as a hash.
The body is provided by the passed-in no-argument block
textarea("name")
# = textarea("NAME" => "name", "COLS" => 70, "ROWS" => 10)
textarea("name", 40, 5)
# = textarea("NAME" => "name", "COLS" => 40, "ROWS" => 5)
# File lib/cgi.rb, line 2046
2046: def textarea(name = "", cols = 70, rows = 10) # :yield:
2047: attributes = if name.kind_of?(String)
2048: { "NAME" => name, "COLS" => cols.to_s,
2049: "ROWS" => rows.to_s }
2050: else
2051: name
2052: end
2053: if block_given?
2054: super(attributes){ yield }
2055: else
2056: super(attributes)
2057: end
2058: end