Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecated TemplateHandler line offset

  • Loading branch information...
commit 27f382641c9ec945a1d657f5efba6a06296dca54 1 parent cd6fe83
Joshua Peek josh authored
2  actionpack/CHANGELOG
View
@@ -1,5 +1,7 @@
*Edge*
+* Deprecated TemplateHandler line offset [Josh Peek]
+
* Allow caches_action to accept cache store options. #416. [José Valim]. Example:
caches_action :index, :redirected, :if => Proc.new { |c| !c.request.format.json? }, :expires_in => 1.hour
8 actionpack/lib/action_view/template_handler.rb
View
@@ -1,9 +1,5 @@
module ActionView
class TemplateHandler
- def self.line_offset
- 0
- end
-
def self.compilable?
false
end
@@ -22,10 +18,6 @@ def compilable?
self.class.compilable?
end
- def line_offset
- self.class.line_offset
- end
-
# Called by CacheHelper#cache
def cache_fragment(block, name = {}, options = nil)
end
12 actionpack/lib/action_view/template_handlers/builder.rb
View
@@ -5,17 +5,11 @@ module TemplateHandlers
class Builder < TemplateHandler
include Compilable
- def self.line_offset
- 2
- end
-
def compile(template)
- content_type_handler = (@view.send!(:controller).respond_to?(:response) ? "controller.response" : "controller")
-
- "#{content_type_handler}.content_type ||= Mime::XML\n" +
- "xml = ::Builder::XmlMarkup.new(:indent => 2)\n" +
+ "controller.response.content_type ||= Mime::XML;" +
+ "xml = ::Builder::XmlMarkup.new(:indent => 2);" +
template.source +
- "\nxml.target!\n"
+ ";xml.target!;"
end
def cache_fragment(block, name = {}, options = nil)
101 actionpack/lib/action_view/template_handlers/compilable.rb
View
@@ -30,11 +30,10 @@ def compile_template(template)
render_symbol = assign_method_name(template)
render_source = create_template_source(template, render_symbol)
- line_offset = self.template_args[render_symbol].size + self.line_offset
begin
file_name = template.filename || 'compiled-template'
- ActionView::Base::CompiledTemplates.module_eval(render_source, file_name, -line_offset)
+ ActionView::Base::CompiledTemplates.module_eval(render_source, file_name, 0)
rescue Exception => e # errors from template code
if Base.logger
Base.logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
@@ -50,65 +49,65 @@ def compile_template(template)
end
private
-
- # Method to check whether template compilation is necessary.
- # The template will be compiled if the inline template or file has not been compiled yet,
- # if local_assigns has a new key, which isn't supported by the compiled code yet,
- # or if the file has changed on disk and checking file mods hasn't been disabled.
- def compile_template?(template)
- method_key = template.method_key
- render_symbol = @view.method_names[method_key]
-
- compile_time = self.compile_time[render_symbol]
- if compile_time && supports_local_assigns?(render_symbol, template.locals)
- if template.filename && !@view.cache_template_loading
- template_changed_since?(template.filename, compile_time)
+ # Method to check whether template compilation is necessary.
+ # The template will be compiled if the inline template or file has not been compiled yet,
+ # if local_assigns has a new key, which isn't supported by the compiled code yet,
+ # or if the file has changed on disk and checking file mods hasn't been disabled.
+ def compile_template?(template)
+ method_key = template.method_key
+ render_symbol = @view.method_names[method_key]
+
+ compile_time = self.compile_time[render_symbol]
+ if compile_time && supports_local_assigns?(render_symbol, template.locals)
+ if template.filename && !@view.cache_template_loading
+ template_changed_since?(template.filename, compile_time)
+ end
+ else
+ true
end
- else
- true
end
- end
- def assign_method_name(template)
- @view.method_names[template.method_key] ||= template.method_name
- end
-
- # Method to create the source code for a given template.
- def create_template_source(template, render_symbol)
- body = compile(template)
+ def assign_method_name(template)
+ @view.method_names[template.method_key] ||= template.method_name
+ end
- self.template_args[render_symbol] ||= {}
- locals_keys = self.template_args[render_symbol].keys | template.locals.keys
- self.template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
+ # Method to create the source code for a given template.
+ def create_template_source(template, render_symbol)
+ body = compile(template)
- locals_code = ""
- locals_keys.each do |key|
- locals_code << "#{key} = local_assigns[:#{key}]\n"
- end
+ self.template_args[render_symbol] ||= {}
+ locals_keys = self.template_args[render_symbol].keys | template.locals.keys
+ self.template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
- <<-end_src
- def #{render_symbol}(local_assigns)
- old_output_buffer = output_buffer;#{locals_code}#{body}
- ensure
- self.output_buffer = old_output_buffer
+ locals_code = ""
+ locals_keys.each do |key|
+ locals_code << "#{key} = local_assigns[:#{key}];"
end
- end_src
- end
- # Return true if the given template was compiled for a superset of the keys in local_assigns
- def supports_local_assigns?(render_symbol, local_assigns)
- local_assigns.empty? ||
- ((args = self.template_args[render_symbol]) && local_assigns.all? { |k,_| args.has_key?(k) })
- end
+ source = <<-end_src
+ def #{render_symbol}(local_assigns)
+ old_output_buffer = output_buffer;#{locals_code};#{body}
+ ensure
+ self.output_buffer = old_output_buffer
+ end
+ end_src
- # Method to handle checking a whether a template has changed since last compile; isolated so that templates
- # not stored on the file system can hook and extend appropriately.
- def template_changed_since?(file_name, compile_time)
- lstat = File.lstat(file_name)
- compile_time < lstat.mtime ||
- (lstat.symlink? && compile_time < File.stat(file_name).mtime)
- end
+ return source
+ end
+ # Return true if the given template was compiled for a superset of the keys in local_assigns
+ def supports_local_assigns?(render_symbol, local_assigns)
+ local_assigns.empty? ||
+ ((args = self.template_args[render_symbol]) && local_assigns.all? { |k,_| args.has_key?(k) })
+ end
+
+ # Method to handle checking a whether a template has changed since last compile; isolated so that templates
+ # not stored on the file system can hook and extend appropriately.
+ def template_changed_since?(file_name, compile_time)
+ lstat = File.lstat(file_name)
+ compile_time < lstat.mtime ||
+ (lstat.symlink? && compile_time < File.stat(file_name).mtime)
+ end
end
end
end
8 actionpack/lib/action_view/template_handlers/rjs.rb
View
@@ -3,13 +3,9 @@ module TemplateHandlers
class RJS < TemplateHandler
include Compilable
- def self.line_offset
- 2
- end
-
def compile(template)
- "controller.response.content_type ||= Mime::JS\n" +
- "update_page do |page|\n#{template.source}\nend"
+ "controller.response.content_type ||= Mime::JS;" +
+ "update_page do |page|;#{template.source};end"
end
def cache_fragment(block, name = {}, options = nil) #:nodoc:

1 comment on commit 27f3826

Joshua Peek
Collaborator

The Rails 500 template only shows your code in the debug output. And you’ll never see all that extra junk in your stack trace. You’ll only get error on line 1.

Please sign in to comment.
Something went wrong with that request. Please try again.