lib/hanami/view/rendered.rb in hanami-view-2.1.0.beta1 vs lib/hanami/view/rendered.rb in hanami-view-2.1.0.beta2
- old
+ new
@@ -5,28 +5,32 @@
module Hanami
class View
# Output of a View rendering
#
# @api public
+ # @since 2.1.0
class Rendered
include Dry::Equalizer(:output, :locals)
# Returns the rendered view
#
# @return [String]
#
# @api public
+ # @since 2.1.0
attr_reader :output
# Returns the hash of locals used to render the view
#
# @return [Hash[<Symbol, Hanami::View::Part>] locals hash
#
# @api public
+ # @since 2.1.0
attr_reader :locals
# @api private
+ # @since 2.1.0
def initialize(output:, locals:)
@output = output
@locals = locals
end
@@ -35,21 +39,48 @@
# @param name [Symbol] local key
#
# @return [Hanami::View::Part]
#
# @api public
+ # @since 2.1.0
def [](name)
locals[name]
end
# Returns the rendered view
#
# @return [String]
#
# @api public
+ # @since 2.1.0
def to_s
output
end
alias_method :to_str, :to_s
+
+ # Matches given input with the rendered view
+ #
+ # @param matcher [String, Regexp] matcher
+ #
+ # @return [TrueClass,FalseClass]
+ #
+ # @api public
+ # @since 2.1.0
+ def match?(matcher)
+ output.match?(matcher)
+ end
+ alias_method :match, :match?
+
+ # Checks if given string is included in the rendered view
+ #
+ # @param string [String] string
+ #
+ # @return [TrueClass,FalseClass]
+ #
+ # @api public
+ # @since 2.1.0
+ def include?(string)
+ output.include?(string)
+ end
end
end
end