table-for 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Y2Q4OGZmYWRiNTc4Y2MwNDAyMmY3YzAxYmUxOGViMGVjZDg0NGFjNQ==
5
- data.tar.gz: !binary |-
6
- ZTY1ZGRlNTVlNjU3M2Q4NGE5ZjgxMDUxNzk5YTFhZjZiMzc5OTFkOQ==
2
+ SHA1:
3
+ metadata.gz: 8719b9d60d0575d808cd0e59db4da06669581cff
4
+ data.tar.gz: 5365a9d7259191c5b11895eb47320663a89b68c1
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YWVkYzU5MzNmOTlmZTIxZDcyOTk1MWY2NWViMDBjYmQxZDBmMjAzY2QxOGU4
10
- YzJiM2M5N2NiNGM5NmQzOTQwOWViNTJhZGQ2YTgxYzRmY2E0N2YzYTA2YmFi
11
- OTg3MzEyYjk0NzI5ODFlYmMxZGZkMDc2NTM3MGVhODEwMWVlYjI=
12
- data.tar.gz: !binary |-
13
- MThiNzAzYzg0Y2U5MGNjZmEwODQyMDcwMWU0MGQ4ZGU3YjFjYjhiOTY2OTQ4
14
- ZjU5ZTAyYjU2MWUxZTliYWI0MzFlM2NiZTg1ZDUyMDhlZTFhNGY3Y2ZkMmZk
15
- Y2Q4OTZjMmU0OTM5MWQyYjhjYzAxMzE5ZjE5NTRmOTUzMDAwMWQ=
6
+ metadata.gz: c4a894bbb863ca45c866c1710ea119cdf11abc2cf8355d907ff4f89a63e6ee83ea7495421f43fcf1a7335a9672186d4a098afec49a76ee0e94a0e2742e06d06e
7
+ data.tar.gz: 0a9e4f2628c39dfe85acd549ea1aee6553437b9fdc633489e377c196b63b50a35312471bff12752789392d542b5321af7503f6089351c0df66ec823e77c61309
@@ -0,0 +1,15 @@
1
+ continue
2
+ html2.gsub(/\s+/, "")
3
+ html1.gsub(/\s+/, "")
4
+ html1.gsub(/\s+/, " ").gsub("> ", ">").
5
+ html2.gsub(/\s+/, " ")
6
+ html1.gsub(/\s+/, " ")
7
+ html1
8
+ Nokogiri::XML(html1)
9
+ Nokogiri::XML(html1).to_s
10
+ Nokogiri::HTML(html1).to_s
11
+ Nokogiri::HTML(html1)
12
+ require 'nokogiri'
13
+ Nokogiri::HTML(html1)
14
+ continue
15
+ html1
@@ -1,3 +1,10 @@
1
+ 3.4.0
2
+ * Links options that are applied to a column will now generate the link even if you override
3
+ column. In haml, this example pointed out by @noctivityinc, now works:
4
+ = t.column link_action: :edit do
5
+ %i.fa.fa-pencil
6
+ * Fixed generation of link_confirm and link_method to apply to the links data element.
7
+
1
8
  3.2.1
2
9
  * Added ability to configure sort_mode order, i.e. if sort links generate sort_modes in :asc, :desc order, or have different labels
3
10
  than :asc and :desc
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gemspec
3
+ gemspec
data/Rakefile CHANGED
@@ -3,8 +3,6 @@ require 'bundler/gem_tasks'
3
3
 
4
4
  # Default directory to look in is `/specs`
5
5
  # Run with `rake spec`
6
- RSpec::Core::RakeTask.new(:spec) do |task|
7
- task.rspec_opts = ['--color', '--format', 'nested']
8
- end
6
+ RSpec::Core::RakeTask.new(:spec)
9
7
 
10
- task :default => :spec
8
+ task :default => :spec
@@ -71,4 +71,4 @@
71
71
  <% end %>
72
72
  <% end if table.defined?(:footer_content) %>
73
73
 
74
- <%= table.render :table %>
74
+ <%= table.render :table %>
@@ -4,7 +4,6 @@ require 'blocks'
4
4
  module TableFor
5
5
  class Base < WithTemplate::Base
