hstore_radio_buttons 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -221,6 +221,38 @@ your own:
221
221
  If you need more control, you should probably just use the Rails helpers
222
222
  approach.
223
223
 
224
+ #### Customizing the label for a button set.
225
+
226
+ If you define a button set like this:
227
+
228
+ person:
229
+ gender:
230
+ - male
231
+ - female
232
+ - other
233
+
234
+ And then do a render like:
235
+
236
+ <%= f.label(:gender) %>
237
+ or
238
+ <%= f.hstore_radio_button(:gender) %>
239
+
240
+ Then your button set will start with the label "Gender". But what if you
241
+ want something else? Use the [Rails translations api](http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models). So in your en.yml file, you could put:
242
+
243
+ en:
244
+ activerecord:
245
+ attributes:
246
+ person:
247
+ gender: "Please pick a gender"
248
+
249
+ And your radio button set will render as:
250
+
251
+ Please pick a gender
252
+ o Male
253
+ o Female
254
+ o Other
255
+
224
256
  ### Persistence
225
257
 
226
258
  The conversion of your data into an hstore is handled by
@@ -252,8 +284,9 @@ contributed by [Davin Lagerroos](https://github.com/davinlagerroos).
252
284
 
253
285
  ### Versions
254
286
 
255
- 0.0.2 - Fixes to inconsistency in how you call buttons by name.
256
- 0.0.1 - Initial
287
+ - 0.0.3 - Added support to customize button-set labels with Rails Internationalization API
288
+ - 0.0.2 - Fixes to inconsistency in how you call buttons by name.
289
+ - 0.0.1 - Initial
257
290
 
258
291
  ## Contributing
259
292
 
@@ -7,7 +7,6 @@ require 'hstore_radio_buttons/configuration'
7
7
  require 'hstore_radio_buttons/button_options'
8
8
  require 'hstore_radio_buttons/button_set'
9
9
  require 'hstore_radio_buttons/method_namer'
10
- require 'hstore_radio_buttons/formatter'
11
10
  require 'hstore_radio_buttons/helpers/form_helper'
12
11
 
13
12
  module HstoreRadioButtons
@@ -16,7 +16,7 @@ module HstoreRadioButtons::FormBuilder
16
16
  options[:separator] = (options[:separator] ? options[:separator] : "<br />")
17
17
  methods = HstoreRadioButtons::MethodNamer.new(method)
18
18
 
19
- button_set = "#{HstoreRadioButtons::Formatter.new(method).to_title}#{options[:separator]}"
19
+ button_set = "#{object.class.human_attribute_name(methods.getter)}#{options[:separator]}"
20
20
 
21
21
  object.public_send(methods.options).each do |radio_option|
22
22
  button_set += @template.hstore_radio_button(@object_name, methods.getter, radio_option, objectify_options(options))
@@ -1,7 +1,7 @@
1
1
  module HstoreRadioButtons
2
2
  class MethodNamer
3
3
  def initialize(button_name)
4
- self.button_name = HstoreRadioButtons::Formatter.new(button_name).to_method
4
+ self.button_name = button_name.to_s.gsub(/ /,"_").downcase
5
5
  end
6
6
 
7
7
  def setter
@@ -1,3 +1,3 @@
1
1
  module HstoreRadioButtons
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -31,10 +31,11 @@ class FormBuilderTest < ActionView::TestCase
31
31
  assert_match /<\/div>$/, it.hstore_radio_button(:gender)
32
32
  end
33
33
 
34
- test "FormBuilder#hstore_radio_button returns a set of buttons that are prefaced with the button set's name" do
34
+ test "FormBuilder#hstore_radio_button returns a set of buttons that are prefaced with the button set's human name" do
35
35
  view.stubs(:hstore_radio_button).with(any_parameters).returns("")
36
+ Person.stubs(:human_attribute_name).with(:gender).returns("Pick a gender?")
36
37
  it = ActionView::Helpers::FormBuilder.new(:person, @person_instance, view, {}, proc {})
37
- assert_match /^<div>Gender/, it.hstore_radio_button(:gender)
38
+ assert_match /^<div>Pick a gender?/, it.hstore_radio_button(:gender)
38
39
  end
39
40
 
40
41
  test "#hstore_radio_button accepts a separator, which will be used to separate the button-set header from the buttons" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hstore_radio_buttons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -160,7 +160,6 @@ files:
160
160
  - lib/hstore_radio_buttons/button_options.rb
161
161
  - lib/hstore_radio_buttons/button_set.rb
162
162
  - lib/hstore_radio_buttons/configuration.rb
163
- - lib/hstore_radio_buttons/formatter.rb
164
163
  - lib/hstore_radio_buttons/helpers/form_helper.rb
165
164
  - lib/hstore_radio_buttons/hstore_radio_data.rb
166
165
  - lib/hstore_radio_buttons/method_namer.rb
@@ -1,19 +0,0 @@
1
- module HstoreRadioButtons
2
- class Formatter
3
- def initialize(raw_button_name)
4
- self.raw_button_name = raw_button_name
5
- end
6
-
7
- def to_method
8
- raw_button_name.to_s.gsub(/ /,"_").downcase
9
- end
10
-
11
- def to_title
12
- raw_button_name.to_s.gsub(/_/," ").titleize
13
- end
14
-
15
- private
16
-
17
- attr_accessor :raw_button_name
18
- end
19
- end