bh 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +17 -15
- data/lib/bh/form_builders/form_builder.rb +3 -1
- data/lib/bh/helpers/alert_helper.rb +1 -1
- data/lib/bh/helpers/form/fields_for_helper.rb +7 -3
- data/lib/bh/helpers/form/file_field_helper.rb +15 -0
- data/lib/bh/version.rb +1 -1
- data/spec/helpers/form/field_helper_spec.rb +1 -1
- data/spec/helpers/form/fields_for_helper_spec.rb +15 -1
- data/spec/helpers/form/file_field_helper_spec.rb +52 -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: 391d2887c75ed952c021d758e428f486de5f5f15
|
4
|
+
data.tar.gz: 15037d24fab141aaf1d7623e39aad31e44312197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b525dc2a2c86b8952d65e078e808a39e3c3cfa8eaa25d3b2d4fac61bb8a412594375a367cc3478d6d0b79a35c8b1ab2a3decd688c356cc0dfd5ddafce0596ccf
|
7
|
+
data.tar.gz: 5acccce283c5abaae55615bb02c3fece400ffac531c94456cd334893bfa2f1bef71e55949b8faf7d0245c133f6160bebd89bb14f1ca046baa0780b7be3721b72
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ 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.0.1 - 2014-09-14
|
10
|
+
|
11
|
+
* [BUGFIX] Remove `form-control` class from `file_field` (#20)
|
12
|
+
* [BUGFIX] Allow `record_object` to be passed to `fields_for` (#22)
|
13
|
+
|
9
14
|
## 1.0.0 - 2014-09-09
|
10
15
|
|
11
16
|
* No changes
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@ Bh · Bootstrap Helpers
|
|
2
2
|
======================
|
3
3
|
|
4
4
|
Bh provides a set of helpers that streamlines the use of
|
5
|
-
[Bootstrap components](http://getbootstrap.com/components) in Ruby views.
|
5
|
+
[Bootstrap 3 components](http://getbootstrap.com/components) in Ruby views.
|
6
6
|
|
7
7
|
The **full documentation** is available at [rubydoc.info](http://rubydoc.info/github/Fullscreen/bh/master/frames).
|
8
8
|
|
@@ -13,7 +13,7 @@ The **full documentation** is available at [rubydoc.info](http://rubydoc.info/gi
|
|
13
13
|
[![Online docs](http://img.shields.io/badge/docs-✓-green.svg)](http://rubydoc.info/github/Fullscreen/bh/master/frames)
|
14
14
|
[![Gem Version](http://img.shields.io/gem/v/bh.svg)](http://rubygems.org/gems/bh)
|
15
15
|
|
16
|
-
Bootstrap is a great framework, but requires
|
16
|
+
Bootstrap 3 is a great framework, but requires many lines of HTML code
|
17
17
|
even for simple components.
|
18
18
|
For instance, you need to write the following HTML to show a _dismissible alert_:
|
19
19
|
|
@@ -27,19 +27,18 @@ For instance, you need to write the following HTML to show a _dismissible alert_
|
|
27
27
|
</div>
|
28
28
|
```
|
29
29
|
|
30
|
-
Writing this for every _dismissible alert_
|
30
|
+
Writing this for every _dismissible alert_ is cumbersome,
|
31
31
|
repetitive, and prone to errors.
|
32
32
|
|
33
|
-
Bh
|
34
|
-
The example above can be rewritten with just one line of code:
|
33
|
+
With Bh, you can achieve the same thing with just one line of code:
|
35
34
|
|
36
35
|
```rhtml
|
37
36
|
<%= alert_box 'You accepted the Terms of service.', dismissible: true %>
|
38
37
|
```
|
39
38
|
|
40
|
-
`alert_box` is only of the helpers provided by Bh
|
41
|
-
You can use
|
42
|
-
of writing Bootstrap components (many HTML lines) with the "Bh way".
|
39
|
+
`alert_box` is only one of the helpers provided by Bh.
|
40
|
+
You can use the helpers you need and even mix-and-match the "standard way"
|
41
|
+
of writing Bootstrap 3 components (many HTML lines) with the "Bh way".
|
43
42
|
|
44
43
|
A comprehensive guide to Bh helpers
|
45
44
|
===================================
|
@@ -56,12 +55,11 @@ How to install
|
|
56
55
|
|
57
56
|
Bh is meant to be included in Rails apps by adding this line to the Gemfile:
|
58
57
|
|
59
|
-
gem 'bh', '~> 1.0
|
58
|
+
gem 'bh', '~> 1.0'
|
60
59
|
|
61
|
-
Since the gem follows [Semantic Versioning](http://semver.org),
|
62
|
-
|
63
|
-
|
64
|
-
and a new version of Bh is released.
|
60
|
+
Since the gem follows [Semantic Versioning](http://semver.org), indicating the
|
61
|
+
version number in your Gemfile in the *'~> major.minor'* format guarantees
|
62
|
+
that your project won’t break when you `bundle update` to a new version.
|
65
63
|
|
66
64
|
Adding `bh` to your Gemfile is all you need!
|
67
65
|
From now on, you will be able to use any Bh helper in your ERB views.
|
@@ -93,8 +91,12 @@ document the changes in CHANGELOG.md and README.md, bump the version, then run
|
|
93
91
|
rake release
|
94
92
|
|
95
93
|
Remember that the bh gem follows [Semantic Versioning](http://semver.org).
|
96
|
-
|
97
|
-
Any new
|
94
|
+
|
95
|
+
Any new release that makes backward-compatible bug fixes should bump the *patch* version (1.0.x).
|
96
|
+
|
97
|
+
Any new release that adds backward-compatible features should bump the *minor* version (1.x.0).
|
98
|
+
|
99
|
+
Any new version that breaks compatibility should bump the *major* version (2.0.0)
|
98
100
|
|
99
101
|
How to contribute
|
100
102
|
=================
|
@@ -2,6 +2,7 @@ require 'bh/helpers/form/check_box_helper'
|
|
2
2
|
require 'bh/helpers/form/field_helper'
|
3
3
|
require 'bh/helpers/form/fieldset_helper'
|
4
4
|
require 'bh/helpers/form/fields_for_helper'
|
5
|
+
require 'bh/helpers/form/file_field_helper'
|
5
6
|
require 'bh/helpers/form/legend_helper'
|
6
7
|
require 'bh/helpers/form/radio_button_helper'
|
7
8
|
require 'bh/helpers/form/select_helper'
|
@@ -14,6 +15,7 @@ module Bh
|
|
14
15
|
include Form::FieldHelper
|
15
16
|
include Form::FieldsetHelper
|
16
17
|
include Form::FieldsForHelper
|
18
|
+
include Form::FileFieldHelper
|
17
19
|
include Form::LegendHelper
|
18
20
|
include Form::RadioButtonHelper
|
19
21
|
include Form::SelectHelper
|
@@ -24,7 +26,7 @@ module Bh
|
|
24
26
|
# strings in ActionView 3
|
25
27
|
def self.textual_field_helpers
|
26
28
|
non_textual_field_helpers = %w(label hidden_field range_field check_box
|
27
|
-
radio_button select submit fields_for label)
|
29
|
+
file_field radio_button select submit fields_for label)
|
28
30
|
field_helpers.map(&:to_s) - non_textual_field_helpers
|
29
31
|
end
|
30
32
|
|
@@ -11,7 +11,7 @@ module Bh
|
|
11
11
|
#
|
12
12
|
# The message to display in the alert can either be passed as the first
|
13
13
|
# parameter (in which case, the options are the second parameter), or as
|
14
|
-
# a block (in which case, the options are the first
|
14
|
+
# a block (in which case, the options are the first parameter).
|
15
15
|
# @example An alert with a plain-text message passed as the first parameter.
|
16
16
|
# alert 'User updated successfully', dismissible: true
|
17
17
|
# @example An alert with an HTML message passed as a block.
|
@@ -6,11 +6,15 @@ module Bh
|
|
6
6
|
include BaseHelper
|
7
7
|
include FieldsetHelper # for fieldset
|
8
8
|
|
9
|
-
def fields_for(record_object = nil, fields_options = {}, &block)
|
9
|
+
def fields_for(record_name, record_object = nil, fields_options = {}, &block)
|
10
|
+
if record_object.is_a?(Hash) && record_object.extractable_options?
|
11
|
+
record_object, fields_options = nil, record_object
|
12
|
+
end
|
13
|
+
|
10
14
|
fields_options[:layout] ||= @options[:layout]
|
11
15
|
fields_options[:errors] ||= @options[:errors]
|
12
|
-
title = fields_options.delete(:title) {
|
13
|
-
fieldset(title) { super record_object, fields_options, &block }
|
16
|
+
title = fields_options.delete(:title) { record_name.to_s.humanize }
|
17
|
+
fieldset(title) { super record_name, record_object, fields_options, &block }
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
data/lib/bh/version.rb
CHANGED
@@ -3,7 +3,7 @@ require 'bh/helpers/form_for_helper'
|
|
3
3
|
include Bh::FormForHelper
|
4
4
|
|
5
5
|
def self.field_helpers_to_test
|
6
|
-
types = %w(email
|
6
|
+
types = %w(email number password phone search telephone text url)
|
7
7
|
if defined?(ActionView::VERSION) # only defined in ActionView >=4
|
8
8
|
# types.concat %w(color date datetime datetime_local month time week)
|
9
9
|
end
|
@@ -4,7 +4,8 @@ include Bh::FormForHelper
|
|
4
4
|
|
5
5
|
describe 'fields_for' do
|
6
6
|
let(:protect_against_forgery?) { false }
|
7
|
-
let(:form) { form_for
|
7
|
+
let(:form) { form_for user, layout: layout, url: '/', &block }
|
8
|
+
let(:user) { User.new }
|
8
9
|
let(:layout) { :whatever }
|
9
10
|
let(:block) { Proc.new {|f| f.fields_for :address, options, &fields_block } }
|
10
11
|
let(:options) { {} }
|
@@ -32,4 +33,17 @@ describe 'fields_for' do
|
|
32
33
|
let(:options) { {layout: :horizontal} }
|
33
34
|
it { expect(form).to match %r{<div class="form-group"><label class="col-sm-3 control-label" for.+?>Street</label>} }
|
34
35
|
end
|
36
|
+
|
37
|
+
context 'given a record object' do
|
38
|
+
let(:block) { Proc.new {|f| f.fields_for :address, user.name, options, &fields_block } }
|
39
|
+
|
40
|
+
specify 'and no other options, uses the provided record object' do
|
41
|
+
expect(form).to include 'fieldset class="panel panel-default">'
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'and other options, uses the provided record object and options' do
|
45
|
+
let(:options) { {title: 'Your address'} }
|
46
|
+
it { expect(form).to include '<div class="panel-heading">Your address</div>' }
|
47
|
+
end
|
48
|
+
end
|
35
49
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bh/helpers/form_for_helper'
|
3
|
+
include Bh::FormForHelper
|
4
|
+
|
5
|
+
describe 'file_field' do
|
6
|
+
let(:protect_against_forgery?) { false }
|
7
|
+
let(:form) { form_for user, layout: layout, errors: errors, url: '/', &block }
|
8
|
+
let(:user) { User.new }
|
9
|
+
let(:errors) { {} }
|
10
|
+
let(:block) { Proc.new {|f| f.file_field :name, accept: 'text/html'} }
|
11
|
+
|
12
|
+
describe 'given a basic layout' do
|
13
|
+
let(:layout) { :basic }
|
14
|
+
specify 'applies form-group to the container to the input' do
|
15
|
+
expect(form).to match %r{<div class="form-group"><label.+?>Name</label><(input|textarea)}
|
16
|
+
end
|
17
|
+
|
18
|
+
specify 'does not apply form-control to the input' do
|
19
|
+
expect(form).not_to match 'form-control'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'given a horizontal layout' do
|
24
|
+
let(:layout) { :horizontal }
|
25
|
+
specify 'applies form-group to the container, col-sm-3.control-label to the label and col-sm-9 to the field container' do
|
26
|
+
expect(form).to match %r{<div class="form-group"><label class="col-sm-3 control-label".+?>Name</label><div class="col-sm-9"><(input|textarea)}
|
27
|
+
end
|
28
|
+
|
29
|
+
specify 'does not apply form-control to the input' do
|
30
|
+
expect(form).not_to match 'form-control'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'given an inline layout' do
|
35
|
+
let(:layout) { :inline }
|
36
|
+
specify 'applies form-group to the container, sr-only to the label' do
|
37
|
+
expect(form).to match %r{<div class="form-group"><label class="sr-only".+?>Name</label><(input|textarea)}
|
38
|
+
end
|
39
|
+
|
40
|
+
specify 'does not apply form-control to the input' do
|
41
|
+
expect(form).not_to match 'form-control'
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'given an error' do
|
45
|
+
before { user.errors.add :name, 'cannot be nil' }
|
46
|
+
|
47
|
+
specify 'applies sr-only to the error message' do
|
48
|
+
expect(form).to include '<span class="help-block text-left sr-only">cannot be nil</span>'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
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.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claudio Baccigalupo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/bh/helpers/form/field_helper.rb
|
152
152
|
- lib/bh/helpers/form/fields_for_helper.rb
|
153
153
|
- lib/bh/helpers/form/fieldset_helper.rb
|
154
|
+
- lib/bh/helpers/form/file_field_helper.rb
|
154
155
|
- lib/bh/helpers/form/legend_helper.rb
|
155
156
|
- lib/bh/helpers/form/radio_button_helper.rb
|
156
157
|
- lib/bh/helpers/form/select_helper.rb
|
@@ -174,6 +175,7 @@ files:
|
|
174
175
|
- spec/helpers/form/field_helper_spec.rb
|
175
176
|
- spec/helpers/form/fields_for_helper_spec.rb
|
176
177
|
- spec/helpers/form/fieldset_helper_spec.rb
|
178
|
+
- spec/helpers/form/file_field_helper_spec.rb
|
177
179
|
- spec/helpers/form/legend_helper_spec.rb
|
178
180
|
- spec/helpers/form/radio_button_helper_spec.rb
|
179
181
|
- spec/helpers/form/select_helper_spec.rb
|
@@ -221,6 +223,7 @@ test_files:
|
|
221
223
|
- spec/helpers/form/field_helper_spec.rb
|
222
224
|
- spec/helpers/form/fields_for_helper_spec.rb
|
223
225
|
- spec/helpers/form/fieldset_helper_spec.rb
|
226
|
+
- spec/helpers/form/file_field_helper_spec.rb
|
224
227
|
- spec/helpers/form/legend_helper_spec.rb
|
225
228
|
- spec/helpers/form/radio_button_helper_spec.rb
|
226
229
|
- spec/helpers/form/select_helper_spec.rb
|