6
6
  alias columns queued_blocks
7
- alias column queue
8
7
 
9
8
  attr_accessor :current_record
10
9
  alias_method :current_row, :current_record
@@ -21,6 +20,31 @@ module TableFor
21
20
  define(:footer_content, options, &block)
22
21
  end
23
22
 
23
+ def column(*args, &block)
24
+ options = args.extract_options!
25
+ queue(*args, options, &block)
26
+ if options[:link_url] ||
27
+ options[:link_action] ||
28
+ options[:link_method] ||
29
+ options[:link_confirm] ||
30
+ options[:link]
31
+ around(columns.last.name) do |content_block, record, column, options|
32
+ options = options.merge(column.options)
33
+ url = if options[:link_url]
34
+ call_with_params(options[:link_url], record)
35
+ else
36
+ [options[:link_action], options[:link_namespace], record].flatten.compact
37
+ end
38
+ html_options = {data: {}}
39
+ html_options[:data][:method] = options[:link_method] if options[:link_method].present?
40
+ html_options[:data][:confirm] = options[:link_confirm] if options[:link_confirm].present?
41
+ html_options = html_options.deep_merge(options[:link_html] || {})
42
+ view.link_to content_block.call, url, html_options
43
+ end
44
+ end
45
+ nil
46
+ end
47
+
24
48
  def header_column_html(column, options={})
25
49
  header_column_html = call_each_hash_value_with_params(options[:header_column_html], column)
26
50
  if options[:sortable]
@@ -51,26 +75,16 @@ module TableFor
51
75
  end
52
76
 
53
77
  def cell_content(record, column, options={})
54
- if options[:link_url] || options[:link_action] || options[:link_method] || options[:link_confirm] || options[:link]
55
- url = options[:link_url] ? call_with_params(options[:link_url], record) : [options[:link_action], options[:link_namespace], record].flatten
56
- end
57
-
58
78
  if options[:formatter]
59
79
  if options[:formatter].is_a?(Proc)
60
- content = call_with_params(options[:formatter], record.send(column.name), options)
80
+ call_with_params(options[:formatter], record.send(column.name), options)
61
81
  else
62
- content = record.send(column.name).try(*options[:formatter])
82
+ record.send(column.name).try(*options[:formatter])
63
83
  end
64
84
  elsif options[:data] || [:edit, :show, :delete].include?(column.name)
65
- content = call_with_params(options[:data], record)
85
+ call_with_params(options[:data], record)
66
86
  else
67
- content = record.send(column.name)
68
- end
69
-
70
- if content.blank? || url.blank? || options[:link] == false
71
- content
72
- elsif url
73
- view.link_to content, url, {:method => options[:link_method], :confirm => options[:link_confirm]}.merge(options[:link_html])
87
+ record.send(column.name)
74
88
  end
75
89
  end
76
90
 
@@ -114,4 +128,4 @@ module TableFor
114
128
  end
115
129
  end
116
130
  end
117
- end
131
+ end
@@ -1,3 +1,3 @@
1
1
  module TableFor
2
- VERSION = "3.3.0"
2
+ VERSION = "3.4.0"
3
3
  end
@@ -3,6 +3,7 @@ require "spec_helper"
3
3
  describe "table_for" do
4
4
  with_model :user do
5
5
  table do |t|
6
+ t.integer "id"
6
7
  t.string "email"
7
8
  t.string "first_name"
8
9
  t.string "last_name"
@@ -17,11 +18,14 @@ describe "table_for" do
17
18
  end
18
19
 
19
20
  before :each do
20
- User.create! :email => "andrew.hunter@livingsocial.com", :first_name => "Andrew", :last_name => "Hunter"
21
- User.create! :email => "todd.fisher@livingsocial.com", :first_name => "Todd", :last_name => "Fisher"
22
- User.create! :email => "jon.phillips@livingsocial.com", :first_name => "Jon", :last_name => "Phillips"
21
+ User.create! id: 1, :email => "andrew.hunter@livingsocial.com", :first_name => "Andrew", :last_name => "Hunter"
22
+ User.create! id: 2, :email => "todd.fisher@livingsocial.com", :first_name => "Todd", :last_name => "Fisher"
23
+ User.create! id: 3, :email => "jon.phillips@livingsocial.com", :first_name => "Jon", :last_name => "Phillips"
23
24
  @users = User.all
