Class: MetaTags::Tag

Inherits:
Object show all
Defined in:
lib/meta_tags/tag.rb,
sig/lib/meta_tags/tag.rbs

Overview

Represents an HTML meta tag with no content ().

Direct Known Subclasses

ContentTag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attributes = {}) ⇒ Tag

Initializes a new instance of Tag class.

Parameters:

  • name (String, Symbol)

    HTML tag name

  • attributes (Hash) (defaults to: {})

    list of HTML tag attributes



13
14
15
16
# File 'lib/meta_tags/tag.rb', line 13

def initialize(name, attributes = {})
  @name = name.to_s
  @attributes = attributes
end

Instance Attribute Details

#attributesHash[String | Symbol, untyped] (readonly)

Returns the value of attribute attributes.

Returns:

  • (Hash[String | Symbol, untyped])


6
7
8
# File 'lib/meta_tags/tag.rb', line 6

def attributes
  @attributes
end

#nameString (readonly)

Returns the value of attribute name.

Returns:

  • (String)


6
7
8
# File 'lib/meta_tags/tag.rb', line 6

def name
  @name
end

Instance Method Details

#prepare_attributes(attributes) ⇒ Hash[String | Symbol, untyped]

Parameters:

  • attributes (Hash[String | Symbol, untyped])

Returns:

  • (Hash[String | Symbol, untyped])


29
30
31
32
33
# File 'lib/meta_tags/tag.rb', line 29

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

#render(view) ⇒ String

Render tag into a Rails view.

Parameters:

  • view (ActionView::Base)

    instance of a Rails view.

Returns:

  • (String)

    HTML string for the tag.



23
24
25
# File 'lib/meta_tags/tag.rb', line 23

def render(view)
  view.tag(name, prepare_attributes(attributes), MetaTags.config.open_meta_tags?)
end