Module: Zable::Html
- Included in:
- View
- Defined in:
- lib/zable/html.rb
Instance Method Summary collapse
- #body_cell_id(ac, elem) ⇒ Object
- #body_row_class ⇒ Object
- #body_row_id(elem) ⇒ Object
- #current_path_with_params(*param_array) ⇒ Object
- #current_url ⇒ Object
- #empty_table_body_row(columns, args) ⇒ Object
- #header_cell_content(attr, columns) ⇒ Object
- #header_cell_href(attr) ⇒ Object
- #header_cell_link_text(attr) ⇒ Object
- #header_cell_sort_image(attr) ⇒ Object
- #param(param_type, param_key, attr) ⇒ Object
- #sort_arrow_image_file(attr) ⇒ Object
- #sort_params(attr) ⇒ Object
-
#table_body(collection, columns, args) ⇒ Object
Table body methods.
- #table_body_row(elem, columns) ⇒ Object
- #table_body_row_cell(ac, elem) ⇒ Object
- #table_body_row_cells(elem, columns) ⇒ Object
- #table_body_rows(collection, columns) ⇒ Object
-
#table_header(columns) ⇒ Object
Table header methods.
- #table_header_cell(attr, columns) ⇒ Object
- #table_header_cells(columns) ⇒ Object
- #table_header_row(columns) ⇒ Object
Instance Method Details
#body_cell_id(ac, elem) ⇒ Object
126 127 128 |
# File 'lib/zable/html.rb', line 126 def body_cell_id(ac, elem) "#{idify_class_name(elem)}_#{elem.id}_#{idify ac[:name]}".html_safe end |
#body_row_class ⇒ Object
130 131 132 |
# File 'lib/zable/html.rb', line 130 def body_row_class cycle("odd", "even", name: "zable_cycle") end |
#body_row_id(elem) ⇒ Object
122 123 124 |
# File 'lib/zable/html.rb', line 122 def body_row_id(elem) "#{idify_class_name(elem)}_#{elem.id}".html_safe end |
#current_path_with_params(*param_array) ⇒ Object
42 43 44 45 46 |
# File 'lib/zable/html.rb', line 42 def current_path_with_params(*param_array) all_params = param_array.reject(&:blank?).map {|p| p.to_query.html_safe}.join("&".html_safe) all_params = all_params.sub("%5B", "[").sub("%5D", "]") current_url << "?".html_safe << all_params end |
#current_url ⇒ Object
38 39 40 |
# File 'lib/zable/html.rb', line 38 def current_url "#{controller.request.fullpath.split("?")[0]}" end |
#empty_table_body_row(columns, args) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/zable/html.rb', line 84 def empty_table_body_row(columns, args) content_tag :tr, :class => 'empty', :id=> "zable-empty-set" do content_tag :td, :colspan => columns.size do (args[:empty_message] || "No items found.").html_safe end end end |
#header_cell_content(attr, columns) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/zable/html.rb', line 29 def header_cell_content(attr, columns) if attr[:title] && attr[:title].respond_to?(:call) attr[:title].call else str = link_to_if attr[:sort], header_cell_link_text(attr), header_cell_href(attr) str << header_cell_sort_image(attr) end end |
#header_cell_href(attr) ⇒ Object
62 63 64 |
# File 'lib/zable/html.rb', line 62 def header_cell_href(attr) current_path_with_params(sort_params(attr), params.slice(:search), @_extra_params) end |
#header_cell_link_text(attr) ⇒ Object
66 67 68 |
# File 'lib/zable/html.rb', line 66 def header_cell_link_text(attr) (attr[:title] || attr[:name].to_s.titleize).html_safe end |
#header_cell_sort_image(attr) ⇒ Object
70 71 72 73 74 |
# File 'lib/zable/html.rb', line 70 def header_cell_sort_image(attr) return ''.html_safe unless attr[:sort] && attr[:sorted?] arrow = sort_arrow_image_file(attr) image_tag arrow end |
#param(param_type, param_key, attr) ⇒ Object
48 49 50 |
# File 'lib/zable/html.rb', line 48 def param(param_type, param_key, attr) "#{param_type}[#{param_key}]=#{attr}" end |
#sort_arrow_image_file(attr) ⇒ Object
58 59 60 |
# File 'lib/zable/html.rb', line 58 def sort_arrow_image_file(attr) attr[:sort_order] == :desc ? "ascending.gif" : "descending.gif" end |
#sort_params(attr) ⇒ Object
52 53 54 55 56 |
# File 'lib/zable/html.rb', line 52 def sort_params(attr) params = { :sort => {:attr => attr[:name]} } params[:sort][:order] = attr[:sort_order] if attr[:sorted?] params end |
#table_body(collection, columns, args) ⇒ Object
Table body methods
77 78 79 80 81 82 |
# File 'lib/zable/html.rb', line 77 def table_body(collection, columns, args) content_tag :tbody do return empty_table_body_row(columns,args) if collection.empty? (table_body_rows(collection, columns) || "".html_safe) + (args[:append] || "".html_safe) end end |
#table_body_row(elem, columns) ⇒ Object
98 99 100 101 102 |
# File 'lib/zable/html.rb', line 98 def table_body_row(elem, columns) content_tag :tr, :id => body_row_id(elem), :class => body_row_class do table_body_row_cells(elem, columns) end end |
#table_body_row_cell(ac, elem) ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/zable/html.rb', line 111 def table_body_row_cell(ac, elem) content_tag(:td, :id => body_cell_id(ac, elem)) do if block_given? yield elem else val = elem.send(ac[:name]) val.respond_to?(:strftime) ? val.strftime("%m/%d/%Y") : val.to_s end end end |
#table_body_row_cells(elem, columns) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/zable/html.rb', line 104 def table_body_row_cells(elem, columns) columns.inject("".html_safe) do |str, ac| block = ac[:block] if ac.has_key?(:block) str << table_body_row_cell(ac, elem, &block) end end |
#table_body_rows(collection, columns) ⇒ Object
92 93 94 95 96 |
# File 'lib/zable/html.rb', line 92 def table_body_rows(collection, columns) collection.inject("".html_safe) do |str, elem| str << table_body_row(elem, columns) end end |
#table_header(columns) ⇒ Object
Table header methods
5 6 7 8 9 |
# File 'lib/zable/html.rb', line 5 def table_header(columns) content_tag :thead do table_header_row(columns) end end |
#table_header_cell(attr, columns) ⇒ Object
23 24 25 26 27 |
# File 'lib/zable/html.rb', line 23 def table_header_cell(attr, columns) content_tag :th, :data => {:column => idify(attr[:name])} do header_cell_content(attr, columns) end end |
#table_header_cells(columns) ⇒ Object
17 18 19 20 21 |
# File 'lib/zable/html.rb', line 17 def table_header_cells(columns) columns.inject("".html_safe) do |str, attr| str << table_header_cell(attr, columns) end end |
#table_header_row(columns) ⇒ Object
11 12 13 14 15 |
# File 'lib/zable/html.rb', line 11 def table_header_row(columns) content_tag :tr do table_header_cells(columns) end end |