24
25
  @view = ActionView::Base.new("app/views")
26
+ @view.class.send(:define_method, :user_path) do |user|
27
+ "/users/#{user.id}"
28
+ end
25
29
  end
26
30
 
27
31
  it "should be able render a table with email and first and last name columns" do
@@ -59,8 +63,8 @@ describe "table_for" do
59
63
 
60
64
  it "should be able to specify html attributes" do
61
65
  buffer = @view.table_for @users, :table_html => {:style => "background-color: orange"}
62
- xml = XmlSimple.xml_in(%%<table style="background-color: orange"><thead><tr></tr></thead><tbody><tr></tr><tr></tr><tr></tr></tbody></table>%)
63
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
66
+ xml = XmlSimple.xml_in(%%<table style="background-color: orange"><thead><tr></tr></thead><tbody><tr></tr><tr></tr><tr></tr></tbody></table>%, keeproot: true)
67
+ XmlSimple.xml_in(buffer, normalisespace: 2, keeproot: true).should eql xml
64
68
  end
65
69
  end
66
70
 
@@ -162,12 +166,7 @@ describe "table_for" do
162
166
  table.column :last_name
163
167
  end
164
168
 
165
- xml = XmlSimple.xml_in(%%
166
- <table>
167
- <thead><tr><th>Repeated Column</th><th>Repeated Column</th></tr></thead>
168
- <tbody><tr><td>Andrew</td><td>Hunter</td></tr></tbody>
169
- </table>%)
170
- XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
169
+ html_includes?(buffer, "<thead><tr><th>Repeated Column</th><th>Repeated Column</th></tr></thead>")
171
170
  end
172
171
 
173
172
  it "should be able to specify html attributes" do
@@ -177,7 +176,7 @@ describe "table_for" do
177
176
  xml = XmlSimple.xml_in(%%<table><thead><tr><th class="sortable">First Name</th></tr></thead><tbody><tr><td>Andrew</td></tr></tbody></table>%)
178
177
  XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
179
178
  end
180
-
179
+
181
180
  it "should be able to dynamically specify column attributes" do
182
181
  buffer = @view.table_for @users[0, 1], :header_column_html => {:class => lambda {@view.cycle("even", "odd")},
183
182
  :id => lambda {|column| "#{column.name.to_s}_header"}} do |table|
@@ -201,81 +200,6 @@ describe "table_for" do
201
200
  XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
202
201
  end
203
202
  end
204
-
205
- # describe "edit_header block" do
206
- # it "should be able to replace the edit_header block" do
207
- # @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
208
- # buffer = @view.table_for @users[0,1] do |table|
209
- # table.define :edit_header do
210
- # "Edit"
211
- # end
212
- # table.column :edit
213
- # end
214
- #
215
- # xml = XmlSimple.xml_in(%%
216
- # <table>
217
- # <thead><tr><th>Edit</th></tr></thead>
218
- # <tbody>
219
- # <tr>
220
- # <td>
221
- # <a href="/users/1/edit">Edit</a>
222
- # </td>
223
- # </tr>
224
- # </tbody>
225
- # </table>%)
226
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
227
- # end
228
- # end
229
- #
230
- # describe "delete_header block" do
231
- # it "should be able to replace the delete_header block" do
232
- # @view.expects(:user_path).with(User.first).returns("/users/1")
233
- # buffer = @view.table_for @users[0,1] do |table|
234
- # table.define :delete_header do
235
- # "Delete"
236
- # end
237
- # table.column :delete
238
- # end
239
- #
240
- # xml = XmlSimple.xml_in(%%
241
- # <table>
242
- # <thead><tr><th>Delete</th></tr></thead>
243
- # <tbody>
244
- # <tr>
245
- # <td>
246
- # <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
247
- # </td>
248
- # </tr>
249
- # </tbody>
250
- # </table>%)
251
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
252
- # end
253
- # end
254
- #
255
- # describe "show_header block" do
256
- # it "should be able to replace the show_header block" do
257
- # @view.expects(:user_path).with(User.first).returns("/users/1")
258
- # buffer = @view.table_for @users[0,1] do |table|
259
- # table.define :show_header do
260
- # "Show"
261
- # end
262
- # table.column :show
263
- # end
264
- #
265
- # xml = XmlSimple.xml_in(%%
266
- # <table>
267
- # <thead><tr><th>Show</th></tr></thead>
268
- # <tbody>
269
- # <tr>
270
- # <td>
271
- # <a href="/users/1">Show</a>
272
- # </td>
273
- # </tr>
274
- # </tbody>
275
- # </table>%)
276
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
277
- # end
278
- # end
279
203
 
