Sha256: 5252c645f0d848306948c43b37b30b5e6961b90558d93b554ea8ae1eb6451ff8

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require "dry/equalizer"

module Dry
  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, Dry::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 [Dry::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

2 entries across 2 versions & 1 rubygems

Version Path
dry-view-0.7.0 lib/dry/view/rendered.rb
dry-view-0.6.0 lib/dry/view/rendered.rb