table-for 2.2.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/example.rdoc ADDED
@@ -0,0 +1,138 @@
1
+ To run the example that generates this table:
2
+ {<img src="https://raw.github.com/hunterae/table-for/master/example_table.png">}[http://example.com]
3
+
4
+ In Gemfile:
5
+ gem "table-for", :git => "git@github.com:hunterae/table-for.git"
6
+
7
+ # To be able to generate an admin namespaced controller with a non-admin namespaced model
8
+ gem 'nifty-generators'
9
+
10
+ # To make things look a little nicer
11
+ gem 'therubyracer'
12
+ gem 'less-rails' #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
13
+ gem 'twitter-bootstrap-rails'
14
+
15
+ # To paginate the list
16
+ gem 'will_paginate', '~> 3.0'
17
+
18
+ In seeds.rb:
19
+ User.create! :email => "hunterae@gmail.com", :first_name => "Andrew", :last_name => "Hunter"
20
+ User.create! :email => "todd@calltrackingmetrics.com", :first_name => "Todd", :last_name => "Fisher"
21
+ User.create! :email => "jon.phillips@livingsocial.com", :first_name => "Jon", :last_name => "Phillips"
22
+
23
+ From console:
24
+ bundle install
25
+ rails g nifty:scaffold Admin::User email:string first_name:string last_name:string
26
+ rails generate bootstrap:install less
27
+ rake db:create && rake db:migrate && rake db:seed && rake db:seed && rake db:seed && rake db:seed
28
+ rails s
29
+
30
+ In routes.rb:
31
+ namespace :admin do
32
+ resources :users do
33
+ collection do
34
+ match :sort, :to => :index, :via => [:get, :post]
35
+ end
36
+ end
37
+ end
38
+
39
+ In users_controller.rb (index action)
40
+ @users = User.unscoped
41
+ if params[:order] && ["asc", "desc"].include?(params[:sort_mode])
42
+ order = params[:order].split(",").map {|o| "#{o} #{params[:sort_mode]}" }.join(", ")
43
+ @users = @users.order(order)
44
+ end
45
+ @users = @users.paginate(:per_page => 10, :page => params[:page])
46
+
47
+ In views/admin/users/index.html.erb
48
+ <%= table_for @users,
49
+ # Specifies the html classes to be applied to the table element
50
+ :table_html => { :class => "table table-hover table-bordered" },
51
+
52
+ # Specifies that all columns are sortable by default
53
+ :sortable => true,
54
+
55
+ # Specifies the url that header sort links use
56
+ :sort_url => sort_admin_users_path,
57
+
58
+ # Specifies the namespace for generating links using Rails routing
59
+ :link_namespace => :admin,
60
+
61
+ # Specifies the classes and ids to be applied to each data row
62
+ :data_row_html => {
63
+ # The class of each row will alternate between four Twitter bootstrap classes: "success", "error", "warning", "info"
64
+ :class => lambda { cycle('success', 'error', 'warning', 'info')},
65
+
66
+ # Specifies the id using a Proc for each data row as "user-ID_OF_USER_RECORD"
67
+ :id => lambda { |user| "user-#{user.id}" }
68
+ } do |table| %>
69
+
70
+ <%# Method 1 for creating a link: Create edit link dynamically by specifying the link_scope globally above as :admin and the link_action as :edit %>
71
+ <% table.column :data => "Modify", :link_action => :edit %>
72
+
73
+ <%# Method 2 for creating a link: Create an show link by providing a link_url Proc %>
74
+ <% table.column :data => "Show", :link_url => lambda { |user| admin_user_path(user) } %>
75
+
76
+ <%# Method 3 for creating a link: Rely on RESTful routes to generate the link %>
77
+ <% table.column :data => "Show 2.0", :link => true %>
78
+
79
+ <%# Outputs the email column of the user; override the default generated header for the column with "Email Address" %>
80
+ <% table.column :email, :header => "Email Address" %>
81
+
82
+ <%# Outputs the first name column of the user with the :downcase method applied to it %>
83
+ <% table.column :first_name, :formatter => :downcase %>
84
+
85
+ <%# Outputs the last name column of the user using formatter Proc to dynamically specify what is output in the data cell %>
86
+ <% table.column :last_name, :formatter => Proc.new { |last_name| last_name.upcase } %>
87
+
88
+ <%# Outputs the created at column of the user applying the strftime method with the argument "%m/%d/%y %I:%M %p" to it %>
89
+ <% table.column :created_at, :formatter => [:strftime, "%m/%d/%y %I:%M %p"] %>
90
+
91
+ <%#
92
+ Outputs the updated_at column of the user
93
+ Overrides the default generated header for the column with the dynamic result of calling it's Proc
94
+ Overrides the default sort-ability by specifying this column as non-sortable
95
+ Overrides the default header html with orange background color
96
+ Dynamically specifies the data for the column with a Proc
97
+ (Note also that the arguments to the Proc are optional and the data record can be accessed via "table.current_row" [or "table.current_record])")
98
+ %>
99
+ <% table.column :updated_at,
100
+ :header => Proc.new {
101
+ content_tag(:span, :class => "badge badge-success") do
102
+ "Last Updated"
103
+ end
104
+ },
105
+ :sortable => false,
106
+ :header_column_html => { :style => "background-color:orange" },
107
+ :data => Proc.new { time_ago_in_words table.current_row.updated_at } %>
108
+
109
+ <%#
110
+ The data for the column can also be provided via a block
111
+ Overrides the default generated header for the column with "Full Name" (will itself be overridden below)
112
+ Overrides the default sort field with "last_name" then "first_name"
113
+ %>
114
+ <% table.column :full_name, :header => "Full Name", :order => "last_name, first_name" do |user| %>
115
+ <%= "#{user.first_name} #{user.last_name}" %>
116
+ <% end %>
117
+
118
+ <%# Overrides the content for the header of the full_name column %>
119
+ <% table.header :full_name do |column, options| %>
120
+ <%= table.header_sort_link(column, options) do %>
121
+ <span class="label label-important">FULL NAME</span>
122
+ <% end %>
123
+ <% end %>
124
+
125
+ <%#
126
+ Method 3 (again) for creating a link: Rely on RESTful routes to generate the link, with a "delete" method
127
+ Applies a confirmation to the link
128
+ Specifies the data to display in the column as "Delete"
129
+ %>
130
+ <% table.column :data => "Delete", :link_method => :delete, :link_confirm => "Are you sure?" %>
131
+
132
+ <%# Adds a footer that spans all the columns of the table and shows pagination links for the table %>
133
+ <% table.footer do %>
134
+ <div class="pull-right">
135
+ <%= will_paginate @users %>
136
+ </div>
137
+ <% end %>
138
+ <% end %>
data/example_table.png ADDED
Binary file
data/lib/table_for.rb CHANGED
@@ -5,10 +5,20 @@ require "blocks"
5
5
  module TableFor
6
6
  autoload :Base, "table_for/base"
7
7
  autoload :ViewAdditions, "table_for/view_additions"
8
+ autoload :HelperMethods, "table_for/helper_methods"
8
9
 
9
10
  mattr_accessor :default_table_class
10
11
  @@default_table_class = nil
11
12
 
13
+ mattr_accessor :render_thead_element
14
+ @@render_thead_element = true
15
+
16
+ mattr_accessor :render_tbody_element
17
+ @@render_tbody_element = true
18
+
19
+ mattr_accessor :render_tfoot_element
20
+ @@render_tfoot_element = true
21
+
12
22
  # Default way to setup TableFor
13
23
  def self.setup
14
24
  yield self
@@ -2,18 +2,12 @@ require 'blocks'
2
2
 
3
3
  module TableFor
4
4
  class Base < Blocks::Base
5
+ include TableFor::HelperMethods::InstanceMethods
6
+
5
7
  alias columns queued_blocks
6
8
  alias column queue
7
9
 
8
10
  attr_accessor :current_record
9
11
  alias_method :current_row, :current_record
10
-
11
- def header(name, options={}, &block)
12
- define("#{name.to_s}_header", options, &block)
13
- end
14
-
15
- def set_current_record(record)
16
- self.current_record = record
17
- end
18
12
  end
19
- end
13
+ end
@@ -0,0 +1,88 @@
1
+ module TableFor
2
+ module HelperMethods
3
+ module InstanceMethods
4
+ def header(name, options={}, &block)
5
+ define("#{name.to_s}_header", options.reverse_merge(:header => true), &block)
6
+ end
7
+
8
+ def footer(options={}, &block)
9
+ define(:footer_content, options, &block)
10
+ end
11
+
12
+ def table_html(options)
13
+ if options[:table_html]
14
+ options[:table_html].reverse_merge!(:class => TableFor.default_table_class) if TableFor.default_table_class
15
+ options[:table_html]
16
+ elsif TableFor.default_table_class
17
+ {:class => TableFor.default_table_class}
18
+ end
19
+ end
20
+
21
+ def header_column_html(column, options={})
22
+ header_column_html = call_each_hash_value_with_params(options[:header_column_html], column)
23
+ if options[:sortable]
24
+ order = options[:order] ? options[:order].to_s : column.name.to_s
25
+ sort_class = (view.params[:order] != order || view.params[:sort_mode] == "reset") ? "sorting" : (view.params[:sort_mode] == "desc" ? "sorting_desc" : "sorting_asc")
26
+ header_column_html[:class] = (header_column_html[:class] ? "#{header_column_html[:class]} #{sort_class}" : sort_class)
27
+ end
28
+ header_column_html
29
+ end
30
+
31
+ def header_cell_content(column, options={})
32
+ unless options[:header] == false
33
+ header_sort_link(column, options) do
34
+ if options[:header]
35
+ call_with_params options[:header], column
36
+ elsif column.anonymous
37
+ nil
38
+ else
39
+ column.name.to_s.titleize
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ def cell_content(record, column, options={})
46
+ if options[:link_url] || options[:link_action] || options[:link_method] || options[:link_confirm] || options[:link]
47
+ url = options[:link_url] ? call_with_params(options[:link_url], record) : [options[:link_action], options[:link_namespace], record].flatten
48
+ end
49
+
50
+ if options[:formatter]
51
+ if options[:formatter].is_a?(Proc)
52
+ content = call_with_params(options[:formatter], record.send(column.name), options)
53
+ else
54
+ content = record.send(column.name).try(*options[:formatter])
55
+ end
56
+ elsif options[:data] || [:edit, :show, :delete].include?(column.name)
57
+ content = call_with_params(options[:data], record)
58
+ else
59
+ content = record.send(column.name)
60
+ end
61
+
62
+ if content.blank? || url.blank? || options[:link] == false
63
+ content
64
+ elsif url
65
+ view.link_to content, url, {:method => options[:link_method], :confirm => options[:link_confirm]}.merge(options[:link_html])
66
+ end
67
+ end
68
+
69
+ def set_current_record(record)
70
+ self.current_record = record
71
+ end
72
+
73
+ def header_sort_link(column, options={}, &block)
74
+ if options[:sortable] && (options[:header] || !column.anonymous)
75
+ order = options[:order] ? options[:order].to_s : column.name.to_s
76
+ sort_mode = (view.params[:order] != order || view.params[:sort_mode] == "reset") ? "asc" : (view.params[:sort_mode] == "desc" ? "reset" : "desc")
77
+ parameters = view.params.merge(:order => order, :sort_mode => sort_mode)
78
+ parameters.delete(:action)
79
+ parameters.delete(:controller)
80
+ url = options[:sort_url] ? options[:sort_url] : ""
81
+ view.link_to view.capture(self, &block), "#{url}?#{parameters.to_query}"
82
+ else
83
+ view.capture(self, &block)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -2,59 +2,7 @@ module TableFor
2
2
  module ViewAdditions
3
3
  module ClassMethods
4
4
  def table_for(records, options={}, &block)
5
- TableFor::Base.new(self, options.merge(:variable => "table", :records => records, :use_partials => false)).render_template("table_for/table_for", &block)
6
- end
7
-
8
- def table_for_header_html(column, options={})
9
- header_html = call_each_hash_value_if_proc(options[:header_html], column)
10
- if options[:sortable]
11
- order = options[:order] ? options[:order].to_s : column.name.to_s
12
- sort_class = (params[:order] != order || params[:sort_mode] == "reset") ? "sorting" : (params[:sort_mode] == "desc" ? "sorting_desc" : "sorting_asc")
13
- header_html[:class] = (header_html[:class] ? "#{header_html[:class]} #{sort_class}" : sort_class)
14
- end
15
- header_html
16
- end
17
-
18
- def table_for_sort_link(column, options={})
19
- order = options[:order] ? options[:order].to_s : column.name.to_s
20
- label = (options[:label] ? options[:label] : column.name.to_s.titleize)
21
- sort_mode = (params[:order] != order || params[:sort_mode] == "reset") ? "asc" : (params[:sort_mode] == "desc" ? "reset" : "desc")
22
- parameters = params.merge(:order => order, :sort_mode => sort_mode)
23
- parameters.delete(:action)
24
- parameters.delete(:controller)
25
- url = options[:sort_url] ? options[:sort_url] : ""
26
- link_to label, "#{url}?#{parameters.to_query}"
27
- end
28
-
29
- def table_for_table_html(options)
30
- if options[:table_html]
31
- options[:table_html].merge!(:class => TableFor.default_table_class) if TableFor.default_table_class && !options[:table_html][:class]
32
- options[:table_html]
33
- elsif TableFor.default_table_class
34
- {:class => TableFor.default_table_class}
35
- end
36
- end
37
-
38
- def table_for_header_cell_data(column, options={})
39
- unless options[:label] == false
40
- if options[:sortable]
41
- table_for_sort_link(column, options)
42
- else
43
- options[:label] ? options[:label] : column.name.to_s.titleize
44
- end
45
- end
46
- end
47
-
48
- def table_for_cell_data(record, column, options)
49
- if (options[:transformation])
50
- if options[:transformation].is_a?(Proc)
51
- call_if_proc(options[:transformation], record, column, options)
52
- else
53
- record.send(column.name).try(*options[:transformation])
54
- end
55
- else
56
- record.send(column.name)
57
- end
5
+ TableFor::Base.new(self, options.merge(:variable => "table", :records => records)).render_template("table_for/table_for", &block)
58
6
  end
59
7
  end
60
8
  end
@@ -118,7 +118,7 @@ describe "table_for" do
118
118
  end
119
119
 
120
120
  it "should be able to specify html attributes" do
121
- buffer = @view.table_for @users[0,1], :header_html => {:class => "sortable"} do |table|
121
+ buffer = @view.table_for @users[0,1], :header_column_html => {:class => "sortable"} do |table|
122
122
  table.column :first_name
123
123
  end
124
124
  xml = XmlSimple.xml_in(%%<table><thead><tr><th class="sortable">First Name</th></tr></thead><tbody><tr><td>Andrew</td></tr></tbody></table>%)
@@ -126,7 +126,7 @@ describe "table_for" do
126
126
  end
127
127
 
128
128
  it "should be able to dynamically specify column attributes" do
129
- buffer = @view.table_for @users[0, 1], :header_html => {:class => lambda {@view.cycle("even", "odd")},
129
+ buffer = @view.table_for @users[0, 1], :header_column_html => {:class => lambda {@view.cycle("even", "odd")},
130
130
  :id => lambda {|column| "#{column.name.to_s}_header"}} do |table|
131
131
  table.column :email
132
132
  table.column :first_name
@@ -149,85 +149,85 @@ describe "table_for" do
149
149
  end
150
150
  end
151
151
 
152
- describe "edit_header block" do
153
- it "should be able to replace the edit_header block" do
154
- @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
155
- buffer = @view.table_for @users[0,1] do |table|
156
- table.define :edit_header do
157
- "Edit"
158
- end
159
- table.column :edit
160
- end
161
-
162
- xml = XmlSimple.xml_in(%%
163
- <table>
164
- <thead><tr><th>Edit</th></tr></thead>
165
- <tbody>
166
- <tr>
167
- <td>
168
- <a href="/users/1/edit">Edit</a>
169
- </td>
170
- </tr>
171
- </tbody>
172
- </table>%)
173
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
174
- end
175
- end
176
-
177
- describe "delete_header block" do
178
- it "should be able to replace the delete_header block" do
179
- @view.expects(:user_path).with(User.first).returns("/users/1")
180
- buffer = @view.table_for @users[0,1] do |table|
181
- table.define :delete_header do
182
- "Delete"
183
- end
184
- table.column :delete
185
- end
186
-
187
- xml = XmlSimple.xml_in(%%
188
- <table>
189
- <thead><tr><th>Delete</th></tr></thead>
190
- <tbody>
191
- <tr>
192
- <td>
193
- <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
194
- </td>
195
- </tr>
196
- </tbody>
197
- </table>%)
198
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
199
- end
200
- end
201
-
202
- describe "show_header block" do
203
- it "should be able to replace the show_header block" do
204
- @view.expects(:user_path).with(User.first).returns("/users/1")
205
- buffer = @view.table_for @users[0,1] do |table|
206
- table.define :show_header do
207
- "Show"
208
- end
209
- table.column :show
210
- end
211
-
212
- xml = XmlSimple.xml_in(%%
213
- <table>
214
- <thead><tr><th>Show</th></tr></thead>
215
- <tbody>
216
- <tr>
217
- <td>
218
- <a href="/users/1">Show</a>
219
- </td>
220
- </tr>
221
- </tbody>
222
- </table>%)
223
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
224
- end
225
- end
152
+ # describe "edit_header block" do
153
+ # it "should be able to replace the edit_header block" do
154
+ # @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
155
+ # buffer = @view.table_for @users[0,1] do |table|
156
+ # table.define :edit_header do
157
+ # "Edit"
158
+ # end
159
+ # table.column :edit
160
+ # end
161
+ #
162
+ # xml = XmlSimple.xml_in(%%
163
+ # <table>
164
+ # <thead><tr><th>Edit</th></tr></thead>
165
+ # <tbody>
166
+ # <tr>
167
+ # <td>
168
+ # <a href="/users/1/edit">Edit</a>
169
+ # </td>
170
+ # </tr>
171
+ # </tbody>
172
+ # </table>%)
173
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
174
+ # end
175
+ # end
176
+ #
177
+ # describe "delete_header block" do
178
+ # it "should be able to replace the delete_header block" do
179
+ # @view.expects(:user_path).with(User.first).returns("/users/1")
180
+ # buffer = @view.table_for @users[0,1] do |table|
181
+ # table.define :delete_header do
182
+ # "Delete"
183
+ # end
184
+ # table.column :delete
185
+ # end
186
+ #
187
+ # xml = XmlSimple.xml_in(%%
188
+ # <table>
189
+ # <thead><tr><th>Delete</th></tr></thead>
190
+ # <tbody>
191
+ # <tr>
192
+ # <td>
193
+ # <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
194
+ # </td>
195
+ # </tr>
196
+ # </tbody>
197
+ # </table>%)
198
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
199
+ # end
200
+ # end
201
+ #
202
+ # describe "show_header block" do
203
+ # it "should be able to replace the show_header block" do
204
+ # @view.expects(:user_path).with(User.first).returns("/users/1")
205
+ # buffer = @view.table_for @users[0,1] do |table|
206
+ # table.define :show_header do
207
+ # "Show"
208
+ # end
209
+ # table.column :show
210
+ # end
211
+ #
212
+ # xml = XmlSimple.xml_in(%%
213
+ # <table>
214
+ # <thead><tr><th>Show</th></tr></thead>
215
+ # <tbody>
216
+ # <tr>
217
+ # <td>
218
+ # <a href="/users/1">Show</a>
219
+ # </td>
220
+ # </tr>
221
+ # </tbody>
222
+ # </table>%)
223
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
224
+ # end
225
+ # end
226
226
 
227
227
  describe "column header contents block" do
228
- it "should be able to override the label for a particular column" do
228
+ it "should be able to override the header for a particular column" do
229
229
  buffer = @view.table_for @users[0,1] do |table|
230
- table.column :email, :label => "Email Address"
230
+ table.column :email, :header => "Email Address"
231
231
  end
232
232
 
233
233
  xml = XmlSimple.xml_in(%%
@@ -238,15 +238,15 @@ describe "table_for" do
238
238
  XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
239
239
  end
240
240
 
241
- it "should be able to override the global defined label for all columns" do
242
- buffer = @view.table_for @users[0,1], :label => "My Default Label" do |table|
243
- table.column :email, :label => "Email Address"
241
+ it "should be able to override the global defined header for all columns" do
242
+ buffer = @view.table_for @users[0,1], :header => "My Default Header" do |table|
243
+ table.column :email, :header => "Email Address"
244
244
  table.column :first_name
245
245
  end
246
246
 
247
247
  xml = XmlSimple.xml_in(%%
248
248
  <table>
249
- <thead><tr><th>Email Address</th><th>My Default Label</th></tr></thead>
249
+ <thead><tr><th>Email Address</th><th>My Default Header</th></tr></thead>
250
250
  <tbody><tr><td>andrew.hunter@livingsocial.com</td><td>Andrew</td></tr></tbody>
251
251
  </table>%)
252
252
  XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
@@ -254,9 +254,9 @@ describe "table_for" do
254
254
 
255
255
  it "should be able to override the definition for a particular column header block" do
256
256
  buffer = @view.table_for @users[0,1] do |table|
257
- table.column :email, :label => "Email Address"
257
+ table.column :email, :header => "Email Address"
258
258
  table.define :email_header do |column, options|
259
- "My Own Header (Replaced #{options[:label]})"
259
+ "My Own Header (Replaced #{options[:header]})"
260
260
  end
261
261
  end
262
262
 
@@ -270,9 +270,9 @@ describe "table_for" do
270
270
 
271
271
  it "should be able to override the definition for a particular column header block using the table_for 'header' method" do
272
272
  buffer = @view.table_for @users[0,1] do |table|
273
- table.column :email, :label => "Email Address"
273
+ table.column :email, :header => "Email Address"
274
274
  table.header :email do |column, options|
275
- "My Own Header (Replaced #{options[:label]})"
275
+ "My Own Header (Replaced #{options[:header]})"
276
276
  end
277
277
  end
278
278
 
@@ -287,7 +287,7 @@ describe "table_for" do
287
287
  it "should add a 'sorting' class to the 'th' element and a link around the header content if a column is sortable" do
288
288
  @view.expects(:params).at_least_once.returns({})
289
289
  buffer = @view.table_for @users[0,1] do |table|
290
- table.column :email, :sortable => true, :header_html => {:class => "email", :style => "color:red"}
290
+ table.column :email, :sortable => true, :header_column_html => {:class => "email", :style => "color:red"}
291
291
  end
292
292
  xml = XmlSimple.xml_in(%%
293
293
  <table>
@@ -396,12 +396,12 @@ describe "table_for" do
396
396
  XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
397
397
  end
398
398
 
399
- it "should allow a global header_html option for all columns and the ability to override on a column by column basis" do
400
- buffer = @view.table_for @users[0,1], :header_html => {:class => lambda {|column| "#{column.name}_header"}} do |table|
399
+ it "should allow a global header_column_html option for all columns and the ability to override on a column by column basis" do
400
+ buffer = @view.table_for @users[0,1], :header_column_html => {:class => lambda {|column| "#{column.name}_header"}} do |table|
401
401
  @view.expects(:params).at_least_once.returns({})
402
402
  table.column :email, :sortable => true
403
- table.column :first_name, :header_html => {:class => "my_header"}
404
- table.column :last_name, :header_html => {:class => "my_other_header"}, :sortable => true
403
+ table.column :first_name, :header_column_html => {:class => "my_header"}
404
+ table.column :last_name, :header_column_html => {:class => "my_other_header"}, :sortable => true
405
405
  end
406
406
  xml = XmlSimple.xml_in(%%
407
407
  <table>
@@ -438,10 +438,10 @@ describe "table_for" do
438
438
  end
439
439
  end
440
440
 
441
- describe "row block" do
442
- it "should be able to replace the row block" do
441
+ describe "data_row block" do
442
+ it "should be able to replace the data_row block" do
443
443
  buffer = @view.table_for @users do |table|
444
- table.define :row do |user|
444
+ table.define :data_row do |user|
445
445
  "<tr><td>User #{user.first_name}</td></tr>".html_safe
446
446
  end
447
447
  table.column :first_name
@@ -460,7 +460,7 @@ describe "table_for" do
460
460
  end
461
461
 
462
462
  it "should be able to dynamically specify row attributes" do
463
- buffer = @view.table_for @users, :row_html => {:class => lambda {@view.cycle("even", "odd")},
463
+ buffer = @view.table_for @users, :data_row_html => {:class => lambda {@view.cycle("even", "odd")},
464
464
  :id => lambda {|user| "user-#{user.id}"}} do |table|
465
465
  table.column :email
466
466
  end
@@ -478,10 +478,10 @@ describe "table_for" do
478
478
  end
479
479
  end
480
480
 
481
- describe "column block" do
482
- it "should be able to replace the columns block" do
481
+ describe "data_column block" do
482
+ it "should be able to replace the data_column block" do
483
483
  buffer = @view.table_for @users[0, 1] do |table|
484
- table.define :column do |column, user, options|
484
+ table.define :data_column do |column, user, options|
485
485
  "<td>#{column.name.to_s.titleize} value is #{user.send(column.name)}</td>".html_safe
486
486
  end
487
487
  table.column :email
@@ -504,7 +504,7 @@ describe "table_for" do
504
504
  end
505
505
 
506
506
  it "should be able to specify html attributes" do
507
- buffer = @view.table_for @users[0,1], :column_html => {:class => "data"} do |table|
507
+ buffer = @view.table_for @users[0,1], :data_column_html => {:class => "data"} do |table|
508
508
  table.column :first_name
509
509
  end
510
510
  xml = XmlSimple.xml_in(%%<table><thead><tr><th>First Name</th></tr></thead><tbody><tr><td class="data">Andrew</td></tr></tbody></table>%)
@@ -512,7 +512,7 @@ describe "table_for" do
512
512
  end
513
513
 
514
514
  it "should be able to dynamically specify column attributes" do
515
- buffer = @view.table_for @users[0, 1], :column_html => {:class => lambda {@view.cycle("even", "odd")},
515
+ buffer = @view.table_for @users[0, 1], :data_column_html => {:class => lambda {@view.cycle("even", "odd")},
516
516
  :id => lambda {|user, column| "#{column.name.to_s}_data"}} do |table|
517
517
  table.column :email
518
518
  table.column :first_name
@@ -535,9 +535,9 @@ describe "table_for" do
535
535
  XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
536
536
  end
537
537
 
538
- it "should allow a global column_html option for all columns and the ability to override on a column by column basis" do
539
- buffer = @view.table_for @users[0,1], :column_html => {:class => lambda {|record, column| "#{column.name}_data"}} do |table|
540
- table.column :first_name, :column_html => {:class => "my_data"}
538
+ it "should allow a global data_column_html option for all columns and the ability to override on a column by column basis" do
539
+ buffer = @view.table_for @users[0,1], :data_column_html => {:class => lambda {|record, column| "#{column.name}_data"}} do |table|
540
+ table.column :first_name, :data_column_html => {:class => "my_data"}
541
541
  table.column :last_name
542
542
  end
543
543
  xml = XmlSimple.xml_in(%%
@@ -554,362 +554,362 @@ describe "table_for" do
554
554
  end
555
555
  end
556
556
 
557
- describe "edit block" do
558
- it "should be able to replace the edit block" do
559
- buffer = @view.table_for @users[0,1] do |table|
560
- table.define :edit do
561
- "Edit Link"
562
- end
563
- table.column :edit
564
- end
565
-
566
- xml = XmlSimple.xml_in(%%
567
- <table>
568
- <thead><tr><th></th></tr></thead>
569
- <tbody><tr><td>Edit Link</td></tr></tbody>
570
- </table>%)
571
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
572
- end
573
-
574
- it "should be able to create an edit column" do
575
- @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
576
-
577
- buffer = @view.table_for @users[0,1] do |table|
578
- table.column :edit
579
- end
580
-
581
- xml = XmlSimple.xml_in(%%
582
- <table>
583
- <thead><tr><th></th></tr></thead>
584
- <tbody><tr><td><a href="/users/1/edit">Edit</a></td></tr></tbody>
585
- </table>%)
586
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
587
- end
588
-
589
- it "should be able to update the label for an edit column" do
590
- @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
591
-
592
- buffer = @view.table_for @users[0,1] do |table|
593
- table.column :edit, :link_label => "Modify"
594
- end
595
-
596
- xml = XmlSimple.xml_in(%%
597
- <table>
598
- <thead><tr><th></th></tr></thead>
599
- <tbody><tr><td><a href="/users/1/edit">Modify</a></td></tr></tbody>
600
- </table>%)
601
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
602
- end
603
-
604
- it "should be able to specify the action for an edit column" do
605
- @view.expects(:modify_user_path).with(User.first).returns("/users/1/modify")
606
-
607
- buffer = @view.table_for @users[0,1] do |table|
608
- table.column :edit, :action => :modify
609
- end
610
-
611
- xml = XmlSimple.xml_in(%%
612
- <table>
613
- <thead><tr><th></th></tr></thead>
614
- <tbody><tr><td><a href="/users/1/modify">Edit</a></td></tr></tbody>
615
- </table>%)
616
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
617
- end
618
-
619
- it "should be able to specify the scope for an edit column" do
620
- @view.expects(:edit_user_test_user_path).with(User.last, User.first).returns("/users/3/test/users/1/edit")
621
-
622
- buffer = @view.table_for @users[0,1] do |table|
623
- table.column :edit, :scope => [User.last, :test]
624
- end
625
-
626
- xml = XmlSimple.xml_in(%%
627
- <table>
628
- <thead><tr><th></th></tr></thead>
629
- <tbody><tr><td><a href="/users/3/test/users/1/edit">Edit</a></td></tr></tbody>
630
- </table>%)
631
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
632
- end
633
-
634
- it "should be able to specify the html for an edit column" do
635
- @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
636
-
637
- buffer = @view.table_for @users[0,1] do |table|
638
- table.column :edit, :link_html => {:style => "color:red"}
639
- end
640
-
641
- xml = XmlSimple.xml_in(%%
642
- <table>
643
- <thead><tr><th></th></tr></thead>
644
- <tbody><tr><td><a href="/users/1/edit" style="color:red">Edit</a></td></tr></tbody>
645
- </table>%)
646
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
647
- end
648
- end
649
-
650
- describe "show block" do
651
- it "should be able to replace the show block" do
652
- buffer = @view.table_for @users[0,1] do |table|
653
- table.define :show do
654
- "Show Link"
655
- end
656
- table.column :show
657
- end
658
-
659
- xml = XmlSimple.xml_in(%%
660
- <table>
661
- <thead><tr><th></th></tr></thead>
662
- <tbody><tr><td>Show Link</td></tr></tbody>
663
- </table>%)
664
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
665
- end
666
-
667
- it "should be able to create a show column" do
668
- @view.expects(:user_path).with(User.first).returns("/users/1")
669
-
670
- buffer = @view.table_for @users[0,1] do |table|
671
- table.column :show
672
- end
673
-
674
- xml = XmlSimple.xml_in(%%
675
- <table>
676
- <thead><tr><th></th></tr></thead>
677
- <tbody><tr><td><a href="/users/1">Show</a></td></tr></tbody>
678
- </table>%)
679
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
680
- end
681
-
682
- it "should be able to update the label for an show column" do
683
- @view.expects(:user_path).with(User.first).returns("/users/1")
684
-
685
- buffer = @view.table_for @users[0,1] do |table|
686
- table.column :show, :link_label => "Display"
687
- end
688
-
689
- xml = XmlSimple.xml_in(%%
690
- <table>
691
- <thead><tr><th></th></tr></thead>
692
- <tbody><tr><td><a href="/users/1">Display</a></td></tr></tbody>
693
- </table>%)
694
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
695
- end
696
-
697
- it "should be able to specify the action for an show column" do
698
- @view.expects(:display_user_path).with(User.first).returns("/users/1/display")
699
-
700
- buffer = @view.table_for @users[0,1] do |table|
701
- table.column :show, :action => :display
702
- end
703
-
704
- xml = XmlSimple.xml_in(%%
705
- <table>
706
- <thead><tr><th></th></tr></thead>
707
- <tbody><tr><td><a href="/users/1/display">Show</a></td></tr></tbody>
708
- </table>%)
709
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
710
- end
711
-
712
- it "should be able to specify the scope for an show column" do
713
- @view.expects(:user_test_user_path).with(User.last, User.first).returns("/users/3/test/users/1")
714
-
715
- buffer = @view.table_for @users[0,1] do |table|
716
- table.column :show, :scope => [User.last, :test]
717
- end
718
-
719
- xml = XmlSimple.xml_in(%%
720
- <table>
721
- <thead><tr><th></th></tr></thead>
722
- <tbody><tr><td><a href="/users/3/test/users/1">Show</a></td></tr></tbody>
723
- </table>%)
724
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
725
- end
726
-
727
- it "should be able to specify the html for an show column" do
728
- @view.expects(:user_path).with(User.first).returns("/users/1")
729
-
730
- buffer = @view.table_for @users[0,1] do |table|
731
- table.column :show, :link_html => {:style => "color:red"}
732
- end
733
-
734
- xml = XmlSimple.xml_in(%%
735
- <table>
736
- <thead><tr><th></th></tr></thead>
737
- <tbody><tr><td><a href="/users/1" style="color:red">Show</a></td></tr></tbody>
738
- </table>%)
739
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
740
- end
741
- end
742
-
743
- describe "delete block" do
744
- it "should be able to replace the delete block" do
745
- buffer = @view.table_for @users[0,1] do |table|
746
- table.define :delete do
747
- "Delete Link"
748
- end
749
- table.column :delete
750
- end
751
-
752
- xml = XmlSimple.xml_in(%%
753
- <table>
754
- <thead><tr><th></th></tr></thead>
755
- <tbody><tr><td>Delete Link</td></tr></tbody>
756
- </table>%)
757
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
758
- end
759
-
760
- it "should be able to create a delete column" do
761
- @view.expects(:user_path).with(User.first).returns("/users/1")
762
-
763
- buffer = @view.table_for @users[0,1] do |table|
764
- table.column :delete
765
- end
766
-
767
- xml = XmlSimple.xml_in(%%
768
- <table>
769
- <thead><tr><th></th></tr></thead>
770
- <tbody>
771
- <tr>
772
- <td>
773
- <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
774
- </td>
775
- </tr>
776
- </tbody>
777
- </table>%)
778
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
779
- end
780
-
781
- it "should be able to update the label for an delete column" do
782
- @view.expects(:user_path).with(User.first).returns("/users/1")
783
-
784
- buffer = @view.table_for @users[0,1] do |table|
785
- table.column :delete, :link_label => "Destroy"
786
- end
787
-
788
- xml = XmlSimple.xml_in(%%
789
- <table>
790
- <thead><tr><th></th></tr></thead>
791
- <tbody>
792
- <tr>
793
- <td>
794
- <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Destroy</a>
795
- </td>
796
- </tr>
797
- </tbody>
798
- </table>%)
799
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
800
- end
801
-
802
- it "should be able to specify the action for an delete column" do
803
- @view.expects(:dispose_user_path).with(User.first).returns("/users/1/dispose")
804
-
805
- buffer = @view.table_for @users[0,1] do |table|
806
- table.column :delete, :action => :dispose
807
- end
808
-
809
- xml = XmlSimple.xml_in(%%
810
- <table>
811
- <thead><tr><th></th></tr></thead>
812
- <tbody>
813
- <tr>
814
- <td>
815
- <a href="/users/1/dispose" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
816
- </td>
817
- </tr>
818
- </tbody>
819
- </table>%)
820
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
821
- end
822
-
823
- it "should be able to specify the scope for a delete column" do
824
- @view.expects(:user_test_user_path).with(User.last, User.first).returns("/users/3/test/users/1")
825
-
826
- buffer = @view.table_for @users[0,1] do |table|
827
- table.column :delete, :scope => [User.last, :test]
828
- end
829
-
830
- xml = XmlSimple.xml_in(%%
831
- <table>
832
- <thead><tr><th></th></tr></thead>
833
- <tbody>
834
- <tr>
835
- <td>
836
- <a href="/users/3/test/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
837
- </td>
838
- </tr>
839
- </tbody>
840
- </table>%)
841
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
842
- end
843
-
844
- it "should be able to specify the html for a delete column" do
845
- @view.expects(:user_path).with(User.first).returns("/users/1")
846
-
847
- buffer = @view.table_for @users[0,1] do |table|
848
- table.column :delete, :link_html => {:style => "color:red"}
849
- end
850
-
851
- xml = XmlSimple.xml_in(%%
852
- <table>
853
- <thead><tr><th></th></tr></thead>
854
- <tbody>
855
- <tr>
856
- <td>
857
- <a href="/users/1" style="color:red" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
858
- </td>
859
- </tr>
860
- </tbody>
861
- </table>%)
862
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
863
- end
864
-
865
- it "should be able to override the delete confirmation message for a delete link" do
866
- @view.expects(:user_path).with(User.first).returns("/users/1")
867
-
868
- buffer = @view.table_for @users[0,1] do |table|
869
- table.column :delete, :confirm => "Are you sure?"
870
- end
871
-
872
- xml = XmlSimple.xml_in(%%
873
- <table>
874
- <thead><tr><th></th></tr></thead>
875
- <tbody>
876
- <tr>
877
- <td>
878
- <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure?">Delete</a>
879
- </td>
880
- </tr>
881
- </tbody>
882
- </table>%)
883
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
884
- end
885
-
886
- it "should be able to override the method for a delete link" do
887
- @view.expects(:user_path).with(User.first).returns("/users/1")
888
-
889
- buffer = @view.table_for @users[0,1] do |table|
890
- table.column :delete, :method => :get
891
- end
892
-
893
- xml = XmlSimple.xml_in(%%
894
- <table>
895
- <thead><tr><th></th></tr></thead>
896
- <tbody>
897
- <tr>
898
- <td>
899
- <a href="/users/1" data-method="get" data-confirm="Are you sure you want to delete this User?">Delete</a>
900
- </td>
901
- </tr>
902
- </tbody>
903
- </table>%)
904
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
905
- end
906
- end
557
+ # describe "edit block" do
558
+ # it "should be able to replace the edit block" do
559
+ # buffer = @view.table_for @users[0,1] do |table|
560
+ # table.define :edit do
561
+ # "Edit Link"
562
+ # end
563
+ # table.column :edit
564
+ # end
565
+ #
566
+ # xml = XmlSimple.xml_in(%%
567
+ # <table>
568
+ # <thead><tr><th></th></tr></thead>
569
+ # <tbody><tr><td>Edit Link</td></tr></tbody>
570
+ # </table>%)
571
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
572
+ # end
573
+ #
574
+ # it "should be able to create an edit column" do
575
+ # @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
576
+ #
577
+ # buffer = @view.table_for @users[0,1] do |table|
578
+ # table.column :edit
579
+ # end
580
+ #
581
+ # xml = XmlSimple.xml_in(%%
582
+ # <table>
583
+ # <thead><tr><th></th></tr></thead>
584
+ # <tbody><tr><td><a href="/users/1/edit">Edit</a></td></tr></tbody>
585
+ # </table>%)
586
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
587
+ # end
588
+ #
589
+ # it "should be able to update the label for an edit column" do
590
+ # @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
591
+ #
592
+ # buffer = @view.table_for @users[0,1] do |table|
593
+ # table.column :edit, :data => "Modify"
594
+ # end
595
+ #
596
+ # xml = XmlSimple.xml_in(%%
597
+ # <table>
598
+ # <thead><tr><th></th></tr></thead>
599
+ # <tbody><tr><td><a href="/users/1/edit">Modify</a></td></tr></tbody>
600
+ # </table>%)
601
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
602
+ # end
603
+ #
604
+ # it "should be able to specify the action for an edit column" do
605
+ # @view.expects(:modify_user_path).with(User.first).returns("/users/1/modify")
606
+ #
607
+ # buffer = @view.table_for @users[0,1] do |table|
608
+ # table.column :edit, :action => :modify
609
+ # end
610
+ #
611
+ # xml = XmlSimple.xml_in(%%
612
+ # <table>
613
+ # <thead><tr><th></th></tr></thead>
614
+ # <tbody><tr><td><a href="/users/1/modify">Edit</a></td></tr></tbody>
615
+ # </table>%)
616
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
617
+ # end
618
+ #
619
+ # it "should be able to specify the scope for an edit column" do
620
+ # @view.expects(:edit_user_test_user_path).with(User.last, User.first).returns("/users/3/test/users/1/edit")
621
+ #
622
+ # buffer = @view.table_for @users[0,1] do |table|
623
+ # table.column :edit, :scope => [User.last, :test]
624
+ # end
625
+ #
626
+ # xml = XmlSimple.xml_in(%%
627
+ # <table>
628
+ # <thead><tr><th></th></tr></thead>
629
+ # <tbody><tr><td><a href="/users/3/test/users/1/edit">Edit</a></td></tr></tbody>
630
+ # </table>%)
631
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
632
+ # end
633
+ #
634
+ # it "should be able to specify the html for an edit column" do
635
+ # @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
636
+ #
637
+ # buffer = @view.table_for @users[0,1] do |table|
638
+ # table.column :edit, :link_html => {:style => "color:red"}
639
+ # end
640
+ #
641
+ # xml = XmlSimple.xml_in(%%
642
+ # <table>
643
+ # <thead><tr><th></th></tr></thead>
644
+ # <tbody><tr><td><a href="/users/1/edit" style="color:red">Edit</a></td></tr></tbody>
645
+ # </table>%)
646
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
647
+ # end
648
+ # end
649
+ #
650
+ # describe "show block" do
651
+ # it "should be able to replace the show block" do
652
+ # buffer = @view.table_for @users[0,1] do |table|
653
+ # table.define :show do
654
+ # "Show Link"
655
+ # end
656
+ # table.column :show
657
+ # end
658
+ #
659
+ # xml = XmlSimple.xml_in(%%
660
+ # <table>
661
+ # <thead><tr><th></th></tr></thead>
662
+ # <tbody><tr><td>Show Link</td></tr></tbody>
663
+ # </table>%)
664
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
665
+ # end
666
+ #
667
+ # it "should be able to create a show column" do
668
+ # @view.expects(:user_path).with(User.first).returns("/users/1")
669
+ #
670
+ # buffer = @view.table_for @users[0,1] do |table|
671
+ # table.column :show
672
+ # end
673
+ #
674
+ # xml = XmlSimple.xml_in(%%
675
+ # <table>
676
+ # <thead><tr><th></th></tr></thead>
677
+ # <tbody><tr><td><a href="/users/1">Show</a></td></tr></tbody>
678
+ # </table>%)
679
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
680
+ # end
681
+ #
682
+ # it "should be able to update the label for an show column" do
683
+ # @view.expects(:user_path).with(User.first).returns("/users/1")
684
+ #
685
+ # buffer = @view.table_for @users[0,1] do |table|
686
+ # table.column :show, :data => "Display"
687
+ # end
688
+ #
689
+ # xml = XmlSimple.xml_in(%%
690
+ # <table>
691
+ # <thead><tr><th></th></tr></thead>
692
+ # <tbody><tr><td><a href="/users/1">Display</a></td></tr></tbody>
693
+ # </table>%)
694
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
695
+ # end
696
+ #
697
+ # it "should be able to specify the action for an show column" do
698
+ # @view.expects(:display_user_path).with(User.first).returns("/users/1/display")
699
+ #
700
+ # buffer = @view.table_for @users[0,1] do |table|
701
+ # table.column :show, :action => :display
702
+ # end
703
+ #
704
+ # xml = XmlSimple.xml_in(%%
705
+ # <table>
706
+ # <thead><tr><th></th></tr></thead>
707
+ # <tbody><tr><td><a href="/users/1/display">Show</a></td></tr></tbody>
708
+ # </table>%)
709
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
710
+ # end
711
+ #
712
+ # it "should be able to specify the scope for an show column" do
713
+ # @view.expects(:user_test_user_path).with(User.last, User.first).returns("/users/3/test/users/1")
714
+ #
715
+ # buffer = @view.table_for @users[0,1] do |table|
716
+ # table.column :show, :scope => [User.last, :test]
717
+ # end
718
+ #
719
+ # xml = XmlSimple.xml_in(%%
720
+ # <table>
721
+ # <thead><tr><th></th></tr></thead>
722
+ # <tbody><tr><td><a href="/users/3/test/users/1">Show</a></td></tr></tbody>
723
+ # </table>%)
724
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
725
+ # end
726
+ #
727
+ # it "should be able to specify the html for an show column" do
728
+ # @view.expects(:user_path).with(User.first).returns("/users/1")
729
+ #
730
+ # buffer = @view.table_for @users[0,1] do |table|
731
+ # table.column :show, :link_html => {:style => "color:red"}
732
+ # end
733
+ #
734
+ # xml = XmlSimple.xml_in(%%
735
+ # <table>
736
+ # <thead><tr><th></th></tr></thead>
737
+ # <tbody><tr><td><a href="/users/1" style="color:red">Show</a></td></tr></tbody>
738
+ # </table>%)
739
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
740
+ # end
741
+ # end
742
+ #
743
+ # describe "delete block" do
744
+ # it "should be able to replace the delete block" do
745
+ # buffer = @view.table_for @users[0,1] do |table|
746
+ # table.define :delete do
747
+ # "Delete Link"
748
+ # end
749
+ # table.column :delete
750
+ # end
751
+ #
752
+ # xml = XmlSimple.xml_in(%%
753
+ # <table>
754
+ # <thead><tr><th></th></tr></thead>
755
+ # <tbody><tr><td>Delete Link</td></tr></tbody>
756
+ # </table>%)
757
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
758
+ # end
759
+ #
760
+ # it "should be able to create a delete column" do
761
+ # @view.expects(:user_path).with(User.first).returns("/users/1")
762
+ #
763
+ # buffer = @view.table_for @users[0,1] do |table|
764
+ # table.column :delete
765
+ # end
766
+ #
767
+ # xml = XmlSimple.xml_in(%%
768
+ # <table>
769
+ # <thead><tr><th></th></tr></thead>
770
+ # <tbody>
771
+ # <tr>
772
+ # <td>
773
+ # <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
774
+ # </td>
775
+ # </tr>
776
+ # </tbody>
777
+ # </table>%)
778
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
779
+ # end
780
+ #
781
+ # it "should be able to update the label for an delete column" do
782
+ # @view.expects(:user_path).with(User.first).returns("/users/1")
783
+ #
784
+ # buffer = @view.table_for @users[0,1] do |table|
785
+ # table.column :delete, :data => "Destroy"
786
+ # end
787
+ #
788
+ # xml = XmlSimple.xml_in(%%
789
+ # <table>
790
+ # <thead><tr><th></th></tr></thead>
791
+ # <tbody>
792
+ # <tr>
793
+ # <td>
794
+ # <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Destroy</a>
795
+ # </td>
796
+ # </tr>
797
+ # </tbody>
798
+ # </table>%)
799
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
800
+ # end
801
+ #
802
+ # it "should be able to specify the action for an delete column" do
803
+ # @view.expects(:dispose_user_path).with(User.first).returns("/users/1/dispose")
804
+ #
805
+ # buffer = @view.table_for @users[0,1] do |table|
806
+ # table.column :delete, :action => :dispose
807
+ # end
808
+ #
809
+ # xml = XmlSimple.xml_in(%%
810
+ # <table>
811
+ # <thead><tr><th></th></tr></thead>
812
+ # <tbody>
813
+ # <tr>
814
+ # <td>
815
+ # <a href="/users/1/dispose" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
816
+ # </td>
817
+ # </tr>
818
+ # </tbody>
819
+ # </table>%)
820
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
821
+ # end
822
+ #
823
+ # it "should be able to specify the scope for a delete column" do
824
+ # @view.expects(:user_test_user_path).with(User.last, User.first).returns("/users/3/test/users/1")
825
+ #
826
+ # buffer = @view.table_for @users[0,1] do |table|
827
+ # table.column :delete, :scope => [User.last, :test]
828
+ # end
829
+ #
830
+ # xml = XmlSimple.xml_in(%%
831
+ # <table>
832
+ # <thead><tr><th></th></tr></thead>
833
+ # <tbody>
834
+ # <tr>
835
+ # <td>
836
+ # <a href="/users/3/test/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
837
+ # </td>
838
+ # </tr>
839
+ # </tbody>
840
+ # </table>%)
841
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
842
+ # end
843
+ #
844
+ # it "should be able to specify the html for a delete column" do
845
+ # @view.expects(:user_path).with(User.first).returns("/users/1")
846
+ #
847
+ # buffer = @view.table_for @users[0,1] do |table|
848
+ # table.column :delete, :link_html => {:style => "color:red"}
849
+ # end
850
+ #
851
+ # xml = XmlSimple.xml_in(%%
852
+ # <table>
853
+ # <thead><tr><th></th></tr></thead>
854
+ # <tbody>
855
+ # <tr>
856
+ # <td>
857
+ # <a href="/users/1" style="color:red" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
858
+ # </td>
859
+ # </tr>
860
+ # </tbody>
861
+ # </table>%)
862
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
863
+ # end
864
+ #
865
+ # it "should be able to override the delete confirmation message for a delete link" do
866
+ # @view.expects(:user_path).with(User.first).returns("/users/1")
867
+ #
868
+ # buffer = @view.table_for @users[0,1] do |table|
869
+ # table.column :delete, :confirm => "Are you sure?"
870
+ # end
871
+ #
872
+ # xml = XmlSimple.xml_in(%%
873
+ # <table>
874
+ # <thead><tr><th></th></tr></thead>
875
+ # <tbody>
876
+ # <tr>
877
+ # <td>
878
+ # <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure?">Delete</a>
879
+ # </td>
880
+ # </tr>
881
+ # </tbody>
882
+ # </table>%)
883
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
884
+ # end
885
+ #
886
+ # it "should be able to override the method for a delete link" do
887
+ # @view.expects(:user_path).with(User.first).returns("/users/1")
888
+ #
889
+ # buffer = @view.table_for @users[0,1] do |table|
890
+ # table.column :delete, :method => :get
891
+ # end
892
+ #
893
+ # xml = XmlSimple.xml_in(%%
894
+ # <table>
895
+ # <thead><tr><th></th></tr></thead>
896
+ # <tbody>
897
+ # <tr>
898
+ # <td>
899
+ # <a href="/users/1" data-method="get" data-confirm="Are you sure you want to delete this User?">Delete</a>
900
+ # </td>
901
+ # </tr>
902
+ # </tbody>
903
+ # </table>%)
904
+ # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
905
+ # end
906
+ # end
907
907
 
908
908
  describe "column data contents block" do
909
909
  it "should be able to replace an individual column data contents block" do
910
910
  buffer = @view.table_for @users[0,1] do |table|
911
- table.column :email, :label => "Email Address"
912
- table.column :label => "Full Name" do |user|
911
+ table.column :email, :header => "Email Address"
912
+ table.column :header => "Full Name" do |user|
913
913
  "#{user.first_name} #{user.last_name}"
914
914
  end
915
915
  end