Class: HexletCode::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/hexlet_code/tag.rb

Constant Summary collapse

SINGLE_TAGS =
%w[area base br col command embed hr img input keygen link meta param source track wbr].freeze

Class Method Summary collapse

Class Method Details

.build(tag_name, attributes = {}, block = nil) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/hexlet_code/tag.rb', line 7

def self.build(tag_name, attributes = {}, block = nil)
  result = "<#{tag_name}"
  attributes.each { |attr_name, attr_value| result << " #{attr_name}=\"#{attr_value}\"" } if attributes.any?
  result << '>'
  body_tag(tag_name, yield, result) if block_given?
  (tag_name, block, result) unless SINGLE_TAGS.include?(tag_name)
  result
end