Module: Shortcuts
- Defined in:
- lib/reparcs/shortcuts.rb
Overview
A collection of shortcut methods for reparcs
Instance Method Summary collapse
-
#shortcut_anchor(href, text) ⇒ Object
A shortcut for creating a anchor takes the url, and the text as parameter.
-
#shortcut_header(size, heading) ⇒ Object
A shortcut for creating a header takes the header size, and the header text as parameters.
-
#shortcut_meta(equiv, content) ⇒ Object
A shortcut for creating a meta data element ‘<meta http-equiv=“?” conten=“?” /> takes the http-equiv type, and the content as parameters.
-
#shortcut_script(code) ⇒ Object
A shortcut for creating a script ‘<script type=“text/javascript”></script>’ takes the javascipt code as parameter.
-
#shortcut_select(hash) ⇒ Object
A shortcut for creating a select ‘<select></select>’ takes a hash object as parameter.
-
#shortcut_style(css) ⇒ Object
A shortcut for creating a style ‘<style type=“text/css”></style> takes the css code as parameter.
-
#shortcut_table(headers, data) ⇒ Object
A shortcut for creating a table of data, takes an array of headers, and a multidimensional array of the table data.
-
#shortcut_title(text) ⇒ Object
A shortcut for creating a title, takes the titles text as parameter.
-
#shortcut_unordered_list(array) ⇒ Object
A shortcut for creating a unordered list ‘ul’ takes an array of elements or strings for the list items.
Instance Method Details
#shortcut_anchor(href, text) ⇒ Object
A shortcut for creating a anchor takes the url, and the text as parameter
6 7 8 9 10 |
# File 'lib/reparcs/shortcuts.rb', line 6 def shortcut_anchor(href, text) anchor = Anchor.new({:href => href}) anchor.append(text) return anchor end |
#shortcut_header(size, heading) ⇒ Object
A shortcut for creating a header takes the header size, and the header text as parameters.
14 15 16 17 18 |
# File 'lib/reparcs/shortcuts.rb', line 14 def shortcut_header(size, heading) head = Header.new(size) head.append(heading) return head end |
#shortcut_meta(equiv, content) ⇒ Object
A shortcut for creating a meta data element ‘<meta http-equiv=“?” conten=“?” /> takes the http-equiv type, and the content as parameters
69 70 71 72 73 |
# File 'lib/reparcs/shortcuts.rb', line 69 def (equiv, content) = Meta.new({:content => content}) .set_attribute("http-equiv", equiv) return end |
#shortcut_script(code) ⇒ Object
A shortcut for creating a script ‘<script type=“text/javascript”></script>’ takes the javascipt code as parameter
46 47 48 49 50 |
# File 'lib/reparcs/shortcuts.rb', line 46 def shortcut_script(code) script = Script.new({:type => 'text/javascript'}) script.append(code) return script end |
#shortcut_select(hash) ⇒ Object
A shortcut for creating a select ‘<select></select>’ takes a hash object as parameter.
34 35 36 37 38 39 40 41 42 |
# File 'lib/reparcs/shortcuts.rb', line 34 def shortcut_select(hash) select = Select.new hash.each do |key, val| option = Option.new({:value => val}) option.append(key.to_s) select.append(option) end return select end |
#shortcut_style(css) ⇒ Object
A shortcut for creating a style ‘<style type=“text/css”></style> takes the css code as parameter
54 55 56 57 58 |
# File 'lib/reparcs/shortcuts.rb', line 54 def shortcut_style(css) style = Style.new({:type => 'text/css'}) style.append(css) return style end |
#shortcut_table(headers, data) ⇒ Object
A shortcut for creating a table of data, takes an array of headers, and a multidimensional array of the table data.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/reparcs/shortcuts.rb', line 78 def shortcut_table(headers, data) tbl = Table.new tbl_hdrs = TableHeader.new tbl_hdr_row = TableRow.new headers.each do |h| tc = TableHeaderCell.new tc.append(h) tbl_hdr_row.append(tc) end tbl_hdrs.append(tbl_hdr_row) tbl.append(tbl_hdrs) tbl_bdy = TableBody.new data.each do |r| tr = TableRow.new r.each do |c| tc = TableCell.new tc.append(c) tr.append(tc) end tbl_bdy.append(tr) end tbl.append(tbl_bdy) return tbl end |
#shortcut_title(text) ⇒ Object
A shortcut for creating a title, takes the titles text as parameter.
61 62 63 64 65 |
# File 'lib/reparcs/shortcuts.rb', line 61 def shortcut_title(text) title = Title.new title.append(text) return title end |
#shortcut_unordered_list(array) ⇒ Object
A shortcut for creating a unordered list ‘ul’ takes an array of elements or strings for the list items.
22 23 24 25 26 27 28 29 30 |
# File 'lib/reparcs/shortcuts.rb', line 22 def shortcut_unordered_list(array) ul = UnorderedList.new array.each do |i| li = ListItem.new li.append(i) ul.append(li) end return ul end |