method
create_template_source
v1.1.6 -
Show latest stable
- Class:
ActionView::Base
create_template_source(extension, template, render_symbol, locals)private
Create source code for given template
# File actionpack/lib/action_view/base.rb, line 439
def create_template_source(extension, template, render_symbol, locals)
if template_requires_setup?(extension)
body = case extension.to_sym
when :rxml
"xml = Builder::XmlMarkup.new(:indent => 2)\n" +
"@controller.headers['Content-Type'] ||= 'application/xml'\n" +
template
when :rjs
"@controller.headers['Content-Type'] ||= 'text/javascript'\n" +
"update_page do |page|\n#{template}\nend"
end
else
body = ERB.new(template, nil, @@erb_trim_mode).src
end
@@template_args[render_symbol] ||= {}
locals_keys = @@template_args[render_symbol].keys | locals
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
locals_code = ""
locals_keys.each do |key|
locals_code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
end
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
end Related methods
- Class methods
- register_template_handler
- Private methods
-
assign_method_name -
assign_variables_from_controller -
cached_template_extension -
compile_template -
compile_template? -
create_template_source -
delegate_render -
evaluate_assigns -
find_template_extension_for -
full_template_path -
path_and_extension -
read_template_file -
supports_local_assigns? -
template_exists? -
template_requires_setup? -
templates_requiring_setup