gridion 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,7 +41,16 @@ module Gridion
41
41
 
42
42
  options={:actions=>[:edit, :delete]}.merge(options).with_indifferent_access
43
43
 
44
-
44
+ if %w(ol ul).include?(options[:table_tag])
45
+ options[:table_header_tag]||="span"
46
+ options[:table_row_tag]||="li"
47
+ options[:table_cell_tag]||="span"
48
+ end
49
+
50
+ options[:table_tag]||="table"
51
+ options[:table_header_tag]||="th"
52
+ options[:table_row_tag]||="tr"
53
+ options[:table_cell_tag]||="td"
45
54
 
46
55
  if collection.blank?
47
56
  if options[:render_empty_grid]
@@ -53,7 +62,9 @@ module Gridion
53
62
 
54
63
  collection.each_with_index {|object, i| grid_binding.row.call(object.class, object, options.merge(:row_is_even=>i%2==1)) } #index starts from 0
55
64
 
56
- grid_binding.paginator.call(collection.first.class, collection, options) if collection.respond_to?(:current_page) && defined?(Kaminari) # we assume only Kaminari is supported
65
+ if collection.respond_to?(:current_page) && defined?(Kaminari) # we assume only Kaminari is supported
66
+ grid_binding.paginator.call(collection.first.class, collection, options) if collection.num_pages > 1
67
+ end
57
68
 
58
69
 
59
70
  grid_binding.footer.call(collection.first.class, collection, options)
@@ -66,20 +77,29 @@ module Gridion
66
77
  def initialize_grid_binding(grid_binding)
67
78
  with_output_buffer do
68
79
  grid_binding.header do |klass, collection, options={}|
69
- safe_concat("<table class=\"#{klass.name.downcase}\">")
70
- safe_concat("<tr>")
71
-
72
- (options[:columns]||klass.column_names).each do |col|
80
+ table_tag = options[:table_tag]||"table"
81
+ table_row_tag=options[:table_row_tag]||"tr"
82
+ table_header_tag=options[:table_header_tag]||"th"
83
+ safe_concat("<#{table_tag} class=\"#{klass.name.downcase}\">")
84
+
85
+ columns=options[:columns]||klass.column_names
86
+
87
+ safe_concat("<#{table_row_tag} class=\"header\">")
88
+ (columns).each do |col|
73
89
  col_label=klass.human_attribute_name(col)
74
90
  col_label = sort_link(options[:q], col, col_label) if defined?(:sort_link) && options.has_key?(:q)
75
- safe_concat("<th>#{col_label}</th>")
91
+ safe_concat("<#{table_header_tag} class=\"header_cell #{col.to_s.parameterize.underscore}\">#{col_label}</#{table_header_tag}>")
76
92
  end
77
- safe_concat("<th class=\"children\"></th>") if options.has_key?(:children)
78
- safe_concat("<th class=\"actions\">Actions</th>")
79
- safe_concat("</tr>")
93
+ safe_concat("<#{table_header_tag} class=\"actions\">Actions</#{table_header_tag}>")
94
+ safe_concat("<#{table_header_tag} class=\"children\"></#{table_header_tag}>") if options.has_key?(:children)
95
+ safe_concat("</#{table_row_tag}>")
80
96
  end
81
97
 
82
98
  grid_binding.row do |klass, object, options={}|
99
+ table_tag = options[:table_tag]||"table"
100
+ table_row_tag=options[:table_row_tag]||"tr"
101
+ table_cell_tag=options[:table_cell_tag]||"td"
102
+
83
103
  object_list=
84
104
  if options.has_key?(:parent)
85
105
  ([options[:parent]] + [object]).flatten
@@ -93,18 +113,23 @@ module Gridion
93
113
  end
94
114
 
95
115
  result =""
96
- result << "<tr id=\"#{klass.name}_#{object.id}\" class=\"#{options[:row_is_even] ? 'even' : 'odd'}\">"
97
116
  aux_columns={}
98
117
  aux_columns=options[:aux_columns].with_indifferent_access if options.has_key?(:aux_columns)
99
118
 
100
119
  formats=(options[:formats]||{}).with_indifferent_access
101
- (options[:columns]||klass.column_names).each do |col|
120
+ actions=options[:actions]
121
+ columns=options[:columns]||klass.column_names
122
+
123
+ row_id="#{klass.name}_#{object.id}"
124
+
125
+ result << "<#{table_row_tag} id=\"#{row_id}\" class=\"#{options[:row_is_even] ? 'even' : 'odd'}\">"
126
+ (columns).each do |col|
102
127
  if aux_columns[col].present?
103
128
  value=aux_columns[col].call(object, options)
104
129
  else
105
130
  value=object.send(col)
106
131
  if formats.has_key?(col)
107
-
132
+
108
133
  if formats[col]==:currency
109
134
  value=number_to_currency(value)
110
135
  elsif formats[col].kind_of?(Hash)
@@ -117,16 +142,30 @@ module Gridion
117
142
  # use hook
118
143
  value=formats[col].call(value)
119
144
  end
120
-
121
-
122
145
  end
123
146
  end
