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.
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module TableCloth
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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
@@ -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
@@ -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 = subject.wrapper_tag(:table) do
55
- 'Hello'
56
- end
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
- table = Nokogiri::HTML(table)
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 do |n|
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(:dummy_table) do
194
- table = Class.new(TableCloth::Base) do
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
- Class.new(table)
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
@@ -11,5 +11,5 @@ RSpec.configure do |config|
11
11
  config.treat_symbols_as_metadata_keys_with_true_values = true
12
12
  config.run_all_when_everything_filtered = true
13
13
  config.filter_run :focus
14
- config.order = 'random'
14
+ config.include LetDeclarations
15
15
  end
@@ -0,0 +1,2 @@
1
+ module LetDeclarations
2
+ end
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.0
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-01 00:00:00.000000000 Z
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