bootstrap_help 0.0.30 → 0.0.31
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/bootstrap_help/table_helpers.rb +18 -5
- data/lib/bootstrap_help/version.rb +1 -1
- data/spec/bootstrap_helper/table_helper_spec.rb +26 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b189fd43be426fec7b3a2c59aa7a72716766b55e
|
4
|
+
data.tar.gz: 9e5a646e55f8b3570a459360056914da54c4a337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 406d733aa5e7a56f8eeea66b2b8379260d1da394b97e4c24130fc079474b4144517855aecaf071c11ee4c7dc4f1a0d6539f9b113aaa385bebc4aeec2c6504cd8
|
7
|
+
data.tar.gz: e906938b5d722b3007b3a146d45cc385896bd79787e759019f42ea90c876b1a7a27a0b0299d37b9dd88a4c764c462c71dfd958198a6fcde1b86cf026027dbf41
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ The Nav Helper helps you quickly build a fixed navigation bar in Bootstrap. For
|
|
40
40
|
The Table Helper helps you quickly build Bootstrap tables with collections of instances. For example:
|
41
41
|
|
42
42
|
```haml
|
43
|
-
= table_for(@apples) do
|
43
|
+
= table_for(@apples, row_decorators: { error: :has_worm?) do
|
44
44
|
= column "Hex Color" do |apple|
|
45
45
|
- apple.color.to_hex
|
46
46
|
= column 'Type of Apple', :type
|
@@ -7,6 +7,7 @@ module BootstrapHelp
|
|
7
7
|
|
8
8
|
def table_for(collection, args={}, &block)
|
9
9
|
@columns = []
|
10
|
+
@row_decorators = args[:row_decorators]
|
10
11
|
block.call
|
11
12
|
content_tag :table, class: "table table-striped table-bordered" do
|
12
13
|
thead + tbody(collection)
|
@@ -24,7 +25,7 @@ module BootstrapHelp
|
|
24
25
|
def tbody(collection)
|
25
26
|
draw_body do
|
26
27
|
collection.each do |item|
|
27
|
-
concat(draw_row {
|
28
|
+
concat(draw_row(item) {
|
28
29
|
@columns.each do |c|
|
29
30
|
parse_column(c, item)
|
30
31
|
end
|
@@ -47,8 +48,12 @@ module BootstrapHelp
|
|
47
48
|
content_tag(:tbody, &block)
|
48
49
|
end
|
49
50
|
|
50
|
-
def draw_row(&block)
|
51
|
-
|
51
|
+
def draw_row(item=nil, &block)
|
52
|
+
if item.present?
|
53
|
+
content_tag(:tr, class: get_row_css_classes(item), &block)
|
54
|
+
else
|
55
|
+
content_tag(:tr, &block)
|
56
|
+
end
|
52
57
|
end
|
53
58
|
|
54
59
|
def draw_column(&block)
|
@@ -57,13 +62,21 @@ module BootstrapHelp
|
|
57
62
|
|
58
63
|
def parse_column(column, item)
|
59
64
|
if column[:block].present?
|
60
|
-
puts "block"
|
61
65
|
output = capture(item, &column[:block])
|
62
66
|
else
|
63
|
-
puts "test"
|
64
67
|
output = item.send(column.fetch(:value)).to_s
|
65
68
|
end
|
66
69
|
concat(draw_column { output })
|
67
70
|
end
|
71
|
+
|
72
|
+
def get_row_css_classes(item)
|
73
|
+
css_classes = []
|
74
|
+
if @row_decorators.present?
|
75
|
+
@row_decorators.each do |css_class, method|
|
76
|
+
css_classes << css_class if item.send(method)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
return css_classes
|
80
|
+
end
|
68
81
|
end
|
69
82
|
end
|
@@ -9,13 +9,13 @@ describe BootstrapHelp::TableHelpers do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
collection = []
|
12
|
-
Customer = Struct.new(:name, :address)
|
13
|
-
collection << Customer.new('Josh', '111')
|
14
|
-
collection << Customer.new('Dave', '222')
|
12
|
+
Customer = Struct.new(:name, :address, :good?, :bad?, :not_right?, :informative?)
|
13
|
+
collection << Customer.new('Josh', '111', true, true, true, true)
|
14
|
+
collection << Customer.new('Dave', '222', true, true, true, true)
|
15
15
|
|
16
16
|
describe '#table_for' do
|
17
17
|
it 'returns a bootstrap table for a given collection' do
|
18
|
-
expected_result = "<table class=\"table table-striped table-bordered\"><thead><tr><th>Name</th><th>Address</th></tr></thead><tbody><tr><td>JOSH</td><td>111</td></tr><tr><td>DAVE</td><td>222</td></tr></tbody></table>"
|
18
|
+
expected_result = "<table class=\"table table-striped table-bordered\"><thead><tr><th>Name</th><th>Address</th></tr></thead><tbody><tr class=\"\"><td>JOSH</td><td>111</td></tr><tr class=\"\"><td>DAVE</td><td>222</td></tr></tbody></table>"
|
19
19
|
|
20
20
|
block = Proc.new {
|
21
21
|
helpers.column 'name' do |customer|
|
@@ -28,7 +28,7 @@ describe BootstrapHelp::TableHelpers do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "has the ability to add manageable links to the end of the table" do
|
31
|
-
expected_result = "<table class=\"table table-striped table-bordered\"><thead><tr><th>Name</th><th>Address</th><th>Any Old Name</th></tr></thead><tbody><tr><td>JOSH</td><td>111</td><td>hello</td></tr><tr><td>DAVE</td><td>222</td><td>hello</td></tr></tbody></table>"
|
31
|
+
expected_result = "<table class=\"table table-striped table-bordered\"><thead><tr><th>Name</th><th>Address</th><th>Any Old Name</th></tr></thead><tbody><tr class=\"\"><td>JOSH</td><td>111</td><td>hello</td></tr><tr class=\"\"><td>DAVE</td><td>222</td><td>hello</td></tr></tbody></table>"
|
32
32
|
|
33
33
|
block = Proc.new {
|
34
34
|
helpers.column 'name' do |customer|
|
@@ -43,5 +43,26 @@ describe BootstrapHelp::TableHelpers do
|
|
43
43
|
expect(helpers.table_for(collection, &block)).to eq(expected_result)
|
44
44
|
|
45
45
|
end
|
46
|
+
|
47
|
+
it "well let you assign classes to rows based off item methods" do
|
48
|
+
expected_result = "<table class=\"table table-striped table-bordered\"><thead><tr><th>Name</th><th>Address</th></tr></thead><tbody><tr class=\"success error warning info\"><td>JOSH</td><td>111</td></tr><tr class=\"success error warning info\"><td>DAVE</td><td>222</td></tr></tbody></table>"
|
49
|
+
|
50
|
+
block = Proc.new {
|
51
|
+
helpers.column 'name' do |customer|
|
52
|
+
customer.name.upcase
|
53
|
+
end
|
54
|
+
helpers.column 'address'
|
55
|
+
}
|
56
|
+
|
57
|
+
row_class_map = {
|
58
|
+
success: :good?,
|
59
|
+
error: :bad?,
|
60
|
+
warning: :not_right?,
|
61
|
+
info: :informative?
|
62
|
+
}
|
63
|
+
|
64
|
+
expect(helpers.table_for(collection, row_decorators: row_class_map, &block)).to eq(expected_result)
|
65
|
+
|
66
|
+
end
|
46
67
|
end
|
47
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstrap_help
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.31
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Klina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|