Permalink
Browse files

Fix: does not render layout on render :nothing => true

  • Loading branch information...
1 parent 0ccd756 commit e4ab8b970f63db6833ab09ac6e24d6e3aae4104b @madadam committed Dec 14, 2010
Showing with 23 additions and 9 deletions.
  1. +9 −9 lib/liquidizer/controller_extensions.rb
  2. +14 −0 test/controller_extensions_test.rb
@@ -37,7 +37,7 @@ def render_with_liquid(options = nil, &block)
content = layout_template.render!(assigns.merge('content_for_layout' => content))
render_without_liquid(options.merge(:text => content, :layout => false))
- else
+ else
render_without_liquid(options, &block)
end
end
@@ -50,15 +50,15 @@ def liquid_template_for_view(options)
unless name
action = extract_action_for_render(options)
-
+
if action && liquify?(action)
- name = liquid_template_name_for_action(action)
+ name = liquid_template_name_for_action(action)
end
end
name && find_and_parse_liquid_template(name)
end
-
+
def liquify?(action)
options = self.class.liquidizer_options
@@ -79,7 +79,7 @@ def liquid_template_for_layout(options)
nil
end
end
-
+
def liquify_layout?(options)
if self.class.liquidizer_options[:layout]
case options[:layout]
@@ -92,7 +92,7 @@ def liquify_layout?(options)
false
end
end
-
+
def extract_action_for_render(options)
if options.nil?
action_name
@@ -105,12 +105,12 @@ def extract_action_for_render(options)
end
end
- UNLIQUIFIABLE_OPTIONS = [:partial, :file, :text, :xml, :json, :js, :inline]
+ UNLIQUIFIABLE_OPTIONS = [:partial, :file, :text, :xml, :json, :js, :inline, :nothing]
def liquifiable_options?(options)
(options.keys.map(&:to_sym) & UNLIQUIFIABLE_OPTIONS).empty?
end
-
+
def find_and_parse_liquid_template(name)
if template_record = find_liquid_template(name)
template = Liquid::Template.parse(template_record.content)
@@ -147,7 +147,7 @@ def prepare_liquid_template(template)
def assigns_for_liquify
variable_names = instance_variable_names
variable_names -= protected_instance_variables
-
+
variable_names.inject({}) do |memo, name|
assign_name = name[/^@(.*)$/, 1] # strip @
next memo if assign_name.starts_with?('_') # skip "private" ivars
@@ -38,6 +38,10 @@ def new
def edit
render :layout => 'awesome_layout'
end
+
+ def destroy
+ render :nothing => true
+ end
end
class CommentsController < BaseController
@@ -258,6 +262,16 @@ def teardown
assert_select '#layout p', 'more awesome new'
end
+ test 'does not apply liquid layout to render :nothing => true' do
+ setup_controller(PostsController)
+
+ LiquidTemplate.create!(:name => 'layout',
+ :content => '<div id="layout">{{ content_for_layout }}</div>')
+
+ get :destroy
+ assert @response.body.blank?, "response should be blank, but was #{@response.body.inspect}"
+ end
+
test 'dropifies instance variables' do
setup_controller(PostsController)

0 comments on commit e4ab8b9

Please sign in to comment.