280
204
  describe "column header contents block" do
281
205
  it "should be able to override the header for a particular column" do
@@ -563,7 +487,7 @@ describe "table_for" do
563
487
  xml = XmlSimple.xml_in(%%<table><thead><tr><th>First Name</th></tr></thead><tbody><tr><td class="data">Andrew</td></tr></tbody></table>%)
564
488
  XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
565
489
  end
566
-
490
+
567
491
  it "should be able to dynamically specify column attributes" do
568
492
  buffer = @view.table_for @users[0, 1], :data_column_html => {:class => lambda {@view.cycle("even", "odd")},
569
493
  :id => lambda {|user, column| "#{column.name.to_s}_data"}} do |table|
@@ -607,358 +531,23 @@ describe "table_for" do
607
531
  end
608
532
  end
609
533
 
610
- # describe "edit block" do
611
- # it "should be able to replace the edit block" do
612
- # buffer = @view.table_for @users[0,1] do |table|
613
- # table.define :edit do
614
- # "Edit Link"
615
- # end
616
- # table.column :edit
617
- # end
618
- #
619
- # xml = XmlSimple.xml_in(%%
620
- # <table>
621
- # <thead><tr><th></th></tr></thead>
622
- # <tbody><tr><td>Edit Link</td></tr></tbody>
623
- # </table>%)
624
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
625
- # end
626
- #
627
- # it "should be able to create an edit column" do
628
- # @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
629
- #
630
- # buffer = @view.table_for @users[0,1] do |table|
631
- # table.column :edit
632
- # end
633
- #
634
- # xml = XmlSimple.xml_in(%%
635
- # <table>
636
- # <thead><tr><th></th></tr></thead>
637
- # <tbody><tr><td><a href="/users/1/edit">Edit</a></td></tr></tbody>
638
- # </table>%)
639
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
640
- # end
641
- #
642
- # it "should be able to update the label for an edit column" do
643
- # @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
644
- #
645
- # buffer = @view.table_for @users[0,1] do |table|
646
- # table.column :edit, :data => "Modify"
647
- # end
648
- #
649
- # xml = XmlSimple.xml_in(%%
650
- # <table>
651
- # <thead><tr><th></th></tr></thead>
652
- # <tbody><tr><td><a href="/users/1/edit">Modify</a></td></tr></tbody>
653
- # </table>%)
654
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
655
- # end
656
- #
657
- # it "should be able to specify the action for an edit column" do
658
- # @view.expects(:modify_user_path).with(User.first).returns("/users/1/modify")
659
- #
660
- # buffer = @view.table_for @users[0,1] do |table|
661
- # table.column :edit, :action => :modify
662
- # end
663
- #
664
- # xml = XmlSimple.xml_in(%%
665
- # <table>
666
- # <thead><tr><th></th></tr></thead>
667
- # <tbody><tr><td><a href="/users/1/modify">Edit</a></td></tr></tbody>
668
- # </table>%)
669
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
670
- # end
671
- #
672
- # it "should be able to specify the scope for an edit column" do
673
- # @view.expects(:edit_user_test_user_path).with(User.last, User.first).returns("/users/3/test/users/1/edit")
674
- #
675
- # buffer = @view.table_for @users[0,1] do |table|
676
- # table.column :edit, :scope => [User.last, :test]
677
- # end
678
- #
679
- # xml = XmlSimple.xml_in(%%
680
- # <table>
681
- # <thead><tr><th></th></tr></thead>
682
- # <tbody><tr><td><a href="/users/3/test/users/1/edit">Edit</a></td></tr></tbody>
683
- # </table>%)
684
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
685
- # end
686
- #
687
- # it "should be able to specify the html for an edit column" do
688
- # @view.expects(:edit_user_path).with(User.first).returns("/users/1/edit")
689
- #
690
- # buffer = @view.table_for @users[0,1] do |table|
691
- # table.column :edit, :link_html => {:style => "color:red"}
692
- # end
693
- #
694
- # xml = XmlSimple.xml_in(%%
695
- # <table>
696
- # <thead><tr><th></th></tr></thead>
697
- # <tbody><tr><td><a href="/users/1/edit" style="color:red">Edit</a></td></tr></tbody>
698
- # </table>%)
699
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
700
- # end
701
- # end
702
- #
703
- # describe "show block" do
704
- # it "should be able to replace the show block" do
705
- # buffer = @view.table_for @users[0,1] do |table|
706
- # table.define :show do
707
- # "Show Link"
708
- # end
709
- # table.column :show
710
- # end
711
- #
712
- # xml = XmlSimple.xml_in(%%
713
- # <table>
714
- # <thead><tr><th></th></tr></thead>
715
- # <tbody><tr><td>Show Link</td></tr></tbody>
716
- # </table>%)
717
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
718
- # end
719
- #
720
- # it "should be able to create a show column" do
721
- # @view.expects(:user_path).with(User.first).returns("/users/1")
722
- #
723
- # buffer = @view.table_for @users[0,1] do |table|
724
- # table.column :show
725
- # end
726
- #
727
- # xml = XmlSimple.xml_in(%%
728
- # <table>
729
- # <thead><tr><th></th></tr></thead>
730
- # <tbody><tr><td><a href="/users/1">Show</a></td></tr></tbody>
731
- # </table>%)
732
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
733
- # end
734
- #
735
- # it "should be able to update the label for an show column" do
736
- # @view.expects(:user_path).with(User.first).returns("/users/1")
737
- #
738
- # buffer = @view.table_for @users[0,1] do |table|
739
- # table.column :show, :data => "Display"
740
- # end
741
- #
742
- # xml = XmlSimple.xml_in(%%
743
- # <table>
744
- # <thead><tr><th></th></tr></thead>
745
- # <tbody><tr><td><a href="/users/1">Display</a></td></tr></tbody>
746
- # </table>%)
747
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
748
- # end
749
- #
750
- # it "should be able to specify the action for an show column" do
751
- # @view.expects(:display_user_path).with(User.first).returns("/users/1/display")
752
- #
753
- # buffer = @view.table_for @users[0,1] do |table|
754
- # table.column :show, :action => :display
755
- # end
756
- #
757
- # xml = XmlSimple.xml_in(%%
758
- # <table>
759
- # <thead><tr><th></th></tr></thead>
760
- # <tbody><tr><td><a href="/users/1/display">Show</a></td></tr></tbody>
761
- # </table>%)
762
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
763
- # end
764
- #
765
- # it "should be able to specify the scope for an show column" do
766
- # @view.expects(:user_test_user_path).with(User.last, User.first).returns("/users/3/test/users/1")
767
- #
768
- # buffer = @view.table_for @users[0,1] do |table|
769
- # table.column :show, :scope => [User.last, :test]
770
- # end
771
- #
772
- # xml = XmlSimple.xml_in(%%
773
- # <table>
774
- # <thead><tr><th></th></tr></thead>
775
- # <tbody><tr><td><a href="/users/3/test/users/1">Show</a></td></tr></tbody>
776
- # </table>%)
777
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
778
- # end
779
- #
780
- # it "should be able to specify the html for an show column" do
781
- # @view.expects(:user_path).with(User.first).returns("/users/1")
782
- #
783
- # buffer = @view.table_for @users[0,1] do |table|
784
- # table.column :show, :link_html => {:style => "color:red"}
785
- # end
786
- #
787
- # xml = XmlSimple.xml_in(%%
788
- # <table>
789
- # <thead><tr><th></th></tr></thead>
790
- # <tbody><tr><td><a href="/users/1" style="color:red">Show</a></td></tr></tbody>
791
- # </table>%)
792
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
793
- # end
794
- # end
795
- #
796
- # describe "delete block" do
797
- # it "should be able to replace the delete block" do
798
- # buffer = @view.table_for @users[0,1] do |table|
799
- # table.define :delete do
800
- # "Delete Link"
801
- # end
802
- # table.column :delete
803
- # end
804
- #
805
- # xml = XmlSimple.xml_in(%%
806
- # <table>
807
- # <thead><tr><th></th></tr></thead>
808
- # <tbody><tr><td>Delete Link</td></tr></tbody>
809
- # </table>%)
810
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
811
- # end
812
- #
813
- # it "should be able to create a delete column" do
814
- # @view.expects(:user_path).with(User.first).returns("/users/1")
815
- #
816
- # buffer = @view.table_for @users[0,1] do |table|
817
- # table.column :delete
818
- # end
819
- #
820
- # xml = XmlSimple.xml_in(%%
821
- # <table>
822
- # <thead><tr><th></th></tr></thead>
823
- # <tbody>
824
- # <tr>
825
- # <td>
826
- # <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
827
- # </td>
828
- # </tr>
829
- # </tbody>
830
- # </table>%)
831
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
832
- # end
833
- #
834
- # it "should be able to update the label for an delete column" do
835
- # @view.expects(:user_path).with(User.first).returns("/users/1")
836
- #
837
- # buffer = @view.table_for @users[0,1] do |table|
838
- # table.column :delete, :data => "Destroy"
839
- # end
840
- #
841
- # xml = XmlSimple.xml_in(%%
842
- # <table>
843
- # <thead><tr><th></th></tr></thead>
844
- # <tbody>
845
- # <tr>
846
- # <td>
847
- # <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Destroy</a>
848
- # </td>
849
- # </tr>
850
- # </tbody>
851
- # </table>%)
852
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
853
- # end
854
- #
855
- # it "should be able to specify the action for an delete column" do
856
- # @view.expects(:dispose_user_path).with(User.first).returns("/users/1/dispose")
857
- #
858
- # buffer = @view.table_for @users[0,1] do |table|
859
- # table.column :delete, :action => :dispose
860
- # end
861
- #
862
- # xml = XmlSimple.xml_in(%%
863
- # <table>
864
- # <thead><tr><th></th></tr></thead>
865
- # <tbody>
866
- # <tr>
867
- # <td>
868
- # <a href="/users/1/dispose" rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this User?">Delete</a>
869
- # </td>
870
- # </tr>
871
- # </tbody>
872
- # </table>%)
873
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
874
- # end
875
- #
876
- # it "should be able to specify the scope for a delete column" do
877
- # @view.expects(:user_test_user_path).with(User.last, User.first).returns("/users/3/test/users/1")
878
- #
879
- # buffer = @view.table_for @users[0,1] do |table|
880
- # table.column :delete, :scope => [User.last, :test]
881
- # end
882
- #
883
- # xml = XmlSimple.xml_in(%%
884
- # <table>
885
- # <thead><tr><th></th></tr></thead>
886
- # <tbody>
887
- # <tr>
888
- # <td>
889
- # <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>
890
- # </td>
891
- # </tr>
892
- # </tbody>
893
- # </table>%)
894
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
895
- # end
896
- #
897
- # it "should be able to specify the html for a delete column" do
898
- # @view.expects(:user_path).with(User.first).returns("/users/1")
899
- #
900
- # buffer = @view.table_for @users[0,1] do |table|
901
- # table.column :delete, :link_html => {:style => "color:red"}
902
- # end
903
- #
904
- # xml = XmlSimple.xml_in(%%
905
- # <table>
906
- # <thead><tr><th></th></tr></thead>
907
- # <tbody>
908
- # <tr>
909
- # <td>
910
- # <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>
911
- # </td>
912
- # </tr>
913
- # </tbody>
914
- # </table>%)
915
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
916
- # end
917
- #
918
- # it "should be able to override the delete confirmation message for a delete link" do
919
- # @view.expects(:user_path).with(User.first).returns("/users/1")
920
- #
921
- # buffer = @view.table_for @users[0,1] do |table|
922
- # table.column :delete, :confirm => "Are you sure?"
923
- # end
924
- #
925
- # xml = XmlSimple.xml_in(%%
926
- # <table>
927
- # <thead><tr><th></th></tr></thead>
928
- # <tbody>
929
- # <tr>
930
- # <td>
931
- # <a href="/users/1" rel="nofollow" data-method="delete" data-confirm="Are you sure?">Delete</a>
932
- # </td>
933
- # </tr>
934
- # </tbody>
935
- # </table>%)
936
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
937
- # end
938
- #
939
- # it "should be able to override the method for a delete link" do
940
- # @view.expects(:user_path).with(User.first).returns("/users/1")
941
- #
942
- # buffer = @view.table_for @users[0,1] do |table|
943
- # table.column :delete, :method => :get
944
- # end
945
- #
946
- # xml = XmlSimple.xml_in(%%
947
- # <table>
948
- # <thead><tr><th></th></tr></thead>
949
- # <tbody>
950
- # <tr>
951
- # <td>
952
- # <a href="/users/1" data-method="get" data-confirm="Are you sure you want to delete this User?">Delete</a>
953
- # </td>
954
- # </tr>
955
- # </tbody>
956
- # </table>%)
957
- # XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
958
- # end
959
- # end
960
-
961
534
  describe "column data contents block" do
