method
create_template_source
v1.2.6 -
Show latest stable
- Class:
ActionView::Base
create_template_source(extension, template, render_symbol, locals)private
Method to create the source code for a given template.
# File actionpack/lib/action_view/base.rb, line 453
def create_template_source(extension, template, render_symbol, locals)
if template_requires_setup?(extension)
body = case extension.to_sym
when :rxml
"controller.response.content_type ||= 'application/xml'\n" +
"xml ||= Builder::XmlMarkup.new(:indent => 2)\n" +
template +
"\nxml.target!\n"
when :rjs
"controller.response.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}]\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? -
compiled_method_name -
compiled_method_name_file_path_segment -
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?