Use similar api for hints and errors, and cache hint to avoid double lookup

This commit is contained in:
Carlos Antonio da Silva 2012-01-10 19:00:14 -02:00
parent 0bca82c419
commit d719e47c18
2 changed files with 6 additions and 2 deletions

View File

@ -3,12 +3,16 @@ module SimpleForm
# Needs to be enabled in order to do automatic lookups.
module Hints
def hint
if options[:hint] == true
@hint ||= if options[:hint] == true
translate(:hints)
else
options[:hint]
end
end
def has_hint?
hint.present?
end
end
end
end

View File

@ -26,7 +26,7 @@ module SimpleForm
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
css += input.html_classes
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.hint
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.has_hint?
css
end
end