提交 3498a29d 编写于 作者: J Justin

Merge pull request #71 from presidentbeef/handle_layout_in_views

Treat render :layout in views like partials
......@@ -202,9 +202,14 @@ class Brakeman::BaseProcessor < SexpProcessor
exp
end
#Convenience method for `make_render exp, true`
def make_render_in_view exp
make_render exp, true
end
#Generates :render node from call to render.
def make_render exp
render_type, value, rest = find_render_type exp[3]
def make_render exp, in_view = false
render_type, value, rest = find_render_type exp[3], in_view
rest = process rest
result = Sexp.new(:render, render_type, value, rest)
result.line(exp.line)
......@@ -214,9 +219,11 @@ class Brakeman::BaseProcessor < SexpProcessor
#Determines the type of a call to render.
#
#Possible types are:
#:action, :default :file, :inline, :js, :json, :nothing, :partial,
#:action, :default, :file, :inline, :js, :json, :nothing, :partial,
#:template, :text, :update, :xml
def find_render_type args
#
#And also :layout for inside templates
def find_render_type args, in_view = false
rest = Sexp.new(:hash)
type = nil
value = nil
......@@ -244,10 +251,18 @@ class Brakeman::BaseProcessor < SexpProcessor
value = args[1]
end
types_in_hash = Set[:action, :file, :inline, :js, :json, :nothing, :partial, :text, :update, :xml]
#render :layout => "blah" means something else when in a template
if in_view
types_in_hash << :layout
end
#Look for "type" of render in options hash
#For example, render :file => "blah"
if hash? args[-1]
hash_iterate(args[-1]) do |key, val|
case key[1]
when :action, :file, :inline, :js, :json, :nothing, :partial, :text, :update, :xml
if types_in_hash.include? key[1]
type = key[1]
value = val
else
......
......@@ -44,7 +44,7 @@ class Brakeman::ErbTemplateProcessor < Brakeman::TemplateProcessor
end
elsif target == nil and method == :render
exp[3] = process(exp[3])
make_render exp
make_render_in_view exp
else
args = exp[3] = process(exp[3])
call = Sexp.new :call, target, method, args
......
......@@ -41,7 +41,7 @@ class Brakeman::ErubisTemplateProcessor < Brakeman::TemplateProcessor
end
elsif target == nil and method == :render
exp[3] = process exp[3]
make_render exp
make_render_in_view exp
else
args = exp[3] = process(exp[3])
call = Sexp.new :call, target, method, args
......
......@@ -92,7 +92,7 @@ class Brakeman::HamlTemplateProcessor < Brakeman::TemplateProcessor
elsif target == nil and method == :render
#Process call to render()
exp[3] = process exp[3]
make_render exp
make_render_in_view exp
else
args = process exp[3]
call = Sexp.new :call, target, method, args
......
......@@ -11,8 +11,13 @@ module Brakeman::RenderHelper
when :action
process_action exp[2][1], exp[3]
when :default
process_template template_name, exp[3]
when :partial
begin
process_template template_name, exp[3]
rescue ArgumentError => e
Brakeman.debug "Problem processing render: #{exp}"
raise e
end
when :partial, :layout
process_partial exp[2], exp[3]
when :nothing
end
......
......@@ -29,3 +29,6 @@
<br />
<%= link_to 'New User', new_user_path %>
<%= @something = params["something_bad"] %>
<%= render :layout => "test_layout" %>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册