class Hanami::Helpers::HtmlHelper::HtmlNode
HTML node
@since 0.1.0 @api private
Public Class Methods
new(name, content, attributes, _options = {})
click to toggle source
Initialize a new HTML node
@param name [Symbol,String] the name of the tag @param content [String,Proc,Hanami::Helpers::HtmlHelper::HtmlBuilder,NilClass] the optional content @param attributes [Hash,NilClass] the optional tag attributes @param _options [Hash] a optional set of data
@return [Hanami::Helpers::HtmlHelper::HtmlNode]
# File lib/hanami/helpers/html_helper/html_node.rb, line 22 def initialize(name, content, attributes, _options = {}) @builder = HtmlBuilder.new @name = name @content = if content.is_a?(Hash) @attributes = content nil else attributes_hash = attributes.to_h if attributes.respond_to?(:to_h) @attributes = prepare_html_attributes(attributes_hash) content end end
Public Instance Methods
to_s()
click to toggle source
Resolve and return the output
@return [String] the output
@since 0.1.0 @api private
@see Hanami::Helpers::HtmlHelper::EmptyHtmlNode#to_s
# File lib/hanami/helpers/html_helper/html_node.rb, line 43 def to_s %(#{super}#{content}</#{@name}>) end
Private Instance Methods
content()
click to toggle source
Resolve the (nested) content
@return [String] the content
@since 0.1.0 @api private
# File lib/hanami/helpers/html_helper/html_node.rb, line 55 def content # rubocop:disable Metrics/MethodLength 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