From a7625d8d0a81eafaa969c9089b841e7c7fe30dcb Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Sun, 17 Apr 2016 11:48:14 -0400 Subject: [PATCH] Use to_partial_path now we control the view context --- lib/mountain_view/presenter.rb | 25 +++++++++++++------------ test/mountain_view/presenter_test.rb | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/mountain_view/presenter.rb b/lib/mountain_view/presenter.rb index ea49a42..43e6bc0 100644 --- a/lib/mountain_view/presenter.rb +++ b/lib/mountain_view/presenter.rb @@ -13,17 +13,13 @@ def initialize(slug, properties = {}) def render(context) context.extend ViewContext context.inject_component_context(self) - context.render partial: partial + context.render self end - def partial + def to_partial_path "#{slug}/#{slug}" end - def exposed_methods - public_methods(false) - [:slug, :properties, :render, :partial] - end - private def default_properties @@ -51,11 +47,11 @@ def properties(*args) end alias_method :property, :properties - private - - def define_property_methods(names = []) + private + + def define_property_methods(names=[]) names.each do |name| - next if method_defined?(name) + next if method_defined?(name) define_method name do properties[name.to_sym] end @@ -66,14 +62,19 @@ def define_property_methods(names = []) module ViewContext attr_reader :_component delegate :properties, to: :_component - + def inject_component_context(component) @_component = component - component.exposed_methods.each do |meth| + methods = component.public_methods(false) - [:slug, :properties, :render, :partial] + methods.each do |meth| next if self.class.method_defined?(meth) self.class.delegate meth, to: :_component end end + + def prefix_partial_path_with_controller_namespace + false + end end end end diff --git a/test/mountain_view/presenter_test.rb b/test/mountain_view/presenter_test.rb index fd7bb6a..f000eaa 100644 --- a/test/mountain_view/presenter_test.rb +++ b/test/mountain_view/presenter_test.rb @@ -12,7 +12,7 @@ def title class MountainView::PresenterTest < ActiveSupport::TestCase test "returns the correct partial path" do presenter = MountainView::Presenter.new("header") - assert_equal "header/header", presenter.partial + assert_equal "header/header", presenter.to_partial_path end test "exposes properties as provided" do