Sha256: 227d4353df51a7e5e36887f0c58e37d68baff0410092d8e6817f6642c700c6af

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require "dry/core/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.8.0 lib/dry/view/rendered.rb
dry-view-0.7.1 lib/dry/view/rendered.rb