Skip to content

Commit

Permalink
allow partial with block, closes padrino#1504
Browse files Browse the repository at this point in the history
  • Loading branch information
ujifgc authored and Ortuna committed Jan 17, 2014
1 parent 5f96d4f commit f59cb39
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions padrino-helpers/lib/padrino-helpers/render_helpers.rb
Expand Up @@ -30,7 +30,7 @@ module RenderHelpers
#
# @note If using this from Sinatra, pass explicit +:engine+ option
#
def partial(template, options={})
def partial(template, options={}, &block)
options = options.reverse_merge(:locals => {}, :layout => false)
explicit_engine = options.delete(:engine)

Expand All @@ -48,7 +48,7 @@ def partial(template, options={})
objects.inject(''.html_safe) do |html,object|
locals[object_name] = object if object
locals["#{object_name}_counter".to_sym] = counter += 1 if counter
html << render(explicit_engine, template_path, options).html_safe
html << render(explicit_engine, template_path, options, &block).html_safe
end
end
alias :render_partial :partial
Expand Down
6 changes: 6 additions & 0 deletions padrino-helpers/test/fixtures/render_app/app.rb
Expand Up @@ -61,4 +61,10 @@ class RenderDemo < Padrino::Application
content_tag :div, 'go block!'
end
end

get '/partial_block_:ext' do
partial "partial_block_#{params[:ext]}" do
content_tag :div, 'go block!'
end
end
end
@@ -0,0 +1,5 @@
<h1>prefix</h1>
<div class="erb-block">
<%= yield %>
</div>
<h3>postfix</h3>
@@ -0,0 +1,4 @@
%h1 prefix
.haml-block
= yield
%h3 postfix
@@ -0,0 +1,4 @@
h1 prefix
.slim-block
= yield
h3 postfix
24 changes: 24 additions & 0 deletions padrino-helpers/test/test_render_helpers.rb
Expand Up @@ -78,6 +78,30 @@ def app
end
end

context 'partial with block' do
should 'show partial slim with block' do
visit '/partial_block_slim'
assert_have_selector 'h1', :content => 'prefix'
assert_have_selector 'h3', :content => 'postfix'
assert_have_selector '.slim-block'
assert_have_selector 'div', :content => 'go block!'
end
should 'show partial erb with block' do
visit '/partial_block_erb'
assert_have_selector 'h1', :content => 'prefix'
assert_have_selector 'h3', :content => 'postfix'
assert_have_selector '.erb-block'
assert_have_selector 'div', :content => 'go block!'
end
should 'show partial haml with block' do
visit '/partial_block_haml'
assert_have_selector 'h1', :content => 'prefix'
assert_have_selector 'h3', :content => 'postfix'
assert_have_selector '.haml-block'
assert_have_selector 'div', :content => 'go block!'
end
end

context 'for #current_engine method' do
should 'detect correctly current engine for a padrino application' do
visit '/current_engine'
Expand Down

0 comments on commit f59cb39

Please sign in to comment.