535
+ context "when passing a link param" do
536
+ it "render a link surrounding a table cell's content when it is true" do
537
+ buffer = @view.table_for @users do |table|
538
+ table.column :email, link: true
539
+ end
540
+ html_includes?(buffer, "<a href='/users/1'>andrew.hunter@livingsocial.com</a>")
541
+ end
542
+ end
543
+
544
+ it "should allow a link_url proc to render a link surrounding a table cell's content" do
545
+ buffer = @view.table_for @users do |table|
546
+ table.column :email, link_url: lambda {|user| "/admin/users/#{user.id}"}
547
+ end
548
+ html_includes?(buffer, "<a href='/admin/users/1'>andrew.hunter@livingsocial.com</a>")
549
+ end
550
+
962
551
  it "should be able to replace an individual column data contents block" do
963
552
  buffer = @view.table_for @users[0,1] do |table|
964
553
  table.column :email, :header => "Email Address"
@@ -975,4 +564,4 @@ describe "table_for" do
975
564
  XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
976
565
  end
977
566
  end
978
- end
567
+ end
@@ -9,7 +9,7 @@ require 'xmlsimple'
9
9
  require 'active_record'
10
10
  require 'active_support/all'
11
11
  require 'with_model'
12
- require 'ruby-debug'
12
+ require 'byebug'
13
13
 
