bootstrap_help 0.0.13 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/bootstrap_help/railtie.rb +1 -0
- data/lib/bootstrap_help/table_helpers.rb +62 -0
- data/lib/bootstrap_help/version.rb +1 -1
- data/lib/bootstrap_help.rb +1 -0
- data/spec/bootstrap_helper/table_helper_spec.rb +24 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c65b4b9da0581f61648ab8b54e9b60545aa82b0d
|
4
|
+
data.tar.gz: ec97fcaf5d88ff64527b54298a0b847b2a558c11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb92522d078ee7ff3e2fe8cdb96e5bfb9ad9ccc7c3b8b0288d219740c789fd52366500db9ca1b9a0a31d987b8e710cee93fe58c54ca36f976ec37c16d3d57952
|
7
|
+
data.tar.gz: 9aa9f96c111a847cb27b161f1acef8085c096e42e941d72d67a01ba042ae7a0231e1849f411f7e300e29f53ac14d0d9a3cc7a1af403d924b3631519e5f77c3d3
|
data/README.md
CHANGED
@@ -35,6 +35,16 @@ The Nav Helper helps you quickly build a fixed navigation bar in Bootstrap. For
|
|
35
35
|
= menu_link_to "Sign In", "#"
|
36
36
|
```
|
37
37
|
|
38
|
+
### Table Helper
|
39
|
+
|
40
|
+
The Table Helper helps you quickly build Bootstrap tables with collections of instances. For example:
|
41
|
+
|
42
|
+
```haml
|
43
|
+
= table_for(@apples) do
|
44
|
+
= column :color
|
45
|
+
= column 'Type of Apple', :type
|
46
|
+
```
|
47
|
+
|
38
48
|
## Contributing
|
39
49
|
|
40
50
|
1. Fork it
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module BootstrapHelp
|
2
|
+
module TableHelpers
|
3
|
+
include ActionView::Helpers::TagHelper
|
4
|
+
include ActionView::Helpers::TextHelper
|
5
|
+
include ActionView::Helpers::UrlHelper
|
6
|
+
include ActionView::Context
|
7
|
+
|
8
|
+
|
9
|
+
def table_for(collection)
|
10
|
+
@columns = []
|
11
|
+
content_tag :table, class: "table table-striped table-bordered" do
|
12
|
+
yield
|
13
|
+
thead + tbody(collection)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def column(name, value = nil, sortable = true, &block)
|
18
|
+
value = name unless value
|
19
|
+
@columns << {:name => name, :value => value, :sortable => sortable, :block => block}
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
private
|
23
|
+
|
24
|
+
def tbody(collection)
|
25
|
+
draw_body do
|
26
|
+
collection.each do |item|
|
27
|
+
concat(draw_row {
|
28
|
+
@columns.each do |c|
|
29
|
+
concat(draw_column {
|
30
|
+
concat(item.send(c.fetch(:value)))
|
31
|
+
})
|
32
|
+
end
|
33
|
+
})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def thead
|
39
|
+
content_tag :thead do
|
40
|
+
draw_row do
|
41
|
+
@columns.each do |c|
|
42
|
+
concat(content_tag(:th, c.fetch(:name).to_s.titleize))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def draw_body
|
49
|
+
content_tag(:tbody) { yield }
|
50
|
+
end
|
51
|
+
|
52
|
+
def draw_row
|
53
|
+
content_tag(:tr) { yield }
|
54
|
+
end
|
55
|
+
|
56
|
+
def draw_column
|
57
|
+
content_tag(:td) { yield }
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
data/lib/bootstrap_help.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BootstrapHelp::TableHelpers do
|
4
|
+
let(:helpers) do
|
5
|
+
class HelpersClass
|
6
|
+
include BootstrapHelp::TableHelpers
|
7
|
+
end
|
8
|
+
HelpersClass.new
|
9
|
+
end
|
10
|
+
describe '#table_for' do
|
11
|
+
it 'returns a bootstrap table for a given collection' do
|
12
|
+
collection = []
|
13
|
+
Customer = Struct.new(:name, :address)
|
14
|
+
collection << Customer.new('Josh', '111')
|
15
|
+
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)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
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.16
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,8 +96,10 @@ files:
|
|
96
96
|
- lib/bootstrap_help.rb
|
97
97
|
- lib/bootstrap_help/nav_helpers.rb
|
98
98
|
- lib/bootstrap_help/railtie.rb
|
99
|
+
- lib/bootstrap_help/table_helpers.rb
|
99
100
|
- lib/bootstrap_help/version.rb
|
100
101
|
- spec/bootstrap_helper/nav_helper_spec.rb
|
102
|
+
- spec/bootstrap_helper/table_helper_spec.rb
|
101
103
|
- spec/spec_helper.rb
|
102
104
|
homepage: https://github.com/jklina/bootstrap_help
|
103
105
|
licenses:
|
@@ -125,4 +127,5 @@ specification_version: 4
|
|
125
127
|
summary: Twitter Bootstrap makeup generators
|
126
128
|
test_files:
|
127
129
|
- spec/bootstrap_helper/nav_helper_spec.rb
|
130
|
+
- spec/bootstrap_helper/table_helper_spec.rb
|
128
131
|
- spec/spec_helper.rb
|