bh 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +2 -2
- data/lib/bh/classes/cdn.rb +2 -2
- data/lib/bh/core_ext/rails/form/base_helper.rb +9 -4
- data/lib/bh/core_ext/rails/form/field_helper.rb +1 -1
- data/lib/bh/core_ext/rails/form_builder.rb +2 -0
- data/lib/bh/core_ext/rails/form_for_helper.rb +10 -1
- data/lib/bh/helpers/button_to_helper.rb +9 -1
- data/lib/bh/version.rb +1 -1
- data/spec/rails/form/check_box_helper_spec.rb +17 -0
- data/spec/rails/form/field_helper_spec.rb +17 -0
- data/spec/rails/form/file_field_helper_spec.rb +23 -1
- data/spec/rails/form/radio_button_helper_spec.rb +17 -0
- data/spec/rails/form/select_helper_spec.rb +17 -0
- data/spec/rails/form_for_helper_spec.rb +12 -5
- data/spec/shared/button_to_helper.rb +10 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5ee96b17731875a1201eb7ec0cf89f1835e44ed
|
4
|
+
data.tar.gz: 538d55809b170aa39b2bf7dc533bf57b601627ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34dc9102e88461797920f35beb0192c13590dbffab164262a6451be3e2224b276b68826dff4c389a7e06a1606653a74b12417e9c863c26ab269e0867257eaecc
|
7
|
+
data.tar.gz: 63405566998bc759a03dfb472aa7b96976d9c3580fec01f1497bfdb1eac3ea6c4d58a7a9d0e5cb1cb33ce2c7eaf5a7e3ab42658bb4c39e1f0b3b736bd89158a0
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,16 @@ For more information about changelogs, check
|
|
6
6
|
[Keep a Changelog](http://keepachangelog.com) and
|
7
7
|
[Vandamme](http://tech-angels.github.io/vandamme).
|
8
8
|
|
9
|
+
## 1.3.0 - 2014-02-02
|
10
|
+
|
11
|
+
* [FEATURE] Extend `form_for` to be wrapped in <li> when inside a `nav`, just like `link_to`
|
12
|
+
* [FEATURE] Extend `button_to` to be wrapped in <li> when inside a `nav`, just like `link_to`
|
13
|
+
* [BUGFIX] Match default placeholder with label content (therefore supporting localization)
|
14
|
+
* [ENHANCEMENT] Bootstrappify forms wrapped in `navbar`, setting their class to "navbar-form"
|
15
|
+
* [ENHANCEMENT] Add `:help` option to display a help block after most form fields
|
16
|
+
* [ENHANCEMENT] Bump Bootstrap version to 3.3.2
|
17
|
+
* [ENHANCEMENT] Bump Font Awesome version to 4.3.0
|
18
|
+
|
9
19
|
## 1.2.0 - 2014-11-13
|
10
20
|
|
11
21
|
* [FEATURE] Add support for Middleman and Padrino for all helpers except `form_for`
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Bh · Bootstrap Helpers
|
2
2
|
======================
|
3
3
|
|
4
|
-
|
5
|
-
[Bootstrap 3 components](http://getbootstrap.com/components) in
|
4
|
+
A set of Ruby helpers that streamlines the use of
|
5
|
+
[Bootstrap 3 components](http://getbootstrap.com/components) in HTML views.
|
6
6
|
|
7
7
|
The **full documentation** is available at [rubydoc.info](http://www.rubydoc.info/github/Fullscreen/bh/master/Bh/Helpers).
|
8
8
|
|
data/lib/bh/classes/cdn.rb
CHANGED
@@ -7,14 +7,14 @@ module Bh
|
|
7
7
|
# @note if unspecified, the version should match the latest available
|
8
8
|
# version. If that's not the case, it's a bug and should be fixed.
|
9
9
|
def self.bootstrap(options = {})
|
10
|
-
options[:version] ||= '3.3.
|
10
|
+
options[:version] ||= '3.3.2'
|
11
11
|
cdn_asset options.merge(library: 'bootstrap')
|
12
12
|
end
|
13
13
|
|
14
14
|
# @note if unspecified, the version should match the latest available
|
15
15
|
# version. If that's not the case, it's a bug and should be fixed.
|
16
16
|
def self.font_awesome(options = {})
|
17
|
-
options[:version] ||= '4.
|
17
|
+
options[:version] ||= '4.3.0'
|
18
18
|
cdn_asset options.merge(library: 'font-awesome')
|
19
19
|
end
|
20
20
|
|
@@ -31,10 +31,15 @@ module Bh
|
|
31
31
|
|
32
32
|
def field_tags(errors, field_type, options = {}, &block)
|
33
33
|
prefix, suffix = options.delete(:prefix), options.delete(:suffix)
|
34
|
+
help_text = options.delete(:help)
|
34
35
|
field = @template.capture(&block)
|
35
36
|
tags = [field_in_group(field, prefix, suffix)]
|
36
37
|
tags << error_icon_tag if show_error_icon?(field_type, errors, suffix)
|
37
|
-
|
38
|
+
if errors.any? && show_error_help?
|
39
|
+
tags << help_tag(errors.to_sentence)
|
40
|
+
elsif help_text
|
41
|
+
tags << help_tag(help_text)
|
42
|
+
end
|
38
43
|
safe_join tags
|
39
44
|
end
|
40
45
|
|
@@ -74,10 +79,10 @@ module Bh
|
|
74
79
|
glyphicon :remove, class: 'form-control-feedback'
|
75
80
|
end
|
76
81
|
|
77
|
-
def
|
82
|
+
def help_tag(help_text)
|
78
83
|
klass = ['help-block', 'text-left']
|
79
84
|
klass << 'sr-only' if inline_form?
|
80
|
-
content_tag :span,
|
85
|
+
content_tag :span, help_text, class: klass.join(' ')
|
81
86
|
end
|
82
87
|
|
83
88
|
def label_for(method, errors, options)
|
@@ -117,7 +122,7 @@ module Bh
|
|
117
122
|
end
|
118
123
|
|
119
124
|
def inline_form?
|
120
|
-
@options[:layout].to_s
|
125
|
+
['inline', 'navbar'].include? @options[:layout].to_s
|
121
126
|
end
|
122
127
|
|
123
128
|
def horizontal_form?
|
@@ -6,7 +6,7 @@ module Bh
|
|
6
6
|
include BaseHelper
|
7
7
|
|
8
8
|
def field(method, field_type, options = {}, &block)
|
9
|
-
options[:placeholder] ||= method
|
9
|
+
options[:placeholder] ||= strip_tags(label method)
|
10
10
|
append_class! options, 'form-control'
|
11
11
|
base_field method, field_type, options, &block
|
12
12
|
end
|
@@ -12,6 +12,8 @@ require 'bh/core_ext/rails/form/submit_helper'
|
|
12
12
|
module Bh
|
13
13
|
# @api private
|
14
14
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
15
|
+
include ActionView::Helpers::SanitizeHelper
|
16
|
+
extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
15
17
|
include Form::CheckBoxHelper
|
16
18
|
include Form::FieldHelper
|
17
19
|
include Form::FieldsetHelper
|
@@ -8,8 +8,16 @@ module Bh
|
|
8
8
|
include ActionView::Helpers::FormHelper # for form_for
|
9
9
|
|
10
10
|
def form_for(record, options = {}, &block)
|
11
|
+
options[:layout] ||= 'navbar' if Bh::Stack.find(Bh::Navbar)
|
11
12
|
add_form_options!(options) if options[:layout]
|
12
|
-
super record, options, &block
|
13
|
+
html = super record, options, &block
|
14
|
+
|
15
|
+
if Bh::Stack.find(Bh::Nav)
|
16
|
+
container = Bh::Base.new(self) { html }
|
17
|
+
container.render_tag :li
|
18
|
+
else
|
19
|
+
html
|
20
|
+
end
|
13
21
|
end
|
14
22
|
|
15
23
|
private
|
@@ -23,6 +31,7 @@ module Bh
|
|
23
31
|
|
24
32
|
def class_for(layout)
|
25
33
|
case layout.to_s
|
34
|
+
when 'navbar' then 'navbar-form'
|
26
35
|
when 'inline' then 'form-inline'
|
27
36
|
when 'horizontal' then 'form-horizontal'
|
28
37
|
end
|
@@ -9,6 +9,7 @@ module Bh
|
|
9
9
|
# Only overrides the original method if called with any of the `:context`,
|
10
10
|
# `:size` or `:layout` option, otherwise calls the original method.
|
11
11
|
# @see http://getbootstrap.com/css/#buttons
|
12
|
+
# @see http://getbootstrap.com/components/#nav
|
12
13
|
# @see http://getbootstrap.com/components/#navbar-buttons
|
13
14
|
# @see http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to
|
14
15
|
# @see http://rubydoc.info/gems/padrino-helpers/Padrino/Helpers/FormHelpers#button_to-instance_method
|
@@ -47,11 +48,18 @@ module Bh
|
|
47
48
|
button_to.append_form_class! 'navbar-form' if Bh::Stack.find(Bh::Navbar)
|
48
49
|
end
|
49
50
|
|
50
|
-
if block_given? && button_to.accepts_block?
|
51
|
+
html = if block_given? && button_to.accepts_block?
|
51
52
|
super button_to.url, button_to.attributes, &-> { button_to.content }
|
52
53
|
else
|
53
54
|
super button_to.content, button_to.url, button_to.attributes, &nil
|
54
55
|
end
|
56
|
+
|
57
|
+
if Bh::Stack.find(Bh::Nav)
|
58
|
+
container = Bh::Base.new(self) { html }
|
59
|
+
container.render_tag :li
|
60
|
+
else
|
61
|
+
html
|
62
|
+
end
|
55
63
|
end
|
56
64
|
end
|
57
65
|
end
|
data/lib/bh/version.rb
CHANGED
@@ -23,6 +23,15 @@ describe 'check_box' do
|
|
23
23
|
it { expect(form).to include 'Given name</label>' }
|
24
24
|
end
|
25
25
|
|
26
|
+
context 'not given a help option, does not display a help box' do
|
27
|
+
it { expect(form).not_to include 'help-block' }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'given a help option, displays a help box' do
|
31
|
+
let(:options) { {help: 'Please select an option'} }
|
32
|
+
it { expect(form).to include '<span class="help-block text-left">Please select an option</span>' }
|
33
|
+
end
|
34
|
+
|
26
35
|
specify 'not given an error, does not apply has-error to the form group' do
|
27
36
|
expect(form).not_to include 'has-error'
|
28
37
|
end
|
@@ -83,6 +92,14 @@ describe 'check_box' do
|
|
83
92
|
end
|
84
93
|
end
|
85
94
|
|
95
|
+
context 'given a help message' do
|
96
|
+
let(:options) { {help: 'Please select an option'} }
|
97
|
+
|
98
|
+
specify 'applies sr-only to the help message' do
|
99
|
+
expect(form).to include '<span class="help-block text-left sr-only">Please select an option</span>'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
86
103
|
context 'given the inline_label: false option' do
|
87
104
|
let(:options) { {inline_label: false} }
|
88
105
|
|
@@ -42,6 +42,15 @@ field_helpers_to_test.each do |form_field|
|
|
42
42
|
it { expect(form).to include 'Given name</label>' }
|
43
43
|
end
|
44
44
|
|
45
|
+
context 'not given a help option, does not display a help box' do
|
46
|
+
it { expect(form).not_to include 'help-block' }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'given a help option, displays a help box' do
|
50
|
+
let(:options) { {help: 'Please write the given name'} }
|
51
|
+
it { expect(form).to include '<span class="help-block text-left">Please write the given name</span>' }
|
52
|
+
end
|
53
|
+
|
45
54
|
specify 'not given a prefix or suffix option, does not use an input group' do
|
46
55
|
expect(form).not_to include 'input-group'
|
47
56
|
end
|
@@ -109,6 +118,14 @@ field_helpers_to_test.each do |form_field|
|
|
109
118
|
expect(form).to match %r{<div class="form-group"><label class="sr-only".+?>Name</label><(input|textarea) class="form-control"}
|
110
119
|
end
|
111
120
|
|
121
|
+
context 'given a help message' do
|
122
|
+
let(:options) { {help: 'Please write the given name'} }
|
123
|
+
|
124
|
+
specify 'applies sr-only to the help message' do
|
125
|
+
expect(form).to include '<span class="help-block text-left sr-only">Please write the given name</span>'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
112
129
|
context 'given an error' do
|
113
130
|
before { user.errors.add :name, 'cannot be nil' }
|
114
131
|
|
@@ -7,7 +7,21 @@ describe 'file_field' do
|
|
7
7
|
let(:form) { form_for user, layout: layout, errors: errors, url: '/', &block }
|
8
8
|
let(:user) { User.new }
|
9
9
|
let(:errors) { {} }
|
10
|
-
let(:block) { Proc.new {|f| f.file_field :name, accept: 'text/html'} }
|
10
|
+
let(:block) { Proc.new {|f| f.file_field :name, options.merge(accept: 'text/html')} }
|
11
|
+
let(:options) { {} }
|
12
|
+
|
13
|
+
context 'given any layout' do
|
14
|
+
let(:layout) { :whatever }
|
15
|
+
|
16
|
+
context 'not given a help option, does not display a help box' do
|
17
|
+
it { expect(form).not_to include 'help-block' }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'given a help option, displays a help box' do
|
21
|
+
let(:options) { {help: 'Please upload a file'} }
|
22
|
+
it { expect(form).to include '<span class="help-block text-left">Please upload a file</span>' }
|
23
|
+
end
|
24
|
+
end
|
11
25
|
|
12
26
|
describe 'given a basic layout' do
|
13
27
|
let(:layout) { :basic }
|
@@ -41,6 +55,14 @@ describe 'file_field' do
|
|
41
55
|
expect(form).not_to match 'form-control'
|
42
56
|
end
|
43
57
|
|
58
|
+
context 'given a help message' do
|
59
|
+
let(:options) { {help: 'Please select a file'} }
|
60
|
+
|
61
|
+
specify 'applies sr-only to the help message' do
|
62
|
+
expect(form).to include '<span class="help-block text-left sr-only">Please select a file</span>'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
44
66
|
context 'given an error' do
|
45
67
|
before { user.errors.add :name, 'cannot be nil' }
|
46
68
|
|
@@ -22,6 +22,15 @@ describe 'radio_button' do
|
|
22
22
|
it { expect(form).to include '> Jerry</label>' }
|
23
23
|
end
|
24
24
|
|
25
|
+
context 'not given a help option, does not display a help box' do
|
26
|
+
it { expect(form).not_to include 'help-block' }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'given a help option, displays a help box' do
|
30
|
+
let(:options) { {help: 'Please select an option'} }
|
31
|
+
it { expect(form).to include '<span class="help-block text-left">Please select an option</span>' }
|
32
|
+
end
|
33
|
+
|
25
34
|
specify 'not given an error, does not apply has-error to the form group' do
|
26
35
|
expect(form).not_to include 'has-error'
|
27
36
|
end
|
@@ -56,6 +65,14 @@ describe 'radio_button' do
|
|
56
65
|
expect(form).to match %r{<div class="radio"><label><input.+? /> Jeremy</label></div>}
|
57
66
|
end
|
58
67
|
|
68
|
+
context 'given a help message' do
|
69
|
+
let(:options) { {help: 'Please select an option'} }
|
70
|
+
|
71
|
+
specify 'applies sr-only to the help message' do
|
72
|
+
expect(form).to include '<span class="help-block text-left sr-only">Please select an option</span>'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
59
76
|
context 'given an error' do
|
60
77
|
before { user.errors.add :name, 'cannot be nil' }
|
61
78
|
|
@@ -22,6 +22,15 @@ describe 'select' do
|
|
22
22
|
it { expect(form).to include 'Given name</label>' }
|
23
23
|
end
|
24
24
|
|
25
|
+
context 'not given a help option, does not display a help box' do
|
26
|
+
it { expect(form).not_to include 'help-block' }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'given a help option, displays a help box' do
|
30
|
+
let(:options) { {help: 'Please select an option'} }
|
31
|
+
it { expect(form).to include '<span class="help-block text-left">Please select an option</span>' }
|
32
|
+
end
|
33
|
+
|
25
34
|
specify 'not given an error, does not apply has-error to the form group' do
|
26
35
|
expect(form).not_to include 'has-error'
|
27
36
|
end
|
@@ -60,6 +69,14 @@ describe 'select' do
|
|
60
69
|
expect(form).to match %r{<div class="form-group"><label class="sr-only".+?>Name</label><select class="form-control"}
|
61
70
|
end
|
62
71
|
|
72
|
+
context 'given a help message' do
|
73
|
+
let(:options) { {help: 'Please select an option'} }
|
74
|
+
|
75
|
+
specify 'applies sr-only to the help message' do
|
76
|
+
expect(form).to include '<span class="help-block text-left sr-only">Please select an option</span>'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
63
80
|
context 'given an error' do
|
64
81
|
before { user.errors.add :name, 'cannot be nil' }
|
65
82
|
|
@@ -3,16 +3,23 @@ require 'bh/core_ext/rails/form_for_helper'
|
|
3
3
|
include Bh::Rails::Helpers
|
4
4
|
|
5
5
|
describe 'form_for' do
|
6
|
+
let(:bh) { RailsView.new }
|
6
7
|
let(:protect_against_forgery?) { false }
|
7
8
|
attr_accessor :output_buffer
|
8
9
|
let(:form) { form_for(:object, options.merge(url: '/')) {} }
|
10
|
+
let(:options) { {} }
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
specify 'by default, does not apply Bootstrap attributes to the form' do
|
13
|
+
expect(form).not_to include 'role="form"'
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
specify 'wrapped in navbar, applies Bootstrap attributes of a navbar form' do
|
17
|
+
bh.navbar { expect(form).to include 'role="form"' }
|
18
|
+
bh.navbar { expect(form).to include 'class="navbar-form"' }
|
19
|
+
end
|
20
|
+
|
21
|
+
specify 'wrapped in nav, surrounds the form in a <li> item' do
|
22
|
+
bh.nav { expect(form).to match %r{^<li><form.+?</form></li>$} }
|
16
23
|
end
|
17
24
|
|
18
25
|
describe 'with layout: :horizontal' do
|
@@ -3,6 +3,7 @@ shared_examples_for 'the button_to helper' do
|
|
3
3
|
all_tests_pass_with 'the :size button_to option'
|
4
4
|
all_tests_pass_with 'the :layout button_to option'
|
5
5
|
all_tests_pass_with 'the button wrapped in navbar'
|
6
|
+
all_tests_pass_with 'the button wrapped in nav'
|
6
7
|
end
|
7
8
|
|
8
9
|
#--
|
@@ -39,4 +40,12 @@ shared_examples_for 'the button wrapped in navbar' do
|
|
39
40
|
html = %r{^<form.+class="navbar-form"}
|
40
41
|
bh.navbar { expect(button_to: {context: :default}).to generate html }
|
41
42
|
end
|
42
|
-
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
shared_examples_for 'the button wrapped in nav' do
|
47
|
+
specify 'surrounds the form in a <li> item' do
|
48
|
+
html = %r{^<li><form.+?</form></li>}
|
49
|
+
bh.nav { expect(:button_to).to generate html }
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claudio Baccigalupo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -320,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
320
320
|
version: '0'
|
321
321
|
requirements: []
|
322
322
|
rubyforge_project:
|
323
|
-
rubygems_version: 2.
|
323
|
+
rubygems_version: 2.4.5
|
324
324
|
signing_key:
|
325
325
|
specification_version: 4
|
326
326
|
summary: Bh provides a set of powerful helpers that streamlines the use of Bootstrap
|