table-for 3.4.1 → 3.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3533f2825ffff2f3b66f417e90842b92cf0aa7b
4
- data.tar.gz: f289fb64ff8ee7bc3325193caad41cd14dba36ba
3
+ metadata.gz: b9751a4f3656971cf37a04524b681722bfc6fcf1
4
+ data.tar.gz: d77d7951df1fa1f1bd74da3150fb3d6f992fcab3
5
5
  SHA512:
6
- metadata.gz: 87a9393fb42dd5506b3c2ea181703b0d048c181f7d4e40b7cf8b13438d35b04f2d6b5d681bee59e555877fc6d061df40abffe61284fcf93cad3ccb0c5611d3f4
7
- data.tar.gz: 7d084afb99618c8f1b5952de9020ae821ff313b807d3e7f9d833ddb4e2b4f8361033aefa99dbb6cc8608b01c5ea54e937b65b05a7753b085f8285ea990bd649d
6
+ metadata.gz: 97340910721e9cda2be1ae4b0f1f5a39eefb55cb5b555d2c222340a17a138376ad15b61da245e7f0b23b295a45dbb1d9c3ba8a72c0523a02961f1990b5652d5d
7
+ data.tar.gz: d2138119120ae4125872b464f6bc413106a522a8be157e838527b1f269a61380f2a3c948220af5676d5c49e9eb7353de19bd95561234b557db629a1da7c5e00a
@@ -1,3 +1,12 @@
1
+ 3.5.0
2
+ * table_for now keeps track of the current index of the row being render, per
3
+ suggestion by @jlfy. Example:
4
+ <%= table_for @users do |table| %>
5
+ <% table.column :id do |user| %>
6
+ "User id #{user.id} rendering with row index #{table.current_index}"
7
+ <% end %>
8
+ <% end %>
9
+
1
10
  3.4.1
2
11
  * Fixed bug introduced in version 3.4.0 where link_namespace defined globally
3
12
  on the table_for call was getting completely ignored. Thanks @panyamin for reporting.
@@ -36,7 +36,7 @@
36
36
  <% end %>
37
37
 
38
38
  <% table.define :data_row do |record, options| %>
39
- <% table.set_current_record(record) %>
39
+ <% table.set_current_record_and_index(record, options[:current_index]) %>
40
40
  <%= content_tag :tr, table.call_each_hash_value_with_params(options[:data_row_html], record) do %>
41
41
  <%= table.render :data_column, record, :collection => table.columns %>
42
42
  <% end %>
@@ -8,6 +8,10 @@ module TableFor
8
8
  attr_accessor :current_record
9
9
  alias_method :current_row, :current_record
10
10
 
11
+ attr_accessor :current_index
12
+ alias_method :current_row_index, :current_index
13
+
14
+
11
15
  def initialize(view, options={})
12
16
  super(view, TableFor.config.merge(options))
13
17
  end
@@ -92,8 +96,9 @@ module TableFor
92
96
  end
93
97
  end
94
98
 
95
- def set_current_record(record)
99
+ def set_current_record_and_index(record, index)
96
100
  self.current_record = record
101
+ self.current_index = index
97
102
  end
98
103
 
99
104
  def header_sort_link(column, options={}, &block)
@@ -1,3 +1,3 @@
1
1
  module TableFor
2
- VERSION = "3.4.1"
2
+ VERSION = "3.5.0"
3
3
  end
@@ -529,6 +529,17 @@ describe "table_for" do
529
529
  </table>%)
530
530
  XmlSimple.xml_in(buffer, 'NormaliseSpace' => 2).should eql xml
531
531
  end
532
+
533
+ it "should be able to use the table's current_index in a cell's data_column_html" do
534
+ buffer = @view.table_for @users do |table|
535
+ table.column :id, data_column_html: {
536
+ class: lambda { |record| "column-for-row-#{table.current_index}"
537
+ }
538
+ }
539
+ end
540
+ html_includes?(buffer, "<td class='column-for-row-0'>1</td>")
541
+ html_includes?(buffer, "<td class='column-for-row-1'>2</td>")
542
+ end
532
543
  end
533
544
 
534
545
  describe "column data contents block" do
@@ -541,6 +552,16 @@ describe "table_for" do
541
552
  end
542
553
  end
543
554
 
555
+ it "should be able to use the table's current_index in the content of a cell" do
556
+ buffer = @view.table_for @users do |table|
557
+ table.column :id do |user|
558
+ "User id #{user.id} rendering with row index #{table.current_index}"
559
+ end
560
+ end
561
+ html_includes?(buffer, "User id 1 rendering with row index 0")
562
+ html_includes?(buffer, "User id 2 rendering with row index 1")
563
+ end
564
+
544
565
  it "should allow a link_url proc to render a link surrounding a table cell's content" do
545
566
  buffer = @view.table_for @users do |table|
546
567
  table.column :email, link_url: lambda {|user| "/admin/users/#{user.id}"}
@@ -19,7 +19,7 @@ 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.1.0"
22
+ spec.add_dependency "with_template", "~> 0.2.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"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table-for
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Hunter
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.0
33
+ version: 0.2.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.1.0
40
+ version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-rails
43
43
  requirement: !ruby/object:Gem::Requirement