aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-09-24 12:30:13 -0500
committerJoshua Peek <josh@joshpeek.com>2009-09-24 12:30:13 -0500
commit610b81beca461a6fa4f00c7023e0e4315eb2b8be (patch)
tree520484e6d2943695a9cb55403bc77f6b8336abfc /actionpack/lib
parent9f96708f53b4eee8830554dd8f0a482160ef4c73 (diff)
downloadrails-610b81beca461a6fa4f00c7023e0e4315eb2b8be.tar.gz
rails-610b81beca461a6fa4f00c7023e0e4315eb2b8be.tar.bz2
rails-610b81beca461a6fa4f00c7023e0e4315eb2b8be.zip
Clean up log output for rendered templates
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/render/rendering.rb4
-rw-r--r--actionpack/lib/action_view/template/error.rb2
-rw-r--r--actionpack/lib/action_view/template/template.rb119
-rw-r--r--actionpack/lib/action_view/template/text.rb29
4 files changed, 87 insertions, 67 deletions
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index b0b75918b7..8b0d4cc627 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -105,7 +105,7 @@ module ActionView
def _render_template(template, layout = nil, options = {}, partial = nil)
logger && logger.info do
- msg = "Rendering #{template.identifier}"
+ msg = "Rendering #{template.inspect}"
msg << " (#{options[:status]})" if options[:status]
msg
end
@@ -123,7 +123,7 @@ module ActionView
if layout
@_layout = layout.identifier
- logger.info("Rendering template within #{layout.identifier}") if logger
+ logger.info("Rendering template within #{layout.inspect}") if logger
content = layout.render(self, locals) {|*name| _layout_for(*name) }
end
content
diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb
index 6e5093c5bd..aa21606f76 100644
--- a/actionpack/lib/action_view/template/error.rb
+++ b/actionpack/lib/action_view/template/error.rb
@@ -32,7 +32,7 @@ module ActionView
def sub_template_message
if @sub_templates
"Trace of template inclusion: " +
- @sub_templates.collect { |template| template.identifier }.join(", ")
+ @sub_templates.collect { |template| template.inspect }.join(", ")
else
""
end
diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb
index 80c1bab7d5..0f64c23649 100644
--- a/actionpack/lib/action_view/template/template.rb
+++ b/actionpack/lib/action_view/template/template.rb
@@ -8,7 +8,7 @@ module ActionView
class Template
extend TemplateHandlers
attr_reader :source, :identifier, :handler, :mime_type, :formats, :details
-
+
def initialize(source, identifier, handler, details)
@source = source
@identifier = identifier
@@ -25,7 +25,7 @@ module ActionView
@formats << :html if format == :js
@details[:formats] = Array.wrap(format.to_sym)
end
-
+
def render(view, locals, &block)
ActiveSupport::Orchestra.instrument(:render_template, :identifier => identifier) do
method_name = compile(locals, view)
@@ -39,7 +39,7 @@ module ActionView
raise TemplateError.new(self, view.assigns, e)
end
end
-
+
# TODO: Figure out how to abstract this
def variable_name
@variable_name ||= identifier[%r'_?(\w+)(\.\w+)*$', 1].to_sym
@@ -49,76 +49,83 @@ module ActionView
def counter_name
@counter_name ||= "#{variable_name}_counter".to_sym
end
-
+
# TODO: kill hax
def partial?
@details[:partial]
end
- private
+ def inspect
+ if defined?(Rails.root)
+ identifier.sub("#{Rails.root}/", '')
+ else
+ identifier
+ end
+ end
- def compile(locals, view)
- method_name = build_method_name(locals)
-
- return method_name if view.respond_to?(method_name)
-
- locals_code = locals.keys.map! { |key| "#{key} = local_assigns[:#{key}];" }.join
+ private
+ def compile(locals, view)
+ method_name = build_method_name(locals)
- code = @handler.call(self)
- if code.sub!(/\A(#.*coding.*)\n/, '')
- encoding_comment = $1
- elsif defined?(Encoding) && Encoding.respond_to?(:default_external)
- encoding_comment = "#coding:#{Encoding.default_external}"
- end
+ return method_name if view.respond_to?(method_name)
- source = <<-end_src
- def #{method_name}(local_assigns)
- old_output_buffer = output_buffer;#{locals_code};#{code}
- ensure
- self.output_buffer = old_output_buffer
- end
- end_src
+ locals_code = locals.keys.map! { |key| "#{key} = local_assigns[:#{key}];" }.join
- if encoding_comment
- source = "#{encoding_comment}\n#{source}"
- line = -1
- else
- line = 0
- end
+ code = @handler.call(self)
+ if code.sub!(/\A(#.*coding.*)\n/, '')
+ encoding_comment = $1
+ elsif defined?(Encoding) && Encoding.respond_to?(:default_external)
+ encoding_comment = "#coding:#{Encoding.default_external}"
+ end
- begin
- ActionView::CompiledTemplates.module_eval(source, identifier, line)
- method_name
- rescue Exception => e # errors from template code
- if logger = (view && view.logger)
- logger.debug "ERROR: compiling #{method_name} RAISED #{e}"
- logger.debug "Function body: #{source}"
- logger.debug "Backtrace: #{e.backtrace.join("\n")}"
+ source = <<-end_src
+ def #{method_name}(local_assigns)
+ old_output_buffer = output_buffer;#{locals_code};#{code}
+ ensure
+ self.output_buffer = old_output_buffer
+ end
+ end_src
+
+ if encoding_comment
+ source = "#{encoding_comment}\n#{source}"
+ line = -1
+ else
+ line = 0
end
- raise ActionView::TemplateError.new(self, {}, e)
+ begin
+ ActionView::CompiledTemplates.module_eval(source, identifier, line)
+ method_name
+ rescue Exception => e # errors from template code
+ if logger = (view && view.logger)
+ logger.debug "ERROR: compiling #{method_name} RAISED #{e}"
+ logger.debug "Function body: #{source}"
+ logger.debug "Backtrace: #{e.backtrace.join("\n")}"
+ end
+
+ raise ActionView::TemplateError.new(self, {}, e)
+ end
end
- end
- class LocalsKey
- @hash_keys = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = {} } }
+ class LocalsKey
+ @hash_keys = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = {} } }
- def self.get(*locals)
- @hash_keys[*locals] ||= new(klass, format, locale)
- end
+ def self.get(*locals)
+ @hash_keys[*locals] ||= new(klass, format, locale)
+ end
- attr_accessor :hash
- def initialize(klass, format, locale)
- @hash = locals.hash
- end
+ attr_accessor :hash
+ def initialize(klass, format, locale)
+ @hash = locals.hash
+ end
- alias_method :eql?, :equal?
- end
+ alias_method :eql?, :equal?
+ end
- def build_method_name(locals)
- # TODO: is locals.keys.hash reliably the same?
- @method_names[locals.keys.hash] ||=
- "_render_template_#{@identifier.hash}_#{__id__}_#{locals.keys.hash}".gsub('-', "_")
- end
+ def build_method_name(locals)
+ # TODO: is locals.keys.hash reliably the same?
+ @method_names[locals.keys.hash] ||=
+ "_render_template_#{@identifier.hash}_#{__id__}_#{locals.keys.hash}".gsub('-', "_")
+ end
end
end
diff --git a/actionpack/lib/action_view/template/text.rb b/actionpack/lib/action_view/template/text.rb
index 9f12e5e0a8..f7d0df5ba0 100644
--- a/actionpack/lib/action_view/template/text.rb
+++ b/actionpack/lib/action_view/template/text.rb
@@ -1,6 +1,5 @@
module ActionView #:nodoc:
class TextTemplate < String #:nodoc:
-
def initialize(string, content_type = Mime[:html])
super(string.to_s)
@content_type = Mime[content_type] || content_type
@@ -10,14 +9,28 @@ module ActionView #:nodoc:
{:formats => [@content_type.to_sym]}
end
- def identifier() self end
-
- def render(*) self end
-
- def mime_type() @content_type end
+ def identifier
+ self
+ end
+
+ def inspect
+ 'inline template'
+ end
+
+ def render(*args)
+ self
+ end
- def formats() [mime_type] end
+ def mime_type
+ @content_type
+ end
- def partial?() false end
+ def formats
+ [mime_type]
+ end
+
+ def partial?
+ false
+ end
end
end