effective_form_inputs 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70ab15ba6a6ca6aa19cbb4cb883fdbdd3e754b76
4
- data.tar.gz: c3468e9539e7a91fd5d61a0a2393ab72718a49c2
3
+ metadata.gz: c7900d6d68d9ad85c83f13437bf38defa3ab74a5
4
+ data.tar.gz: 1a420193c6931459879b81257cab65dc7f46725e
5
5
  SHA512:
6
- metadata.gz: 57dba2ff14677bea5a9b8085865cf69a8810359b4f4b76d64a74d2cab5571646d172d3e22537ff0ed7feacb7404ae1b0a261329e809b4f35169cac112728bb6c
7
- data.tar.gz: 0ed08a3df3d337401cd8e435d3358503513bf882c650f8d539682ac0f4e7a15a787d4f4e267482bb7509b8dea64d940267f4ad02cb7ec9d2900d397bdc53c6bf
6
+ metadata.gz: fb6e75dbcd8068f41950bbd0c37de005860470d4a7e29d2e6266424b68641280ed3aad58374faba20a418558ea5301e5ed0dea17161a6da114895e662e595034
7
+ data.tar.gz: ab2d3f112626f0f2a721762b150a620140d95a8a0ad3d415dea61b97d303c9914c23ce10ebfce1957d3ba39a1c841011c8fd993a36628f74707db2bdddfe08dd
data/README.md CHANGED
@@ -691,7 +691,9 @@ To install this form input individually, add the following to your application.c
691
691
 
692
692
  There is no javascript.
693
693
 
694
- ### Usage
694
+ ### Bootstrap button group
695
+
696
+ Pass `buttons: true` to the input options to render as a bootstrap button group.
695
697
 
696
698
  As a SimpleForm input:
697
699
 
@@ -700,13 +702,20 @@ As a SimpleForm input:
700
702
  = f.input :breakfast,
701
703
  :as => :effective_radio_buttons,
702
704
  :collection => ['eggs', 'toast', 'bacon'],
703
- :images => [asset_path('eggs.png'), asset_path('toast.png'), asset_path('bacon.png')]
705
+ :buttons => true
704
706
  ```
705
707
 
706
- ### Options
708
+ ### Images
707
709
 
708
- The only additional option is `images: []`, which must be an array of strings the same length as the collection.
710
+ Pass `images: []` as an array of strings with the same length as the collection to render image buttons.
709
711
 
712
+ ```ruby
713
+ = simple_form_for @user do |f|
714
+ = f.input :breakfast,
715
+ :as => :effective_radio_buttons,
716
+ :collection => ['eggs', 'toast', 'bacon'],
717
+ :images => [asset_path('eggs.png'), asset_path('toast.png'), asset_path('bacon.png')]
718
+ ```
710
719
 
711
720
  ## License
712
721
 
@@ -19,18 +19,22 @@ module Inputs
19
19
 
20
20
  def to_html
21
21
  initialize_and_validate_images!
22
- collection_radio_buttons(@object_name, @method, collection, options[:value_method], options[:label_method], {}, item_html_options, &proc { |builder| render_item(builder) })
22
+ collection_radio_buttons(@object_name, @method, collection, options[:value_method], options[:label_method], options.slice(:checked), item_html_options, &proc { |builder| render_item(builder) })
23
23
  end
24
24
 
25
25
  def render_item(builder)
26
- if options[:nested_boolean_style] == :nested
26
+ if options[:nested_boolean_style] == :nested || options[:buttons]
27
27
  item = builder.label { builder.radio_button + item_image_or_text(builder) }
28
28
  else
29
29
  item = builder.radio_button + builder.label { item_image_or_text(builder) }
30
30
  end
31
31
 
32
32
  if options[:item_wrapper_tag]
33
- content_tag(options[:item_wrapper_tag], item, class: options[:item_wrapper_class])
33
+ active = (builder.object.send(options[:value_method]).to_s == value.to_s)
34
+
35
+ content_tag(options[:item_wrapper_tag], item,
36
+ class: ['btn', 'btn-default', options[:item_wrapper_class], ('active' if active)].flatten.uniq.join(' ')
37
+ )
34
38
  else
35
39
  item
36
40
  end
@@ -63,6 +67,10 @@ module Inputs
63
67
  end
64
68
  end
65
69
 
70
+ def value
71
+ options[:checked] || super
72
+ end
73
+
66
74
  private
67
75
 
68
76
  def initialize_and_validate_images!
@@ -15,6 +15,10 @@ if defined?(SimpleForm)
15
15
  if options[:images]
16
16
  options[:wrapper_html] ||= {}
17
17
  options[:wrapper_html][:class] = "#{options[:wrapper_html][:class]} image_radio_buttons".strip
18
+ elsif options[:buttons]
19
+ options[:wrapper_html] ||= {}
20
+ options[:wrapper_html][:class] = "#{options[:wrapper_html][:class]} button_radio_buttons btn-group".strip
21
+ options[:wrapper_html][:data] = { toggle: 'buttons' }
18
22
  end
19
23
 
20
24
  Inputs::EffectiveRadioButtons::Input.new(object, object_name, template, attribute_name, input_options, (merge_wrapper_options(input_html_options, wrapper_options) || {})).to_html
@@ -11,7 +11,7 @@ module Inputs
11
11
  if value.kind_of?(String) && value.start_with?('<p>') && value.end_with?('</p>')
12
12
  content_tag(:p, value[3...-4].html_safe, tag_options)
13
13
  else
14
- content_tag(:p, (value.html_safe? ? value : value.to_s.html_safe), tag_options)
14
+ content_tag(:p, (value.html_safe? ? value : (value.to_s || '').html_safe), tag_options)
15
15
  end
16
16
 
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveFormInputs
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_form_inputs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-04 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails