Sha256: 06072be3c3d652f06f0879060e16327a5ef524e126c57017e600c503d1106df3
Contents?: true
Size: 1.84 KB
Versions: 1
Compression:
Stored size: 1.84 KB
Contents
require 'lotus/helpers/html_helper/empty_html_node' module Lotus module Helpers module HtmlHelper # HTML node # # @since 0.1.0 # @api private # # @see Lotus::Helpers::HtmlHelper::EmptyHtmlNode class HtmlNode < EmptyHtmlNode # Initialize a new HTML node # # @param name [Symbol,String] the name of the tag # @param content [String,Proc,Lotus::Helpers::HtmlHelper::HtmlBuilder,NilClass] the optional content # @param attributes [Hash,NilClass] the optional tag attributes # # @return [Lotus::Helpers::HtmlHelper::HtmlNode] 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 # Resolve and return the output # # @return [String] the output # # @since 0.1.0 # @api private # # @see Lotus::Helpers::HtmlHelper::EmptyHtmlNode#to_s def to_s %(#{ super }#{ content }</#{ @name }>) end private # Resolve the (nested) content # # @return [String] the content # # @since 0.1.0 # @api private 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 end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lotus-helpers-0.1.0 | lib/lotus/helpers/html_helper/html_node.rb |