Class: Lotus::Helpers::HtmlHelper::HtmlNode Private

Inherits:
EmptyHtmlNode show all
Defined in:
lib/lotus/helpers/html_helper/html_node.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

HTML node

See Also:

Since:

  • 0.1.0

Constant Summary

Constants inherited from EmptyHtmlNode

EmptyHtmlNode::ATTRIBUTES_SEPARATOR

Instance Method Summary collapse

Methods inherited from EmptyHtmlNode

#attributes

Constructor Details

#initialize(name, content, attributes) ⇒ Lotus::Helpers::HtmlHelper::HtmlNode

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new HTML node

Parameters:

  • name (Symbol, String)

    the name of the tag

  • content (String, Proc, Lotus::Helpers::HtmlHelper::HtmlBuilder, NilClass)

    the optional content

  • attributes (Hash, NilClass)

    the optional tag attributes

Since:

  • 0.1.0


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lotus/helpers/html_helper/html_node.rb', line 20

def initialize(name, content, attributes)
  @builder = HtmlBuilder.new
  @name    = name
  @content = case content
             when Hash
               @attributes = content
               nil
             else
               @attributes = attributes.to_h if attributes.respond_to?(:to_h)
               content
             end
end

Instance Method Details

#contentString (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Resolve the (nested) content

Returns:

  • (String)

    the content

Since:

  • 0.1.0


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lotus/helpers/html_helper/html_node.rb', line 52

def content
  case @content
  when Proc
    result = @builder.resolve(&@content)

    if @builder.nested?
      "\n#{ @builder }\n"
    else
      "\n#{ Utils::Escape.html(result) }\n"
    end
  else
    Utils::Escape.html(@content)
  end
end

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Resolve and return the output

Returns:

  • (String)

    the output

See Also:

Since:

  • 0.1.0


41
42
43
# File 'lib/lotus/helpers/html_helper/html_node.rb', line 41

def to_s
  %(#{ super }#{ content }</#{ @name }>)
end