124
- result << "<td class=\"#{col}\">#{value}</td>"
147
+ result << "<#{table_cell_tag} class=\"#{col}\">#{value}</#{table_cell_tag}>"
148
+ end
149
+
150
+
151
+ if actions.present?
152
+ result << "<#{table_cell_tag} class=\"actions\">"
153
+ if actions.kind_of?(Proc)
154
+ result << actions.call(object, options)
155
+ elsif actions.kind_of?(Array)
156
+ result << "#{link_to 'Show', object_list, :class=>%w{action_link show}}" if actions.include?(:show)
157
+ result << "#{link_to 'Edit', [:edit]+ object_list, :class=>%w{action_link edit}}" if actions.include?(:edit)
158
+ result << "#{link_to 'Delete', object_list, :class=>%w{action_link delete}, :method=>:delete, :confirm=>'Are you sure?'}" if actions.include?(:delete)
159
+ elsif actions.kind_of?(Hash)
160
+ result << "#{link_to 'Show', object_list, {:class=>%w{action_link show}}.merge(actions[:show]||{})}" if actions.has_key?(:show)
161
+ result << "#{link_to 'Edit', [:edit]+ object_list, {:class=>%w{action_link edit}}.merge(actions[:edit]||{})}" if actions.include?(:edit)
162
+ result << "#{link_to 'Delete', object_list, {:class=>%w{action_link delete}, :method=>:delete, :confirm=>'Are you sure?'}.merge(actions[:delete]||{})}" if actions.include?(:delete)
163
+ end
164
+ result << "</#{table_cell_tag}>"
125
165
  end
126
- actions=options[:actions]
127
166
 
128
167
  if options.has_key?(:children)
129
- result << "<td class=\"children\">"
168
+ result << "<#{table_cell_tag} class=\"children\">"
130
169
  children_hash=
131
170
  if options[:children].kind_of?(Array)
132
171
  options[:children].each_with_object({}) {|child, h| h[child]=child.to_s.singularize.classify.constantize.model_name.human.pluralize }
@@ -140,42 +179,36 @@ module Gridion
140
179
  result << link_to(label, [namespaces, object, child].flatten, :class=>"child_link #{child.to_s}")
141
180
  end
142
181
 
143
- result << "</td>"
182
+ result << "</#{table_cell_tag}>"
144
183
  end
145
184
 
146
- if actions.present?
147
- result << "<td class=\"actions\">"
148
- if actions.kind_of?(Proc)
149
- result << actions.call(object, options)
150
- elsif actions.kind_of?(Array)
151
- result << "#{link_to 'Show', object_list, :class=>%w{action_link show}}" if actions.include?(:show)
152
- result << "#{link_to 'Edit', [:edit]+ object_list, :class=>%w{action_link edit}}" if actions.include?(:edit)
153
- result << "#{link_to 'Delete', object_list, :class=>%w{action_link delete}, :method=>:delete, :confirm=>'Are you sure?'}" if actions.include?(:delete)
154
- elsif actions.kind_of?(Hash)
155
- result << "#{link_to 'Show', object_list, {:class=>%w{action_link show}}.merge(actions[:show]||{})}" if actions.has_key?(:show)
156
- result << "#{link_to 'Edit', [:edit]+ object_list, {:class=>%w{action_link edit}}.merge(actions[:edit]||{})}" if actions.include?(:edit)
157
- result << "#{link_to 'Delete', object_list, {:class=>%w{action_link delete}, :method=>:delete, :confirm=>'Are you sure?'}.merge(actions[:delete]||{})}" if actions.include?(:delete)
158
- end
159
- result << "</td>"
160
- end
161
- result << "</tr>"
185
+
186
+ result << "</#{table_row_tag}>"
162
187
  safe_concat(result)
163
188
 
164
189
  end
165
190
 
166
191
  grid_binding.paginator do |klass, collection, options|
192
+ table_tag = options[:table_tag]
193
+ table_row_tag=options[:table_row_tag]
194
+ table_cell_tag=options[:table_cell_tag]
195
+
167
196
  colspans=(options[:columns]||klass.column_names).count + 2 #TODO: change this to number of action columns
168
197
  result = ""
169
- result << "<tr class=\"footer\">"
170
- result << "<td colspan=\"#{colspans}\">"
198
+ result << "<#{table_row_tag} class=\"paginator\">"
199
+ result << "<#{table_cell_tag} colspan=\"#{colspans}\">"
171
200
  result << paginate(collection)
172
- result << "</td>"
173
- result << "</tr>"
201
+ result << "</#{table_cell_tag}>"
202
+ result << "</#{table_row_tag}>"
174
203
  safe_concat(result)
175
204
  end
176
205
 
177
206
  grid_binding.footer do |klass, collection, options={}|
178
- safe_concat("</table>")
207
+ table_tag = options[:table_tag]
208
+ table_row_tag=options[:table_row_tag]
209
+ table_cell_tag=options[:table_cell_tag]
210
+
211
+ safe_concat("</#{table_tag}>")
179
212
  end
180
213
 
181
214
 
@@ -1,3 +1,3 @@
1
1
  module Gridion
2
- VERSION = "0.0.16"
2
+ VERSION = "0.0.17"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gridion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-02 00:00:00.000000000Z
12
+ date: 2011-12-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3
16
- requirement: &70223266421760 !ruby/object:Gem::Requirement
16
+ requirement: &70341045774500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70223266421760
24
+ version_requirements: *70341045774500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: kaminari
27
- requirement: &70223266421260 !ruby/object:Gem::Requirement
27
+ requirement: &70341045773800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70223266421260
35
+ version_requirements: *70341045773800
36
36
  description: Simple grid helper for rails
37
37
  email:
38
38
  - william@tofugear.com
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  segments:
92
92
  - 0
93
- hash: -2662129059111446417
93
+ hash: -2132856971133222190
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  segments:
101
101
  - 0
102
- hash: -2662129059111446417
102
+ hash: -2132856971133222190
103
103
  requirements: []
104
104
  rubyforge_project:
105
105
  rubygems_version: 1.8.10