Sha256: d4b5be2363f2234d2c02cc647e21d4126c03559bf97d1df6e6d3de69716c47a4

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Hanami
  module Helpers
    module HtmlHelper
      # HTML Fragment
      #
      # @since 0.2.6
      # @api private
      #
      # @see Hanami::Helpers::HtmlHelper::HtmlFragment
      class HtmlFragment
        # Initialize a HTML Fragment
        #
        # @param blk [Proc,Hanami::Helpers::HtmlHelper::HtmlBuilder,NilClass] the content block
        #
        # @return [Hanami::Helpers::HtmlHelper::HtmlFragment]
        def initialize(&blk)
          @builder = HtmlBuilder.new
          @blk = blk
        end

        # Resolve and return the output
        #
        # @return [String] the output
        #
        # @since 0.2.6
        # @api private
        #
        # @see Hanami::Helpers::HtmlHelper::EmptyHtmlNode#to_s
        def to_s
          content.to_s
        end

        def content
          result = @builder.resolve(&@blk)

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-helpers-0.3.0 lib/hanami/helpers/html_helper/html_fragment.rb