class ActionView::Helpers::TagHelper::TagBuilder
:nodoc:
def boolean_tag_option(key)
def boolean_tag_option(key) %(#{key}="#{key}") end
def content_tag_string(name, content, options, escape = true)
def content_tag_string(name, content, options, escape = true) tag_options = tag_options(options, escape) if options if escape name = ERB::Util.xml_name_escape(name) content = ERB::Util.unwrapped_html_escape(content) end "<#{name}#{tag_options}>#{PRE_CONTENT_STRINGS[name]}#{content}</#{name}>".html_safe end
def handle_deprecated_escape_options(options)
def handle_deprecated_escape_options(options) # The option :escape_attributes has been merged into the options hash to be # able to warn when it is used, so we need to handle default values here. escape_option_provided = options.has_key?(:escape) escape_attributes_option_provided = options.has_key?(:escape_attributes) if escape_attributes_option_provided ActiveSupport::Deprecation.warn(<<~MSG) Use of the option :escape_attributes is deprecated. It currently \ escapes both names and values of tags and attributes and it is \ equivalent to :escape. If any of them are enabled, the escaping \ is fully enabled. MSG end return true unless escape_option_provided || escape_attributes_option_provided escape_option = options.delete(:escape) escape_attributes_option = options.delete(:escape_attributes) escape_option || escape_attributes_option end
def initialize(view_context)
def initialize(view_context) @view_context = view_context end
def method_missing(called, *args, **options, &block)
def method_missing(called, *args, **options, &block) tag_string(called, *args, **options, &block) end
def prefix_tag_option(prefix, key, value, escape)
def prefix_tag_option(prefix, key, value, escape) key = "#{prefix}-#{key.to_s.dasherize}" unless value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(BigDecimal) value = value.to_json end tag_option(key, value, escape) end
def respond_to_missing?(*args)
def respond_to_missing?(*args) true end
def tag_option(key, value, escape)
def tag_option(key, value, escape) key = ERB::Util.xml_name_escape(key) if escape if value.is_a?(Array) value = escape ? safe_join(value, " ") : value.join(" ") else value = escape ? ERB::Util.unwrapped_html_escape(value).dup : value.to_s.dup end value.gsub!('"', """) %(#{key}="#{value}") end
def tag_options(options, escape = true)
def tag_options(options, escape = true) return if options.blank? output = +"" sep = " " options.each_pair do |key, value| if TAG_PREFIXES.include?(key) && value.is_a?(Hash) value.each_pair do |k, v| next if v.nil? output << sep output << prefix_tag_option(key, k, v, escape) end elsif BOOLEAN_ATTRIBUTES.include?(key) if value output << sep output << boolean_tag_option(key) end elsif !value.nil? output << sep output << tag_option(key, value, escape) end end output unless output.empty? end
def tag_string(name, content = nil, **options, &block)
def tag_string(name, content = nil, **options, &block) escape = handle_deprecated_escape_options(options) content = @view_context.capture(self, &block) if block_given? if VOID_ELEMENTS.include?(name) && content.nil? "<#{name.to_s.dasherize}#{tag_options(options, escape)}>".html_safe else content_tag_string(name.to_s.dasherize, content || "", options, escape) end end