class TagStatement

A tag

Constants

VOID_TAGS

w3c.github.io/html/syntax.html#void-elements

Public Instance Methods

class_attribute() click to toggle source
# File lib/emerald/nodes/tag_statement.rb, line 31
def class_attribute
  unless classes.empty?
    class_names = classes
      .elements
      .map{ |c| c.name.text_value }
      .join(' ')

    " class=\"#{class_names}\""
  else
    ''
  end
end
closing_tag(_context) click to toggle source
# File lib/emerald/nodes/tag_statement.rb, line 75
def closing_tag(_context)
  "</#{tag.text_value}>"
end
id_attribute() click to toggle source
# File lib/emerald/nodes/tag_statement.rb, line 44
def id_attribute
  unless identifier.empty?
    " id=\"#{identifier.name.text_value}\""
  else
    ''
  end
end
opening_tag(context) click to toggle source
# File lib/emerald/nodes/tag_statement.rb, line 52
def opening_tag(context)
  "<#{tag.text_value}" +
    id_attribute +
    class_attribute +
    (
      if !attributes.empty?
        ' ' + attributes.to_html(context)
      else
        ''
      end
    ) + (
      if void_tag?
        ' />'
      else
        '>'
      end
    )
end
to_html(context) click to toggle source
# File lib/emerald/nodes/tag_statement.rb, line 15
def to_html(context)
  if void_tag?
    opening_tag(context)
  else
    opening_tag(context) +
      (
        if !body.empty?
          body.to_html(context)
        else
          ''
        end
      ) +
      closing_tag(context)
  end
end
void_tag?() click to toggle source
# File lib/emerald/nodes/tag_statement.rb, line 71
def void_tag?
  VOID_TAGS.include? tag.text_value
end