def process_template name, args, called_from = nil, *_
Brakeman.debug "Rendering #{name} (#{called_from})"
name = name.to_s.gsub(/^\//, "")
template = @tracker.templates[name.to_sym]
unless template
Brakeman.debug "[Notice] No such template: #{name}"
return
end
if called_from
called_from.last_template = template
end
template_env = only_ivars(:include_request_vars)
digest = Digest::SHA1.new.update(template_env.instance_variable_get(:@env).to_a.sort.to_s << name).to_s.to_sym
if @tracker.template_cache.include? digest
return
else
@tracker.template_cache << digest
options = get_options args
if string? options[:layout]
process_template "layouts/#{options[:layout][1]}", nil, nil, nil
elsif node_type? options[:layout], :false
elsif not template.name.to_s.match(/[^\/_][^\/]+$/)
process_layout
end
if hash? options[:locals]
hash_iterate options[:locals] do |key, value|
template_env[Sexp.new(:call, nil, key.value)] = value
end
end
if options[:collection]
variable = template.name.to_s.match(/[^\/_][^\/]+$/)[0].to_sym
if options[:as]
if string? options[:as] or symbol? options[:as]
variable = options[:as].value.to_sym
end
end
collection = get_class_target(options[:collection]) || Brakeman::Tracker::UNKNOWN_MODEL
template_env[Sexp.new(:call, nil, variable)] = Sexp.new(:call, Sexp.new(:const, collection), :new)
end
template_env.all.each do |_var, value|
unless value.original_line
value.original_line = value.line
end
end
src = Brakeman::TemplateAliasProcessor.new(@tracker, template, called_from).process_safely(template.src, template_env)
digest = Digest::SHA1.new.update(name + src.to_s).to_s.to_sym
if @tracker.template_cache.include? digest
return
else
@tracker.template_cache << digest
end
@tracker.processor.process_template name, src, template.type, called_from
end
end