bootstrap_help 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/bootstrap_help/table_helpers.rb +19 -13
- data/lib/bootstrap_help/version.rb +1 -1
- data/spec/bootstrap_helper/table_helper_spec.rb +11 -6
- 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: 18e3af557a9b03c01bbf6bf3570c9f2657b2e73f
|
4
|
+
data.tar.gz: 0e6043adc86f3b74a7f899e0dac843f20b3a407b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c174f7b4934d82258dc428eab24822ed3204cd2f5a9fa3f4e5495e757572304b69b7a267d564e86a529f938f5f5738ee35d2fd83a05651fd88f96d7e361396b
|
7
|
+
data.tar.gz: a23ee602af85877de6bc09ba9c90877a89df944e8b1acf7f1117a716b2b49ce7f031932754bd74194b58cfda6f742d7d3903abacaba72f5eb6cd7b9bdf9435c3
|
data/README.md
CHANGED
@@ -5,11 +5,10 @@ module BootstrapHelp
|
|
5
5
|
include ActionView::Helpers::UrlHelper
|
6
6
|
include ActionView::Context
|
7
7
|
|
8
|
-
|
9
|
-
def table_for(collection)
|
8
|
+
def table_for(collection, &block)
|
10
9
|
@columns = []
|
10
|
+
block.call
|
11
11
|
content_tag :table, class: "table table-striped table-bordered" do
|
12
|
-
yield
|
13
12
|
thead + tbody(collection)
|
14
13
|
end
|
15
14
|
end
|
@@ -19,6 +18,7 @@ module BootstrapHelp
|
|
19
18
|
@columns << {:name => name, :value => value, :sortable => sortable, :block => block}
|
20
19
|
nil
|
21
20
|
end
|
21
|
+
|
22
22
|
private
|
23
23
|
|
24
24
|
def tbody(collection)
|
@@ -26,9 +26,7 @@ module BootstrapHelp
|
|
26
26
|
collection.each do |item|
|
27
27
|
concat(draw_row {
|
28
28
|
@columns.each do |c|
|
29
|
-
|
30
|
-
concat(item.send(c.fetch(:value)))
|
31
|
-
})
|
29
|
+
parse_column(c, item)
|
32
30
|
end
|
33
31
|
})
|
34
32
|
end
|
@@ -45,18 +43,26 @@ module BootstrapHelp
|
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
|
-
def draw_body
|
49
|
-
content_tag(:tbody)
|
46
|
+
def draw_body(&block)
|
47
|
+
content_tag(:tbody, &block)
|
50
48
|
end
|
51
49
|
|
52
|
-
def draw_row
|
53
|
-
content_tag(:tr)
|
50
|
+
def draw_row(&block)
|
51
|
+
content_tag(:tr, &block)
|
54
52
|
end
|
55
53
|
|
56
|
-
def draw_column
|
57
|
-
content_tag(:td)
|
54
|
+
def draw_column(&block)
|
55
|
+
content_tag(:td, &block)
|
58
56
|
end
|
59
57
|
|
60
|
-
|
58
|
+
def parse_column(column, item)
|
59
|
+
attribute = item.send(column.fetch(:value))
|
60
|
+
if column[:block].present?
|
61
|
+
output = column[:block].call(attribute)
|
62
|
+
else
|
63
|
+
output = attribute
|
64
|
+
end
|
65
|
+
concat(draw_column { concat(output) })
|
66
|
+
end
|
61
67
|
end
|
62
68
|
end
|
@@ -7,18 +7,23 @@ describe BootstrapHelp::TableHelpers do
|
|
7
7
|
end
|
8
8
|
HelpersClass.new
|
9
9
|
end
|
10
|
+
|
10
11
|
describe '#table_for' do
|
11
12
|
it 'returns a bootstrap table for a given collection' do
|
12
13
|
collection = []
|
13
14
|
Customer = Struct.new(:name, :address)
|
14
15
|
collection << Customer.new('Josh', '111')
|
15
16
|
collection << Customer.new('Dave', '222')
|
16
|
-
expected_result = "<table class=\"table table-striped table-bordered\"><thead><tr><th>Name</th><th>Address</th></tr></thead><tbody><tr><td>
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
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
|
+
|
19
|
+
block = Proc.new {
|
20
|
+
helpers.column 'name' do |value|
|
21
|
+
value.upcase
|
22
|
+
end
|
23
|
+
helpers.column 'address'
|
24
|
+
}
|
25
|
+
|
26
|
+
expect(helpers.table_for(collection, &block)).to eq(expected_result)
|
22
27
|
end
|
23
28
|
end
|
24
29
|
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.19
|
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-08-
|
11
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|