Skip to content

Commit

Permalink
Specifying the button size (e.g. btn-lg) should still generate the …
Browse files Browse the repository at this point in the history
…appropriate button class.
  • Loading branch information
lowjoel committed May 20, 2015
1 parent 6671edd commit e08ded1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
## master

### enhancements

### bug fixes
* Specifying the button size (e.g. `btn-lg`) should still generate the appropriate button class
(`btn-default` or `btn-primary`). [@lowjoel](https://github.com/lowjoel)

## 1.1.0

### enhancements
* There is no longer a need to retain a Simple Form initialiser, as well as a Simple
Form-Bootstrap initialiser. Just call `SimpleForm::setup` and the Bootstrap defaults would be
automatically applied. [@lowjoel](https://github.com/lowjoel)
[@rhodrid](https://github.com/rhodrid)
automatically applied. [@lowjoel](https://github.com/lowjoel)
* Started writing specs and running them on Travis!

### bug fixes
*
5 changes: 4 additions & 1 deletion lib/simple_form/bootstrap/form_builders/button.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module SimpleForm::Bootstrap::FormBuilders::Button
BUTTON_CLASSES = ['btn-default', 'btn-primary', 'btn-success', 'btn-info', 'btn-warning',
'btn-danger', 'btn-link'].freeze

# Adds the btn-default class selectively to buttons which do not have an explicit button type.
def button(type, *args, &proc)
options = args.extract_options!.dup
options[:class] = [*options[:class]]

# Add the specified class type.
if options[:class].select { |cls| cls.length < 4 || cls[0, 4] == 'btn-' }.empty?
if options[:class].select { |cls| BUTTON_CLASSES.include?(cls) }.empty?
if type.to_s == :submit.to_s.freeze
options[:class] << 'btn-primary'
else
Expand Down
8 changes: 8 additions & 0 deletions spec/simple_form/bootstrap/form_builders/button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def test
end
end

context 'when a button size is specified' do
let(:button_class) { ['btn-lg'] }
let(:button_options) { { class: button_class } }
it 'includes the btn-default class' do
expect(rendered).to have_tag('button.btn.btn-default.btn-lg', text: button_text)
end
end

context 'when creating a submit button' do
let(:button_type) { :submit }
context 'when no button class is specified' do
Expand Down

0 comments on commit e08ded1

Please sign in to comment.