hstore_radio_buttons 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +35 -2
- data/lib/hstore_radio_buttons.rb +0 -1
- data/lib/hstore_radio_buttons/helpers/form_helper.rb +1 -1
- data/lib/hstore_radio_buttons/method_namer.rb +1 -1
- data/lib/hstore_radio_buttons/version.rb +1 -1
- data/test/lib/hstore_radio_buttons/helpers/form_builder_test.rb +3 -2
- metadata +1 -2
- data/lib/hstore_radio_buttons/formatter.rb +0 -19
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.
|
256
|
-
0.0.
|
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
|
|
data/lib/hstore_radio_buttons.rb
CHANGED
@@ -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 = "#{
|
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))
|
@@ -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>
|
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.
|
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
|