Class: DatoDast::HtmlTag

Inherits:
Object
  • Object
show all
Defined in:
lib/dato_dast/html_tag.rb

Constant Summary collapse

EMPTY =
""
NEWLINE =
"\n"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, options = {}) ⇒ HtmlTag

Returns a new instance of HtmlTag.



25
26
27
28
29
30
# File 'lib/dato_dast/html_tag.rb', line 25

def initialize(tag, options = {})
  @tag = tag
  @css_class = options["css_class"] || ""
  @meta = options["meta"] || {}
  @object = options["object"]
end

Class Method Details

.parse(tag, object = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dato_dast/html_tag.rb', line 6

def self.parse(tag, object = nil)
  case tag
  when String
    new(tag)
  when Hash
    html_tag = tag["tag"]
    css_class = tag["css_class"]
    meta = tag["meta"]

    HtmlTag.new(html_tag, { "css_class" => css_class, "meta" => meta, "object" => object })
  when HtmlTag
    tag
  when nil
    HtmlTag.new(nil)
  else
    nil
  end
end

Instance Method Details

#closeObject



38
39
40
41
42
# File 'lib/dato_dast/html_tag.rb', line 38

def close
  return EMPTY unless tag

  NEWLINE + "</#{tag}>"
end

#openObject



32
33
34
35
36
# File 'lib/dato_dast/html_tag.rb', line 32

def open
  return EMPTY unless tag

  "<#{tag}#{css_class}#{meta}>" + NEWLINE
end