Sha256: def6edfc6f785cd053a1c61881238dff9081d578c2043639f01f833a0a582de2

Contents?: true

Size: 888 Bytes

Versions: 6

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

module MetaTags
  # Represents an HTML meta tag with no content (<tag />).
  class Tag
    attr_reader :name, :attributes

    # Initializes a new instance of Tag class.
    #
    # @param [String, Symbol] name HTML tag name
    # @param [Hash] attributes list of HTML tag attributes
    #
    def initialize(name, attributes = {})
      @name = name
      @attributes = attributes
    end

    # Render tag into a Rails view.
    #
    # @param [ActionView::Base] view instance of a Rails view.
    # @return [String] HTML string for the tag.
    #
    def render(view)
      view.tag(name, prepare_attributes(attributes), MetaTags.config.open_meta_tags?)
    end

    protected

    def prepare_attributes(attributes)
      attributes.each do |key, value|
        attributes[key] = value.iso8601 if value.respond_to?(:iso8601)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
meta-tags-2.15.0 lib/meta_tags/tag.rb
meta-tags-2.14.0 lib/meta_tags/tag.rb
meta-tags-2.13.0 lib/meta_tags/tag.rb
meta-tags-2.12.0 lib/meta_tags/tag.rb
meta-tags-2.11.1 lib/meta_tags/tag.rb
meta-tags-2.11.0 lib/meta_tags/tag.rb