twitter_bootstrap-helpers 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -3,19 +3,34 @@
|
|
3
3
|
## Installation
|
4
4
|
|
5
5
|
Add to your gem file and call `bundle` to install it.
|
6
|
-
|
7
6
|
```ruby
|
8
7
|
gem twitter_bootstrap-helpers install
|
9
8
|
```
|
10
9
|
|
10
|
+
Adding to rails
|
11
|
+
```ruby
|
12
|
+
gem 'twitter_bootstrap-helpers'
|
13
|
+
```
|
14
|
+
|
11
15
|
## Usage
|
12
16
|
|
13
|
-
|
17
|
+
Basic usage with form helper
|
18
|
+
```erb
|
19
|
+
<%= bootstrap_form_for @post do |f| %>
|
20
|
+
<%= f.text_field_control :title %>
|
21
|
+
<%= f.text_area_control :body %>
|
22
|
+
<%= f.checkbox_control :published %>
|
23
|
+
<%= f.form_actions %>
|
24
|
+
<% end %>
|
25
|
+
```
|
14
26
|
|
15
|
-
|
16
|
-
|
17
|
-
|
27
|
+
To use form builder directly
|
28
|
+
```erb
|
29
|
+
<%= form_for @post, builder: TwitterBootstrap::Helpers::FormBuilder,
|
30
|
+
html:{class: 'form-horizontal'} do |f| %>
|
31
|
+
<%= f.text_field_control :title %>
|
18
32
|
<%= f.text_area_control :body %>
|
19
|
-
<%= f.
|
33
|
+
<%= f.checkbox_control :published %>
|
34
|
+
<%= f.form_actions %>
|
20
35
|
<% end %>
|
21
36
|
```
|
@@ -22,25 +22,88 @@ module TwitterBootstrap
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
# Submit button
|
26
|
+
# <input class="btn btn-primary" name="commit" type="submit" value="Create Post" />
|
25
27
|
def submit(value=nil, options={})
|
26
28
|
options[:class] = 'btn btn-primary' unless options.has_key? :class
|
27
29
|
super value, options
|
28
30
|
end
|
31
|
+
|
32
|
+
# Cancel button
|
33
|
+
#
|
34
|
+
# Creates a cancel link that will link to the index path of the
|
35
|
+
# current object by default a cancel url can also be passed as
|
36
|
+
# a param.
|
37
|
+
#
|
38
|
+
# <a href="/posts" class="btn">Cancel</a>
|
39
|
+
def cancel(url=nil)
|
40
|
+
url = @template.polymorphic_path(@object.class) if url.nil?
|
41
|
+
@template.link_to :Cancel, url, class: 'btn'
|
42
|
+
end
|
43
|
+
|
44
|
+
# Check box control
|
45
|
+
# <div class="control-group">
|
46
|
+
# <div class="controls">
|
47
|
+
# <label class="checkbox inline-form" for="input_id">
|
48
|
+
# <input type="checkbox" id="input_id" value="1" />
|
49
|
+
# Text Input
|
50
|
+
# </label>
|
51
|
+
# </div>
|
52
|
+
# </div>
|
53
|
+
def checkbox_control(attr, text=nil, *args)
|
54
|
+
options = args.extract_options!
|
55
|
+
options = { class: 'control-group' }
|
56
|
+
options[:class] += ' error' if @object.errors[attr].any?
|
57
|
+
text = attr.to_s.humanize if text.nil?
|
58
|
+
@template.content_tag :div, options do
|
59
|
+
@template.concat controls(attr) {
|
60
|
+
@template.concat label(attr, text, class: 'checkbox inline'){
|
61
|
+
@template.concat check_box(attr)
|
62
|
+
@template.concat text
|
63
|
+
}
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Form actions
|
69
|
+
# <div class="form-actions">
|
70
|
+
# <input input="submit" value="Create Post" />
|
71
|
+
# <a href="/posts" class="btn">Cancel</a>
|
72
|
+
# </div>
|
73
|
+
def form_actions(options={})
|
74
|
+
@template.content_tag :div, class: 'form-actions' do
|
75
|
+
@template.concat submit
|
76
|
+
@template.concat " " # Add space so submit and cancel buttons don't collide
|
77
|
+
@template.concat cancel(options[:cancel_url])
|
78
|
+
end
|
79
|
+
end
|
29
80
|
|
30
|
-
# Control Group Example
|
81
|
+
# Field Control Group Example
|
82
|
+
#
|
83
|
+
# Pass an input field name to create a standard control group
|
84
|
+
#
|
31
85
|
# <div class="control-group">
|
32
86
|
# <label class="control-label" for="input_id">Text Input</label>
|
33
87
|
# <div class="controls">
|
34
88
|
# <input type="input_type" class="input-xlarge" id="input_id" />
|
35
89
|
# </div>
|
36
90
|
# </div>
|
37
|
-
|
38
91
|
def field_control_group(type, attr, *args)
|
39
92
|
control_group attr do
|
40
93
|
@template.concat send(type, attr, *args)
|
41
94
|
end
|
42
95
|
end
|
43
96
|
|
97
|
+
# Control Group
|
98
|
+
#
|
99
|
+
# Yield block within control group
|
100
|
+
#
|
101
|
+
# <div class="control-group">
|
102
|
+
# <label class="control-label" for="input_id">Text Input</label>
|
103
|
+
# <div class="controls">
|
104
|
+
# <%= yield %>
|
105
|
+
# </div>
|
106
|
+
# </div>
|
44
107
|
def control_group(attr, text = nil, &block )
|
45
108
|
options = { class: 'control-group' }
|
46
109
|
options[:class] += ' error' if @object.errors[attr].any?
|
@@ -50,6 +113,13 @@ module TwitterBootstrap
|
|
50
113
|
end
|
51
114
|
end
|
52
115
|
|
116
|
+
# Control Group
|
117
|
+
#
|
118
|
+
# Yield block within control group
|
119
|
+
#
|
120
|
+
# <div class="controls">
|
121
|
+
# <%= yield %>
|
122
|
+
# </div>
|
53
123
|
def controls(attr, &block)
|
54
124
|
@template.content_tag :div, class: 'controls' do
|
55
125
|
yield
|
@@ -57,6 +127,8 @@ module TwitterBootstrap
|
|
57
127
|
end
|
58
128
|
end
|
59
129
|
|
130
|
+
# Display inline error
|
131
|
+
# <span class="help-inline">can't be blank.</span>
|
60
132
|
def errors_on(attr)
|
61
133
|
if @object.errors[attr].any?
|
62
134
|
@template.content_tag(:span,
|
@@ -25,6 +25,19 @@ class TwitterBootstrap::HelpersTest < ActionView::TestCase
|
|
25
25
|
</div>')
|
26
26
|
end
|
27
27
|
|
28
|
+
test "checkbox_control" do
|
29
|
+
assert_equal @builder.checkbox_control(:published),
|
30
|
+
r('<div class="control-group">
|
31
|
+
<div class="controls">
|
32
|
+
<label class="checkbox inline" for="post_published">
|
33
|
+
<input name="post[published]" type="hidden" value="0" />
|
34
|
+
<input id="post_published" name="post[published]" type="checkbox" value="1" />
|
35
|
+
Published
|
36
|
+
</label>
|
37
|
+
</div>
|
38
|
+
</div>')
|
39
|
+
end
|
40
|
+
|
28
41
|
test "field_control_group" do
|
29
42
|
assert_equal @builder.field_control_group(:text_field,:title),
|
30
43
|
r('<div class="control-group">
|
@@ -39,6 +52,26 @@ class TwitterBootstrap::HelpersTest < ActionView::TestCase
|
|
39
52
|
assert_equal @builder.submit, '<input class="btn btn-primary" name="commit" type="submit" value="Create Post" />'
|
40
53
|
end
|
41
54
|
|
55
|
+
test "cancel" do
|
56
|
+
assert_equal @builder.cancel, '<a href="/posts" class="btn">Cancel</a>'
|
57
|
+
end
|
58
|
+
|
59
|
+
test "form_actions" do
|
60
|
+
assert_equal @builder.form_actions,
|
61
|
+
r('<div class="form-actions">
|
62
|
+
<input class="btn btn-primary" name="commit" type="submit" value="Create Post" />
|
63
|
+
<a href="/posts" class="btn">Cancel</a>
|
64
|
+
</div>')
|
65
|
+
end
|
66
|
+
|
67
|
+
test "form_actions with custom cancel button" do
|
68
|
+
assert_equal @builder.form_actions(cancel_url:'/'),
|
69
|
+
r('<div class="form-actions">
|
70
|
+
<input class="btn btn-primary" name="commit" type="submit" value="Create Post" />
|
71
|
+
<a href="/" class="btn">Cancel</a>
|
72
|
+
</div>')
|
73
|
+
end
|
74
|
+
|
42
75
|
test "input fields should have class input-xlarge" do
|
43
76
|
assert_equal @builder.text_field_control(:title),
|
44
77
|
r('<div class="control-group">
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_bootstrap-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
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: 2012-07-
|
12
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|