table_cloth 0.3.0.beta1 → 0.3.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,14 +3,16 @@ 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 }
8
6
 
9
7
  def initialize(collection, view)
10
8
  @collection = collection
11
9
  @view = view
12
10
  end
13
11
 
12
+ def config
13
+ self.class.config
14
+ end
15
+
14
16
  class << self
15
17
  def presenter(klass=nil)
16
18
  return @presenter = klass if klass
@@ -47,6 +49,10 @@ module TableCloth
47
49
  @columns ||= {}
48
50
  @columns[options[:name]] = options
49
51
  end
52
+
53
+ def config
54
+ @config ||= TableCloth::Configuration.new
55
+ end
50
56
  end
51
57
  end
52
58
  end
@@ -6,7 +6,7 @@ module TableCloth
6
6
 
7
7
  included do
8
8
  OPTIONS.each do |option|
9
- cattr_accessor option
9
+ class_attribute option
10
10
  self.send "#{option}=", ActiveSupport::OrderedOptions.new
11
11
  end
12
12
  end
@@ -10,6 +10,11 @@ module TableCloth
10
10
  def config_for(type)
11
11
  self.send(type).to_hash
12
12
  end
13
+ alias [] config_for
14
+ end
15
+
16
+ def [](key)
17
+ self.send(key)
13
18
  end
14
19
  end
15
20
  end
@@ -57,16 +57,21 @@ module TableCloth
57
57
  end
58
58
 
59
59
  def wrapper_tag(type, value=nil, options={}, &block)
60
- table_config = table.class.config.send(type).to_hash
61
- tag_options = TableCloth.config_for(type)
62
- tag_options.merge!(table_config)
63
- tag_options.merge!(options)
60
+ options = tag_options(type, options)
64
61
 
65
62
  content = if block_given?
66
- v.content_tag(type, tag_options, &block)
63
+ v.content_tag(type, options, &block)
67
64
  else
68
- v.content_tag(type, value, tag_options)
65
+ v.content_tag(type, value, options)
69
66
  end
70
67
  end
68
+
69
+ private
70
+
71
+ def tag_options(type, options={})
72
+ options = options.dup
73
+ options.merge!(table.config[type])
74
+ options.merge!(TableCloth.config_for(type))
75
+ end
71
76
  end
72
77
  end
@@ -1,3 +1,3 @@
1
1
  module TableCloth
2
- VERSION = "0.3.0.beta1"
2
+ VERSION = "0.3.0.beta2"
3
3
  end
@@ -48,6 +48,18 @@ describe TableCloth::Base do
48
48
  end
49
49
  end
50
50
 
51
+ context ".config" do
52
+ it "returns a configurable class" do
53
+ expect(subject.config).to be_kind_of TableCloth::Configuration
54
+ end
55
+
56
+ context "for an instance" do
57
+ it "returns a configurable class" do
58
+ expect(table_instance.config).to be_kind_of TableCloth::Configuration
59
+ end
60
+ end
61
+ end
62
+
51
63
  context 'presenters' do
52
64
  it 'has a presenter method' do
53
65
  subject.should respond_to :presenter
@@ -3,33 +3,21 @@ require 'spec_helper'
3
3
  describe TableCloth::Configuration do
4
4
  subject { Class.new(TableCloth::Configuration) }
5
5
 
6
- it 'configures table options' do
7
- subject.table.classes = 'table'
8
- subject.table.classes.should == 'table'
6
+ context "options" do
7
+ TableCloth::Configuration::OPTIONS.each do |option|
8
+ it "configures #{option} options" do
9
+ subject.send(option).classes = "option_value"
10
+ expect(subject.send(option).classes).to eq("option_value")
11
+ end
12
+ end
9
13
  end
10
14
 
11
- it 'configures thead options' do
12
- subject.thead.classes = 'thead'
13
- subject.thead.classes.should == 'thead'
14
- end
15
-
16
- it 'configures th options' do
17
- subject.th.classes = 'th'
18
- subject.th.classes.should == 'th'
19
- end
20
-
21
- it 'configures tbody options' do
22
- subject.tbody.classes = 'tbody'
23
- subject.tbody.classes.should == 'tbody'
24
- end
25
-
26
- it 'configures tr options' do
27
- subject.tr.classes = 'tr'
28
- subject.tr.classes.should == 'tr'
29
- end
15
+ context "[] accessor" do
16
+ let(:option) { TableCloth::Configuration::OPTIONS.first }
30
17
 
31
- it 'configures td options' do
32
- subject.td.classes = 'td'
33
- subject.td.classes.should == 'td'
18
+ it "returns the option" do
19
+ subject.send(option).classes = "something"
20
+ expect(subject.new[option].classes).to eq("something")
21
+ end
34
22
  end
35
23
  end
@@ -59,13 +59,13 @@ describe TableCloth::Presenter do
59
59
 
60
60
  context 'tags' do
61
61
  it '.wrapper_tag includes config for a tag in block form' do
62
- TableCloth::Configuration.table.should_receive(:to_hash).and_return(class: "stuff")
62
+ TableCloth::Configuration.table.should_receive(:to_hash).once.and_return(class: "stuff")
63
63
  table = subject.wrapper_tag(:table) { "Hello "}
64
64
  Nokogiri::HTML(table).at_xpath('//table')[:class].should == 'stuff'
65
65
  end
66
66
 
67
67
  it '.wrapper_tag includes config for a tag without a block' do
68
- TableCloth::Configuration.table.should_receive(:to_hash).and_return(class: "stuff")
68
+ TableCloth::Configuration.table.should_receive(:to_hash).once.and_return(class: "stuff")
69
69
  table = subject.wrapper_tag(:table, 'Hello')
70
70
  Nokogiri::HTML(table).at_xpath('//table')[:class].should == 'stuff'
71
71
  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.3.0.beta1
4
+ version: 0.3.0.beta2
5
5
  prerelease: 6
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-12-29 00:00:00.000000000 Z
12
+ date: 2013-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec