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
- #page_size_params ⇒ 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
132 133 134 |
# File 'lib/zable/html.rb', line 132 def body_cell_id(ac, elem) "#{idify_class_name(elem)}_#{elem.id}_#{idify ac[:name]}".html_safe end |
#body_row_class ⇒ Object
136 137 138 |
# File 'lib/zable/html.rb', line 136 def body_row_class cycle("odd", "even", name: "zable_cycle") end |
#body_row_id(elem) ⇒ Object
128 129 130 |
# File 'lib/zable/html.rb', line 128 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.gsub("%5B", "[").gsub("%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
90 91 92 93 94 95 96 |
# File 'lib/zable/html.rb', line 90 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
68 69 70 |
# File 'lib/zable/html.rb', line 68 def header_cell_href(attr) current_path_with_params(sort_params(attr), params.slice(:search), page_size_params, @_extra_params) end |
#header_cell_link_text(attr) ⇒ Object
72 73 74 |
# File 'lib/zable/html.rb', line 72 def header_cell_link_text(attr) (attr[:title] || attr[:name].to_s.titleize).html_safe end |
#header_cell_sort_image(attr) ⇒ Object
76 77 78 79 80 |
# File 'lib/zable/html.rb', line 76 def header_cell_sort_image(attr) return ''.html_safe unless attr[:sort] && attr[:sorted?] arrow = sort_arrow_image_file(attr) image_tag arrow end |
#page_size_params ⇒ Object
58 59 60 61 62 |
# File 'lib/zable/html.rb', line 58 def page_size_params p = {} p[:page] = {:size => params[:page][:size]} if params[:page] && params[:page][:size] p 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
64 65 66 |
# File 'lib/zable/html.rb', line 64 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) p = { :sort => {:attr => attr[:name]} } p[:sort][:order] = attr[:sort_order] if attr[:sorted?] p end |
#table_body(collection, columns, args) ⇒ Object
Table body methods
83 84 85 86 87 88 |
# File 'lib/zable/html.rb', line 83 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
104 105 106 107 108 |
# File 'lib/zable/html.rb', line 104 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
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/zable/html.rb', line 117 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
110 111 112 113 114 115 |
# File 'lib/zable/html.rb', line 110 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
98 99 100 101 102 |
# File 'lib/zable/html.rb', line 98 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 |