table_for_collection 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -38,26 +38,28 @@ This ruby code will produce following HTML:
38
38
  :class => "simple-row"
39
39
  }
40
40
  } do -%>
41
- <% column :name %>
41
+ <% column :name, :html => { :width => "25%" } %>
42
42
  <% column :email %>
43
43
  <% column :address, :title => "Home" %>
44
44
  <% end %>
45
45
 
46
- You can put :html hash to the options list. In this case table will be created with
47
- given html attributes. Also :title value in the :column method will be used as column's
48
- title. It will produce HTML similar to:
46
+ You can put :html hash to the options list (inside the :column method too). In this case
47
+ table will be created with given html attributes. Also :title value in the :column method
48
+ will be used as column's title. It will produce HTML similar to:
49
49
 
50
50
  <table class="simple-table" id="users" width="100%">
51
51
  <thead>
52
52
  <tr>
53
- <td>Name</td>
54
- <td>Email</td>
55
- <td>Home</td>
53
+ <th>Name</th>
54
+ <th>Email</th>
55
+ <th>Home</th>
56
56
  </tr>
57
57
  </thead>
58
58
  <tbody>
59
- <tr class="simple-row"
60
- ...
59
+ <tr class="simple-row">
60
+ <td width="25%">...</td>
61
+ <td>...</td>
62
+ <td>...</td>
61
63
  </tr>
62
64
  </tbody>
63
65
  </table>
@@ -1,8 +1,9 @@
1
1
  module TableHelper
2
2
  class Column # :nodoc:
3
- attr_reader :title
3
+ attr_reader :title, :html
4
4
  def initialize(template, obj, ops)
5
5
  @template, @options, @attr, @title = template, ops, obj, ""
6
+ @html = @options.delete(:html)
6
7
  end
7
8
 
8
9
  def content_for
@@ -70,7 +70,7 @@ module TableHelper
70
70
  @records.map do |rec|
71
71
  content_tag(:tr, tr_options) do
72
72
  @columns.map do |col|
73
- content_tag :td do
73
+ content_tag :td, col.html do
74
74
  col.content_for(rec).to_s
75
75
  end
76
76
  end.join
@@ -1,4 +1,4 @@
1
1
  module TableHelper
2
2
  GEM_NAME = "table_for_collection"
3
- VERSION = "1.0"
3
+ VERSION = "1.0.1"
4
4
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "table_for"
1
+ require "table_for_collection"
2
2
  require "webrat"
3
3
 
4
4
  RSpec.configure do |config|
@@ -72,6 +72,25 @@ describe ActionView::Base do
72
72
  end
73
73
  end
74
74
  # <%= table_for @users do %>
75
+ # <% column :name, :html => { :width => "50%" } %>
76
+ # <% end %>
77
+ describe "with column :html options" do
78
+ before(:each) do
79
+ @html = template.table_for(users) do
80
+ column :id, :html => { :class => "user-id", :width => "50%" }
81
+ end
82
+ end
83
+ it "should render valid HTML" do
84
+ @html.should have_selector("table") do |table|
85
+ table.should have_selector("tbody/tr") do |tr|
86
+ users.each do |user|
87
+ tr.should have_selector("td.user-id[@width='50%']")
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ # <%= table_for @users do %>
75
94
  # <% columns :name, :email, :address %>
76
95
  # <% end %>
77
96
  describe "with columns" do
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_for_collection
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- version: "1.0"
9
+ - 1
10
+ version: 1.0.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Dima Lunich
@@ -110,7 +111,7 @@ rubyforge_project: ""
110
111
  rubygems_version: 1.3.7
111
112
  signing_key:
112
113
  specification_version: 3
113
- summary: table_for_collection-1.0
114
+ summary: table_for_collection-1.0.1
114
115
  test_files:
115
116
  - spec/core_ex/array_spec.rb
116
117
  - spec/spec_helper.rb