table_cloth 0.3.0.beta1 → 0.3.0.beta2
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.
- data/lib/table_cloth/base.rb +8 -2
- data/lib/table_cloth/configurable_elements.rb +1 -1
- data/lib/table_cloth/configuration.rb +5 -0
- data/lib/table_cloth/presenter.rb +11 -6
- data/lib/table_cloth/version.rb +1 -1
- data/spec/lib/base_spec.rb +12 -0
- data/spec/lib/configuration_spec.rb +13 -25
- data/spec/lib/presenter_spec.rb +2 -2
- metadata +2 -2
data/lib/table_cloth/base.rb
CHANGED
@@ -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
|
@@ -57,16 +57,21 @@ module TableCloth
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def wrapper_tag(type, value=nil, options={}, &block)
|
60
|
-
|
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,
|
63
|
+
v.content_tag(type, options, &block)
|
67
64
|
else
|
68
|
-
v.content_tag(type, value,
|
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
|
data/lib/table_cloth/version.rb
CHANGED
data/spec/lib/base_spec.rb
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
12
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
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
|
data/spec/lib/presenter_spec.rb
CHANGED
@@ -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.
|
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:
|
12
|
+
date: 2013-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|