Sha256: 5e686c14de0f73df8d781af6304803e25a432d7ab1cfd95a8a336e7581b894b5

Contents?: true

Size: 706 Bytes

Versions: 2

Compression:

Stored size: 706 Bytes

Contents

require 'dry-equalizer'

module Dry
  module View
    class Part
      include Dry::Equalizer(:renderer)

      attr_reader :renderer

      def initialize(renderer)
        @renderer = renderer
      end

      def render(path, &block)
        renderer.render(path, self, &block)
      end

      def template?(name)
        renderer.lookup("_#{name}")
      end

      def respond_to_missing?(meth, include_private = false)
        super || template?(meth)
      end

      private

      def method_missing(meth, *args, &block)
        template_path = template?(meth)

        if template_path
          render(template_path, &block)
        else
          super
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-view-0.1.1 lib/dry/view/part.rb
dry-view-0.1.0 lib/dry/view/part.rb