Module: Zable::Html

Included in:
View
Defined in:
lib/zable/html.rb

Instance Method Summary collapse

Instance Method Details

#body_cell_id(ac, elem) ⇒ Object



128
129
130
# File 'lib/zable/html.rb', line 128

def body_cell_id(ac, elem)
  "#{idify_class_name(elem)}_#{elem.id}_#{idify ac[:name]}".html_safe
end

#body_row_classObject



132
133
134
# File 'lib/zable/html.rb', line 132

def body_row_class
  cycle("odd", "even", name: "zable_cycle")
end

#body_row_id(elem) ⇒ Object



124
125
126
# File 'lib/zable/html.rb', line 124

def body_row_id(elem)
  "#{idify_class_name(elem)}_#{elem.id}".html_safe
end

#current_urlObject



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



86
87
88
89
90
91
92
# File 'lib/zable/html.rb', line 86

def empty_table_body_row(columns, args)
   :tr, :class => 'empty', :id=> "zable-empty-set" do
     :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



63
64
65
66
# File 'lib/zable/html.rb', line 63

def header_cell_href(attr)
  all_params = [sort_params(attr), search_params(@search), (@_extra_params || {}).to_query.html_safe].reject(&:blank?).join("&".html_safe)
  current_url << "?".html_safe << all_params
end


68
69
70
# File 'lib/zable/html.rb', line 68

def header_cell_link_text(attr)
  (attr[:title] || attr[:name].to_s.titleize).html_safe
end

#header_cell_sort_image(attr) ⇒ Object



72
73
74
75
76
# File 'lib/zable/html.rb', line 72

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



42
43
44
# File 'lib/zable/html.rb', line 42

def param(param_type, param_key, attr)
  "#{param_type}[#{param_key}]=#{attr}"
end

#search_params(params) ⇒ Object



53
54
55
56
57
# File 'lib/zable/html.rb', line 53

def search_params(params)
  params.to_a.collect do |param|
    param(:search, param.first, param.second)
  end.join("&".html_safe)
end

#sort_arrow_image_file(attr) ⇒ Object



59
60
61
# File 'lib/zable/html.rb', line 59

def sort_arrow_image_file(attr)
  attr[:sort_order] == :desc ? "ascending.gif" : "descending.gif"
end

#sort_params(attr) ⇒ Object



46
47
48
49
50
51
# File 'lib/zable/html.rb', line 46

def sort_params(attr)
  params = []
  params << param(:sort, "attr", attr[:name])
  params << param(:sort, "order", attr[:sort_order]) if attr[:sorted?]
  params.join("&".html_safe)
end

#table_body(collection, columns, args) ⇒ Object

Table body methods



79
80
81
82
83
84
# File 'lib/zable/html.rb', line 79

def table_body(collection, columns, args)
   :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



100
101
102
103
104
# File 'lib/zable/html.rb', line 100

def table_body_row(elem, columns)
   :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



113
114
115
116
117
118
119
120
121
122
# File 'lib/zable/html.rb', line 113

def table_body_row_cell(ac, elem)
  (: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



106
107
108
109
110
111
# File 'lib/zable/html.rb', line 106

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



94
95
96
97
98
# File 'lib/zable/html.rb', line 94

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)
   :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)
   :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)
   :tr do
    table_header_cells(columns)
  end
end