From 4396f1e6a88fcb861010bcea1af7e97c8c3789ed Mon Sep 17 00:00:00 2001 From: Jordan Owens Date: Sat, 1 Dec 2018 23:50:51 -0500 Subject: [PATCH] Fix issue setting content_for value with method param --- sinatra-contrib/lib/sinatra/capture.rb | 3 +-- sinatra-contrib/spec/content_for/parameter_value.erb | 1 + sinatra-contrib/spec/content_for/parameter_value.erubis | 1 + sinatra-contrib/spec/content_for/parameter_value.haml | 1 + sinatra-contrib/spec/content_for/parameter_value.slim | 1 + sinatra-contrib/spec/content_for_spec.rb | 5 +++++ 6 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 sinatra-contrib/spec/content_for/parameter_value.erb create mode 100644 sinatra-contrib/spec/content_for/parameter_value.erubis create mode 100644 sinatra-contrib/spec/content_for/parameter_value.haml create mode 100644 sinatra-contrib/spec/content_for/parameter_value.slim diff --git a/sinatra-contrib/lib/sinatra/capture.rb b/sinatra-contrib/lib/sinatra/capture.rb index 0bbe7a17..10a00733 100644 --- a/sinatra-contrib/lib/sinatra/capture.rb +++ b/sinatra-contrib/lib/sinatra/capture.rb @@ -97,8 +97,7 @@ module Sinatra result = block[*args] elsif current_engine == :erb || current_engine == :slim @_out_buf, _buf_was = '', @_out_buf - block[*args] - result = eval('@_out_buf', block.binding) + result = block.call(*args) @_out_buf = _buf_was else buffer = eval '_buf if defined?(_buf)', block.binding diff --git a/sinatra-contrib/spec/content_for/parameter_value.erb b/sinatra-contrib/spec/content_for/parameter_value.erb new file mode 100644 index 00000000..b22350c1 --- /dev/null +++ b/sinatra-contrib/spec/content_for/parameter_value.erb @@ -0,0 +1 @@ +<% content_for :foo, 'foo' %> diff --git a/sinatra-contrib/spec/content_for/parameter_value.erubis b/sinatra-contrib/spec/content_for/parameter_value.erubis new file mode 100644 index 00000000..b22350c1 --- /dev/null +++ b/sinatra-contrib/spec/content_for/parameter_value.erubis @@ -0,0 +1 @@ +<% content_for :foo, 'foo' %> diff --git a/sinatra-contrib/spec/content_for/parameter_value.haml b/sinatra-contrib/spec/content_for/parameter_value.haml new file mode 100644 index 00000000..6f492b28 --- /dev/null +++ b/sinatra-contrib/spec/content_for/parameter_value.haml @@ -0,0 +1 @@ +- content_for :foo, 'foo' diff --git a/sinatra-contrib/spec/content_for/parameter_value.slim b/sinatra-contrib/spec/content_for/parameter_value.slim new file mode 100644 index 00000000..6f492b28 --- /dev/null +++ b/sinatra-contrib/spec/content_for/parameter_value.slim @@ -0,0 +1 @@ +- content_for :foo, 'foo' diff --git a/sinatra-contrib/spec/content_for_spec.rb b/sinatra-contrib/spec/content_for_spec.rb index f53235d4..3cc28102 100644 --- a/sinatra-contrib/spec/content_for_spec.rb +++ b/sinatra-contrib/spec/content_for_spec.rb @@ -210,6 +210,11 @@ describe Sinatra::ContentFor do expect(body).to eq("bar") end + it 'renders content set as parameter' do + expect(get('/parameter_value')).to be_ok + expect(body).to eq("foo") + end + it 'renders blocks declared with the same key you use when rendering' do expect(get('/same_key')).to be_ok expect(body).to eq("foo")