aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/helpers/tags/placeholderable.rb
blob: 5ae57cdeefddde22a3e484962c55a08d59064009 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true
module ActionView
  module Helpers
    module Tags # :nodoc:
      module Placeholderable # :nodoc:
        def initialize(*)
          super

          if tag_value = @options[:placeholder]
            placeholder = tag_value if tag_value.is_a?(String)
            method_and_value = tag_value.is_a?(TrueClass) ? @method_name : "#{@method_name}.#{tag_value}"

            placeholder ||= Tags::Translator
              .new(object, @object_name, method_and_value, scope: "helpers.placeholder")
              .translate
            placeholder ||= @method_name.humanize
            @options[:placeholder] = placeholder
          end
        end
      end
    end
  end
end