Created
June 3, 2017 03:55
-
-
Save ghiculescu/d8c04204841b6fc8164be7d8b641e7e0 to your computer and use it in GitHub Desktop.
If you say `placeholder: true` on a form element, Rails gets it from i18n. Do the same for `tooltip: true`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# based on https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/tags/placeholderable.rb | |
# config/initializers/tooltipable.rb | |
module ActionView | |
module Helpers | |
module Tags # :nodoc: | |
module Tooltipable # :nodoc: | |
def initialize(*) | |
super | |
if tag_value = @options[:tooltip] | |
tooltip = tag_value if tag_value.is_a?(String) | |
method_and_value = tag_value.is_a?(TrueClass) ? @method_name : "#{@method_name}.#{tag_value}" | |
tooltip ||= Tags::Translator | |
.new(object, @object_name, method_and_value, "helpers.tooltip") | |
.translate | |
tooltip ||= @method_name.humanize | |
@options[:tooltip] = tooltip | |
end | |
end | |
end | |
end | |
end | |
end | |
ActionView::Helpers::Tags::TextField.send(:include, ActionView::Helpers::Tags::Tooltipable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment