3 # Copyright (c) 2005 Jamis Buck
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 module ExceptionNotifierHelper
24 VIEW_PATH = "views/exception_notifier"
25 APP_PATH = "#{RAILS_ROOT}/app/#{VIEW_PATH}"
27 def render_section(section)
28 RAILS_DEFAULT_LOGGER.info("rendering section #{section.inspect}")
29 summary = render_overridable(section).strip
31 title = render_overridable(:title, :locals => { :title => section }).strip
32 "#{title}\n\n#{summary.gsub(/^/, " ")}\n\n"
36 def render_overridable(partial, options={})
37 if File.exist?(path = "#{APP_PATH}/_#{partial}.rhtml")
38 render(options.merge(:file => path, :use_full_path => false))
39 elsif File.exist?(path = "#{File.dirname(__FILE__)}/../#{VIEW_PATH}/_#{partial}.rhtml")
40 render(options.merge(:file => path, :use_full_path => false))
46 def inspect_model_object(model, locals={})
47 render_overridable(:inspect_model,
48 :locals => { :inspect_model => model,
49 :show_instance_variables => true,
50 :show_attributes => true }.merge(locals))
53 def inspect_value(value)
55 result = object_to_yaml(value).gsub(/\n/, "\n ").strip
56 result = result[0,len] + "... (#{result.length-len} bytes more)" if result.length > len+20
60 def object_to_yaml(object)
61 object.to_yaml.sub(/^---\s*/m, "")