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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e35df1897f26da48803b1a453bd3daf0bf52a843
4
- data.tar.gz: 80a0b4ec1af1a910e8d3cac1dd08b863165b95ba
3
+ metadata.gz: 18e3af557a9b03c01bbf6bf3570c9f2657b2e73f
4
+ data.tar.gz: 0e6043adc86f3b74a7f899e0dac843f20b3a407b
5
5
  SHA512:
6
- metadata.gz: 56c7e77f795b45f5c67cabf76e70f4f550b33108416abe510f0f1fb690d6d37fc150b04272eeef8285406ff9e73d8ad17f463bb626a2b12d8ca20296118aa0da
7
- data.tar.gz: 5b330c277e5e11b67a1dbfe8ea6182779fde0003e71c3ca9a2d728a786ee53a479605409ebd4f3ddf76724e9dde397431cc729fe077403d2bd25826a1aa83edb
6
+ metadata.gz: 2c174f7b4934d82258dc428eab24822ed3204cd2f5a9fa3f4e5495e757572304b69b7a267d564e86a529f938f5f5738ee35d2fd83a05651fd88f96d7e361396b
7
+ data.tar.gz: a23ee602af85877de6bc09ba9c90877a89df944e8b1acf7f1117a716b2b49ce7f031932754bd74194b58cfda6f742d7d3903abacaba72f5eb6cd7b9bdf9435c3
data/README.md CHANGED
@@ -41,7 +41,8 @@ The Table Helper helps you quickly build Bootstrap tables with collections of in
41
41
 
42
42
  ```haml
43
43
  = table_for(@apples) do
44
- = column :color
44
+ = column :color do |color|
45
+ - color.to_hex
45
46
  = column 'Type of Apple', :type
46
47
  ```
47
48
 
@@ -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
- concat(draw_column {
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) { yield }
46
+ def draw_body(&block)
47
+ content_tag(:tbody, &block)
50
48
  end
51
49
 
52
- def draw_row
53
- content_tag(:tr) { yield }
50
+ def draw_row(&block)
51
+ content_tag(:tr, &block)
54
52
  end
55
53
 
56
- def draw_column
57
- content_tag(:td) { yield }
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
@@ -1,3 +1,3 @@
1
1
  module BootstrapHelp
2
- VERSION = "0.0.18"
2
+ VERSION = "0.0.19"
3
3
  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>Josh</td><td>111</td></tr><tr><td>Dave</td><td>222</td></tr></tbody></table>"
17
- expect(
18
- helpers.table_for(collection) {
19
- helpers.column 'name'; helpers.column 'address' }
20
- ).
21
- to eq(expected_result)
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.18
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-09 00:00:00.000000000 Z
11
+ date: 2013-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler