Cache other required options and fix typo
This commit is contained in:
parent
176e52f139
commit
057df0c632
|
@ -1,12 +1,12 @@
|
|||
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
|
||||
# caching facility to speed up form construciton.
|
||||
# caching facility to speed up form construction.
|
||||
module I18nCache
|
||||
def i18n_cache(key)
|
||||
get_i18n_cache(key)[I18n.locale] ||= yield.freeze
|
||||
end
|
||||
|
||||
|
||||
def get_i18n_cache(key)
|
||||
instance_variable_get(:"@#{key}") || reset_i18n_cache(key)
|
||||
end
|
||||
|
@ -15,4 +15,4 @@ module SimpleForm
|
|||
instance_variable_set(:"@#{key}", {})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,11 +15,15 @@ module SimpleForm
|
|||
end
|
||||
|
||||
def translate_required_text
|
||||
I18n.t(:"simple_form.required.text", :default => 'required')
|
||||
i18n_cache :translate_required_text do
|
||||
I18n.t(:"simple_form.required.text", :default => 'required')
|
||||
end
|
||||
end
|
||||
|
||||
def translate_required_mark
|
||||
I18n.t(:"simple_form.required.mark", :default => '*')
|
||||
i18n_cache :translate_required_mark do
|
||||
I18n.t(:"simple_form.required.mark", :default => '*')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@ require 'test_helper'
|
|||
class LabelTest < ActionView::TestCase
|
||||
|
||||
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
|
||||
|
||||
test 'input should generate a label with the text field' do
|
||||
|
|
Loading…
Reference in New Issue