Changed call to label_text to always pass the new thrid parameter, and made the default a proc that ignores it. This is a breaking change.
This commit is contained in:
parent
5fa75a1115
commit
cdf43ea3ea
|
@ -66,7 +66,7 @@ module SimpleForm
|
|||
|
||||
# How the label text should be generated altogether with the required text.
|
||||
mattr_accessor :label_text
|
||||
@@label_text = lambda { |label, required| "#{required} #{label}" }
|
||||
@@label_text = proc { |label, required| "#{required} #{label}" }
|
||||
|
||||
# You can define the class to be used on all labels. Defaults to none.
|
||||
mattr_accessor :label_class
|
||||
|
|
|
@ -30,11 +30,7 @@ module SimpleForm
|
|||
end
|
||||
|
||||
def label_text
|
||||
@label_text_extended ||= SimpleForm.label_text.parameters.size == 3
|
||||
(@label_text_extended ?
|
||||
SimpleForm.label_text.call(raw_label_text, required_label_text, options[:label].present?) :
|
||||
SimpleForm.label_text.call(raw_label_text, required_label_text))
|
||||
.strip.html_safe
|
||||
SimpleForm.label_text.call(raw_label_text, required_label_text, options[:label].present?).strip.html_safe
|
||||
end
|
||||
|
||||
def label_target
|
||||
|
|
|
@ -63,21 +63,21 @@ class LabelTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'builder allows label order to be changed' do
|
||||
swap SimpleForm, label_text: lambda { |l, r| "#{l}:" } do
|
||||
swap SimpleForm, label_text: proc { |l, r| "#{l}:" } do
|
||||
with_label_for @user, :age
|
||||
assert_select 'label.integer[for=user_age]', "Age:"
|
||||
end
|
||||
end
|
||||
|
||||
test 'builder should allow custom formatting when label is explicitly specified' do
|
||||
swap SimpleForm, label_text: lambda {|l, r, explicit| explicit ? l : "#{l.titleize}:" } do
|
||||
swap SimpleForm, label_text: proc {|l, r, explicit| explicit ? l : "#{l.titleize}:" } do
|
||||
with_label_for @user, :time_zone, 'What is your home time zone?'
|
||||
assert_select 'label[for=user_time_zone]', 'What is your home time zone?'
|
||||
end
|
||||
end
|
||||
|
||||
test 'builder should allow custom formatting when label is generated' do
|
||||
swap SimpleForm, label_text: lambda {|l, r, explicit| explicit ? l : "#{l.titleize}:" } do
|
||||
swap SimpleForm, label_text: proc {|l, r, explicit| explicit ? l : "#{l.titleize}:" } do
|
||||
with_label_for @user, :time_zone
|
||||
assert_select 'label[for=user_time_zone]', 'Time Zone:'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue