Sha256: 8c98503d1425d53cec14e9a927f1d826447790c7d4fb0235b0c84b441a9d1839

Contents?: true

Size: 1.05 KB

Versions: 22

Compression:

Stored size: 1.05 KB

Contents

require 'hanami/utils/escape'

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

        # @api private
        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

22 entries across 22 versions & 1 rubygems

Version Path
hanami-helpers-1.3.3 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.3.2 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.3.1 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.3.0 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.3.0.beta1 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.2.2 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.2.1 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.2.0 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.2.0.rc2 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.1.2 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.2.0.rc1 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.2.0.beta2 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.2.0.beta1 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.1.1 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.1.0 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.1.0.rc1 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.1.0.beta3 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.1.0.beta2 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.1.0.beta1 lib/hanami/helpers/html_helper/html_fragment.rb
hanami-helpers-1.0.0 lib/hanami/helpers/html_helper/html_fragment.rb