Cache other required options and fix typo
This commit is contained in:
parent
176e52f139
commit
057df0c632
|
@ -1,7 +1,7 @@
|
||||||
module SimpleForm
|
module SimpleForm
|
||||||
# A lot of configuration valeus are retrived from I18n,
|
# A lot of configuration values are retrived from I18n,
|
||||||
# like boolean collection, required string. This module provides
|
# like boolean collection, required string. This module provides
|
||||||
# caching facility to speed up form construciton.
|
# caching facility to speed up form construction.
|
||||||
module I18nCache
|
module I18nCache
|
||||||
def i18n_cache(key)
|
def i18n_cache(key)
|
||||||
get_i18n_cache(key)[I18n.locale] ||= yield.freeze
|
get_i18n_cache(key)[I18n.locale] ||= yield.freeze
|
||||||
|
|
|
@ -15,13 +15,17 @@ module SimpleForm
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate_required_text
|
def translate_required_text
|
||||||
|
i18n_cache :translate_required_text do
|
||||||
I18n.t(:"simple_form.required.text", :default => 'required')
|
I18n.t(:"simple_form.required.text", :default => 'required')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def translate_required_mark
|
def translate_required_mark
|
||||||
|
i18n_cache :translate_required_mark do
|
||||||
I18n.t(:"simple_form.required.mark", :default => '*')
|
I18n.t(:"simple_form.required.mark", :default => '*')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,9 @@ require 'test_helper'
|
||||||
class LabelTest < ActionView::TestCase
|
class LabelTest < ActionView::TestCase
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
SimpleForm::FormBuilder.reset_i18n_cache :translate_required_string
|
[:string, :text, :mark].each do |cache|
|
||||||
|
SimpleForm::FormBuilder.reset_i18n_cache :"translate_required_#{cache}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'input should generate a label with the text field' do
|
test 'input should generate a label with the text field' do
|
||||||
|
|
Loading…
Reference in New Issue