Skip to content

Commit

Permalink
Use to_partial_path now we control the view context
Browse files Browse the repository at this point in the history
  • Loading branch information
tombeynon committed Apr 17, 2016
1 parent 2449dcc commit a429b20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions lib/mountain_view/presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion test/mountain_view/presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a429b20

Please sign in to comment.