Sha256: 48a5cda1debf61e3d53286461e9c87270f16e5ac9991f1ec3193d5476f23e6ad

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require "dry/core/equalizer"

module Hanami
  class View
    # Output of a View rendering
    #
    # @api public
    class Rendered
      include Dry::Equalizer(:output, :locals)

      # Returns the rendered view
      #
      # @return [String]
      #
      # @api public
      attr_reader :output

      # Returns the hash of locals used to render the view
      #
      # @return [Hash[<Symbol, Hanami::View::Part>] locals hash
      #
      # @api public
      attr_reader :locals

      # @api private
      def initialize(output:, locals:)
        @output = output
        @locals = locals
      end

      # Returns the local corresponding to the key
      #
      # @param name [Symbol] local key
      #
      # @return [Hanami::View::Part]
      #
      # @api public
      def [](name)
        locals[name]
      end

      # Returns the rendered view
      #
      # @return [String]
      #
      # @api public
      def to_s
        output
      end
      alias_method :to_str, :to_s
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hanami-view-2.1.0.beta1 lib/hanami/view/rendered.rb
hanami-view-2.0.0.alpha8 lib/hanami/view/rendered.rb
hanami-view-2.0.0.alpha7 lib/hanami/view/rendered.rb
hanami-view-2.0.0.alpha6 lib/hanami/view/rendered.rb
hanami-view-2.0.0.alpha5 lib/hanami/view/rendered.rb
hanami-view-2.0.0.alpha3 lib/hanami/view/rendered.rb
hanami-view-2.0.0.alpha2 lib/hanami/view/rendered.rb