14
14
  def print_hash(hash)
15
15
  hash.inject("") { |s, (k, v)| "#{s} #{k}: #{v}." }
@@ -19,4 +19,12 @@ RSpec.configure do |config|
19
19
  config.extend WithModel
20
20
  config.mock_with :mocha
21
21
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
22
- end
22
+ end
23
+
24
+ def normalize_html(html)
25
+ html.gsub(/\s+/, "").gsub(/\"/, "'")
26
+ end
27
+
28
+ def html_includes?(html1, html2)
29
+ normalize_html(html1).should include normalize_html(html2)
30
+ end
@@ -4,7 +4,7 @@ describe TableFor::Base do
4
4
  before(:each) do
5
5
  @view_class = Class.new
6
6
  @view = @view_class.new
7
- @view_class.send(:include, Blocks::ViewAdditions::ClassMethods)
7
+ @view_class.send(:include, Blocks::ViewAdditions)
8
8
  @base = TableFor::Base.new(@view)
9
9
  @records = [OpenStruct.new(:id => 1)]
10
10
  @column = stub(:name => :my_column, :anonymous => false)
@@ -61,10 +61,6 @@ describe TableFor::Base do
61
61
  end
62
62
  end
63
63
 
64
- # describe "#table_html" do
65
- #
66
- # end
67
-
68
64
  describe "#header_column_html" do
69
65
  it "should return an empty hash if header_column_html is not passed in" do
70
66
  header_column_html = @base.header_column_html(@column)
@@ -148,4 +144,4 @@ describe TableFor::Base do
148
144
  @base.header_sort_link(@column, :sortable => true) { @column.name.to_s.titleize }.should eql "my link"
149
145
  end
150
146
  end
151
- end
147
+ end
@@ -6,7 +6,7 @@ describe TableFor::ViewAdditions do
6
6
  @view = @view_class.new
7
7
  @view_class.send(:include, ActionView::Helpers::TextHelper)
8
8
  @view_class.send(:include, TableFor::ViewAdditions::ClassMethods)
9
- @view_class.send(:include, Blocks::ViewAdditions::ClassMethods)
9
+ @view_class.send(:include, Blocks::ViewAdditions)
10
10
  @records = [OpenStruct.new(:id => 1)]
11
11
  @column = stub(:name => :my_column)
12
12
  end
@@ -42,4 +42,4 @@ describe TableFor::ViewAdditions do
42
42
  @view.table_for(@records, :option1 => 1, :option2 => "2")
43
43
  end
44
44
  end
45
- end
45
+ end
@@ -19,13 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "rails", ">= 3.0.0"
22
- spec.add_dependency "with_template", "~> 0.0.6"
22
+ spec.add_dependency "with_template", "~> 0.1.0"
23
23
 
24
24
  spec.add_development_dependency "rspec-rails", ">= 2.0.0.beta.20"
25
25
  spec.add_development_dependency "mocha", "0.10.3"
26
26
  spec.add_development_dependency "xml-simple", "1.1.1"
27
- spec.add_development_dependency "supermodel", "0.1.4"
27
+ spec.add_development_dependency "supermodel"
28
28
  spec.add_development_dependency "sqlite3"
29
- spec.add_development_dependency "with_model", "0.2.6"
30
- spec.add_development_dependency "debugger"
29
+ spec.add_development_dependency "with_model"
30
+ spec.add_development_dependency "byebug"
31
+ spec.add_development_dependency "nokogiri"
31
32
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table-for
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Hunter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-21 00:00:00.000000000 Z
11
+ date: 2015-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: with_template
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.6
33
+ version: 0.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.6
40
+ version: 0.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.0.0.beta.20
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.0.0.beta.20
55
55
  - !ruby/object:Gem::Dependency
@@ -84,56 +84,70 @@ dependencies:
84
84
  name: supermodel
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 0.1.4
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 0.1.4
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sqlite3
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: with_model
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 0.2.6
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 0.2.6
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
- name: debugger
140
+ name: nokogiri
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - ! '>='
143
+ - - ">="
130
144
  - !ruby/object:Gem::Version
131
145
  version: '0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - ! '>='
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
153
  description: table-for is a table builder for an array of objects, easily allowing
@@ -144,10 +158,8 @@ executables: []
144
158
  extensions: []
145
159
  extra_rdoc_files: []
146
160
  files:
147
- - .gitignore
148
- - .rspec
149
- - .ruby-gemset
150
- - .ruby-version
161
+ - ".byebug_history"
162
+ - ".gitignore"
151
163
  - CHANGELOG.rdoc
152
164
  - Gemfile
153
165
  - Gemfile.lock
@@ -178,17 +190,17 @@ require_paths:
178
190
  - lib
179
191
  required_ruby_version: !ruby/object:Gem::Requirement
180
192
  requirements:
181
- - - ! '>='
193
+ - - ">="
182
194
  - !ruby/object:Gem::Version
183
195
  version: '0'
184
196
  required_rubygems_version: !ruby/object:Gem::Requirement
185
197
  requirements:
186
- - - ! '>='
198
+ - - ">="
187
199
  - !ruby/object:Gem::Version
188
200
  version: '0'
189
201
  requirements: []
190
202
  rubyforge_project:
191
- rubygems_version: 2.2.2
203
+ rubygems_version: 2.4.8
192
204
  signing_key:
193
205
  specification_version: 4
194
206
  summary: table-for is a table builder for an array of objects, easily allowing overriding
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --colour
2
- --backtrace
@@ -1 +0,0 @@
1
- table-for
@@ -1 +0,0 @@
1
- 1.9.3