Sha256: 961785b35df0784cb4a3b7c0d399787ed3cbe9197256891cbb27b08c5e5a952e

Contents?: true

Size: 893 Bytes

Versions: 9

Compression:

Stored size: 893 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.to_s
      @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

9 entries across 9 versions & 1 rubygems

Version Path
meta-tags-2.22.1 lib/meta_tags/tag.rb
meta-tags-2.22.1.rc1 lib/meta_tags/tag.rb
meta-tags-2.22.0 lib/meta_tags/tag.rb
meta-tags-2.21.0 lib/meta_tags/tag.rb
meta-tags-2.20.0 lib/meta_tags/tag.rb
meta-tags-2.19.0 lib/meta_tags/tag.rb
meta-tags-2.18.0 lib/meta_tags/tag.rb
meta-tags-2.17.0 lib/meta_tags/tag.rb
meta-tags-2.16.0 lib/meta_tags/tag.rb