Skip to content

Commit

Permalink
disable concatenating - in templates for Slim and Haml, add tests f…
Browse files Browse the repository at this point in the history
…or this
  • Loading branch information
ujifgc committed Oct 10, 2013
1 parent 25af5b5 commit 80a0e24
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 26 deletions.
4 changes: 1 addition & 3 deletions padrino-helpers/lib/padrino-helpers/form_helpers.rb
Expand Up @@ -90,9 +90,7 @@ def form_tag(url, options={}, &block)
inner_form_html << csrf_token_field
end
inner_form_html << mark_safe(capture_html(&block))
not_concat = options.delete(:not_concat)
form_html = content_tag(:form, inner_form_html, options)
not_concat ? form_html : concat_content(form_html)
concat_content content_tag(:form, inner_form_html, options)
end

##
Expand Down
Expand Up @@ -64,11 +64,15 @@ def capture_from_template(*args, &block)
##
# Outputs the given text to the templates buffer directly.
#
# This method is called when template uses block-aware helpers. For Slim and Haml such
# helpers just return output to use with `=`. For Erb this method is implemented in
# ErbHandler by concatenating text captured from the block to output buffer.
#
# @example
# @handler.concat_to_template("This will be output to the template buffer")
#
def concat_to_template(text="")
# Implemented in subclass.
text
end
end
end
Expand Down
11 changes: 0 additions & 11 deletions padrino-helpers/lib/padrino-helpers/output_helpers/haml_handler.rb
Expand Up @@ -24,17 +24,6 @@ def engine_matches?(block)
def capture_from_template(*args, &block)
engine_matches?(block) ? template.capture_haml(*args, &block) : block.call(*args)
end

##
# Outputs the given text to the templates buffer directly.
#
# @example
# @handler.concat_to_template("This will be output to the template buffer")
#
def concat_to_template(text="")
template.haml_concat(text)
nil
end
end
OutputHelpers.register(:haml, HamlHandler)
end
Expand Down
11 changes: 0 additions & 11 deletions padrino-helpers/lib/padrino-helpers/output_helpers/slim_handler.rb
Expand Up @@ -26,17 +26,6 @@ def capture_from_template(*args, &block)
engine_matches?(block) ? captured : raw
end

##
# Outputs the given text to the templates buffer directly.
#
# @example
# @handler.concat_to_template("This will be output to the template buffer")
#
def concat_to_template(text="")
self.output_buffer << text if text
nil
end

##
# Returns true if the block given is of the handler's template type; false otherwise.
#
Expand Down
4 changes: 4 additions & 0 deletions padrino-helpers/test/fixtures/render_app/app.rb
Expand Up @@ -32,6 +32,10 @@ class RenderDemo < Padrino::Application
render "double_capture_#{params[:ext]}"
end

get '/wrong_capture_:ext' do
render "wrong_capture_#{params[:ext]}"
end

# partial with object
get '/partial/object' do
partial 'template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" }
Expand Down
@@ -0,0 +1,3 @@
<%= form_for( :object, '/' ) do |f| %>
<%= content_tag(:p, 'this is wrong') %>
<% end %>
@@ -0,0 +1,2 @@
- form_for :object, '/' do |f|
= content_tag(:p, 'this is wrong')
@@ -0,0 +1,2 @@
- form_for :object, '/' do |f|
= content_tag(:p, 'this is wrong')
16 changes: 16 additions & 0 deletions padrino-helpers/test/test_render_helpers.rb
Expand Up @@ -90,5 +90,21 @@ def app
visit '/double_capture_erb'
assert_equal 1,$number_of_captures
end

should "fail on wrong erb usage" do
assert_raises(SyntaxError) do
visit '/wrong_capture_erb'
end
end

should "ignore wrong haml usage" do
visit '/wrong_capture_haml'
assert_have_no_selector 'p', :content => 'this is wrong'
end

should "ignore wrong slim usage" do
visit '/wrong_capture_slim'
assert_have_no_selector 'p', :content => 'this is wrong'
end
end
end

0 comments on commit 80a0e24

Please sign in to comment.