Skip to content

Commit

Permalink
Include Hanami::Action::Response#exposures in view rendering context
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Jul 2, 2020
1 parent 18a3936 commit efc9019
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/hanami/action/response.rb
Expand Up @@ -72,7 +72,7 @@ def body=(str)
end

def render(view, **options)
self.body = view.(**view_options.(request, self), **options).to_str
self.body = view.(**view_options.(request, self), **options.merge(exposures)).to_str
end

def format=(args)
Expand Down
Expand Up @@ -35,6 +35,7 @@ class TestAction < Main::Action
include Deps[view: "views.test_view"]
def handle(req, res)
res[:job] = "Singer"
res.render view, name: req.params[:name]
end
end
Expand Down Expand Up @@ -73,7 +74,7 @@ class View < Hanami::View
module Main
module Views
class TestView < Main::View
expose :name
expose :name, :job
end
end
end
Expand All @@ -89,6 +90,7 @@ class TestView < Main::View
h1 Hello, #{name}
- request.params.to_h.values.sort.each do |value|
p = value
p = job
SLIM

require "hanami/init"
Expand All @@ -97,7 +99,7 @@ class TestView < Main::View
response = action.(name: "Jennifer", last_name: "Lopez")
rendered = response.body[0]

expect(rendered).to eq "<html><body><h1>Hello, Jennifer</h1><p>Jennifer</p><p>Lopez</p></body></html>"
expect(rendered).to eq "<html><body><h1>Hello, Jennifer</h1><p>Jennifer</p><p>Lopez</p><p>Singer</p></body></html>"
end
end
end

0 comments on commit efc9019

Please sign in to comment.