table_cloth 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/table_cloth/base.rb +3 -5
- data/lib/table_cloth/version.rb +1 -1
- data/lib/table_cloth.rb +2 -1
- data/spec/lib/base_spec.rb +14 -0
- data/spec/lib/presenter_spec.rb +5 -11
- data/spec/lib/presenters/default_spec.rb +7 -11
- data/spec/spec_helper.rb +1 -1
- data/spec/support/let_declarations.rb +2 -0
- metadata +4 -2
data/lib/table_cloth/base.rb
CHANGED
@@ -3,6 +3,8 @@ module TableCloth
|
|
3
3
|
NoPresenterError = Class.new(Exception)
|
4
4
|
|
5
5
|
attr_reader :collection, :view
|
6
|
+
class_attribute :config, instance_accessor: false
|
7
|
+
self.config = Class.new { include ConfigurableElements }
|
6
8
|
|
7
9
|
def initialize(collection, view)
|
8
10
|
@collection = collection
|
@@ -16,7 +18,7 @@ module TableCloth
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def columns
|
19
|
-
@columns ||=self.class.columns.each_with_object({}) do |(column_name, column), columns|
|
21
|
+
@columns ||= self.class.columns.each_with_object({}) do |(column_name, column), columns|
|
20
22
|
columns[column_name] = column if column.available?(self)
|
21
23
|
end
|
22
24
|
end
|
@@ -26,10 +28,6 @@ module TableCloth
|
|
26
28
|
end
|
27
29
|
|
28
30
|
class << self
|
29
|
-
def config
|
30
|
-
@config ||= Class.new { include ConfigurableElements }
|
31
|
-
end
|
32
|
-
|
33
31
|
def presenter(klass=nil)
|
34
32
|
return @presenter = klass if klass
|
35
33
|
|
data/lib/table_cloth/version.rb
CHANGED
data/lib/table_cloth.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'action_view'
|
2
|
+
require 'active_support/core_ext/class'
|
2
3
|
require 'table_cloth/version'
|
3
4
|
require 'table_cloth/configurable_elements'
|
4
5
|
require 'table_cloth/base'
|
@@ -21,7 +22,7 @@ module TableCloth
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def config_for(type)
|
24
|
-
Configuration.config_for(type)
|
25
|
+
Configuration.config_for(type).dup
|
25
26
|
end
|
26
27
|
module_function :config_for
|
27
28
|
end
|
data/spec/lib/base_spec.rb
CHANGED
@@ -149,4 +149,18 @@ describe TableCloth::Base do
|
|
149
149
|
subject.columns[:actions].should have(2).actions
|
150
150
|
end
|
151
151
|
end
|
152
|
+
|
153
|
+
context "configuration" do
|
154
|
+
subject { Class.new(TableCloth::Base) }
|
155
|
+
let(:sibling1_class) { Class.new(subject) }
|
156
|
+
let(:sibling2_class) { Class.new(subject) }
|
157
|
+
|
158
|
+
it "allows configuration" do
|
159
|
+
expect { subject.config.table.cellpadding = '0' }.to change { subject.config.table.cellpadding }.to('0')
|
160
|
+
end
|
161
|
+
|
162
|
+
it "doesn't interfere with configuration of parent classes" do
|
163
|
+
expect { sibling1_class.config.table.cellpadding = '0' }.not_to change { sibling2_class.config.table.cellpadding }
|
164
|
+
end
|
165
|
+
end
|
152
166
|
end
|
data/spec/lib/presenter_spec.rb
CHANGED
@@ -49,22 +49,16 @@ describe TableCloth::Presenter do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
context 'tags' do
|
52
|
-
before(:all) { TableCloth::Configuration.table.class = 'stuff' }
|
53
52
|
it '.wrapper_tag includes config for a tag in block form' do
|
54
|
-
table
|
55
|
-
|
56
|
-
|
57
|
-
table = Nokogiri::HTML(table)
|
58
|
-
|
59
|
-
table.at_xpath('//table')[:class].should == 'stuff'
|
60
|
-
table.at_xpath('//table').text.should include 'Hello'
|
53
|
+
TableCloth::Configuration.table.should_receive(:to_hash).and_return(class: "stuff")
|
54
|
+
table = subject.wrapper_tag(:table) { "Hello "}
|
55
|
+
Nokogiri::HTML(table).at_xpath('//table')[:class].should == 'stuff'
|
61
56
|
end
|
62
57
|
|
63
58
|
it '.wrapper_tag includes config for a tag without a block' do
|
59
|
+
TableCloth::Configuration.table.should_receive(:to_hash).and_return(class: "stuff")
|
64
60
|
table = subject.wrapper_tag(:table, 'Hello')
|
65
|
-
|
66
|
-
table.at_xpath('//table')[:class].should == 'stuff'
|
67
|
-
table.at_xpath('//table').text.should include 'Hello'
|
61
|
+
Nokogiri::HTML(table).at_xpath('//table')[:class].should == 'stuff'
|
68
62
|
end
|
69
63
|
end
|
70
64
|
end
|
@@ -11,14 +11,7 @@ describe TableCloth::Presenters::Default do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:objects) do
|
14
|
-
3.times.map
|
15
|
-
num = n+1
|
16
|
-
DummyModel.new.tap do |d|
|
17
|
-
d.id = num # Wat
|
18
|
-
d.email = "robert#{num}@example.com"
|
19
|
-
d.name = "robert#{num}"
|
20
|
-
end
|
21
|
-
end
|
14
|
+
3.times.map {|n| dummy_model.dup.tap {|dm| dm.id = n+1 } }
|
22
15
|
end
|
23
16
|
|
24
17
|
let(:view_context) { ActionView::Base.new }
|
@@ -190,8 +183,8 @@ describe TableCloth::Presenters::Default do
|
|
190
183
|
include_examples "table configuration"
|
191
184
|
|
192
185
|
context "is extendable" do
|
193
|
-
let(:
|
194
|
-
|
186
|
+
let(:parent_table) do
|
187
|
+
Class.new(TableCloth::Base) do
|
195
188
|
column :email
|
196
189
|
|
197
190
|
config.table.class = 'table2'
|
@@ -201,7 +194,10 @@ describe TableCloth::Presenters::Default do
|
|
201
194
|
config.tr.class = 'tr2'
|
202
195
|
config.td.class = 'td2'
|
203
196
|
end
|
204
|
-
|
197
|
+
end
|
198
|
+
|
199
|
+
let(:dummy_table) do
|
200
|
+
Class.new(parent_table)
|
205
201
|
end
|
206
202
|
|
207
203
|
include_examples "table configuration"
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_cloth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- spec/support/dummy_table.rb
|
168
168
|
- spec/support/dummy_table_with_actions.rb
|
169
169
|
- spec/support/dummy_table_with_value_options.rb
|
170
|
+
- spec/support/let_declarations.rb
|
170
171
|
- spec/support/shared_config_examples.rb
|
171
172
|
- spec/support/view_mocks.rb
|
172
173
|
- table_cloth.gemspec
|
@@ -210,5 +211,6 @@ test_files:
|
|
210
211
|
- spec/support/dummy_table.rb
|
211
212
|
- spec/support/dummy_table_with_actions.rb
|
212
213
|
- spec/support/dummy_table_with_value_options.rb
|
214
|
+
- spec/support/let_declarations.rb
|
213
215
|
- spec/support/shared_config_examples.rb
|
214
216
|
- spec/support/view_mocks.rb
|