提交 a30cf962 编写于 作者: J Justin Collins

[WIP] render :layout in views

上级 d1332357
......@@ -210,9 +210,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)
......@@ -222,9 +227,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
......@@ -252,10 +259,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
......
......@@ -35,7 +35,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,14 +11,25 @@ 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
$stderr.puts e
$stderr.puts self.class
$stderr.puts @template[:name]
$stderr.puts "Problem processing render: #{exp}"
end
when :partial, :layout
process_partial exp[2], exp[3]
when :nothing
end
exp
end
def process_layout_in_view exp
$stderr.puts exp.inspect
end
#Processes layout
def process_layout name = nil
if name.nil? and defined? layout_name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册