Skip to content

Commit

Permalink
Added .html.erb extension to partial template search heuristics
Browse files Browse the repository at this point in the history
  • Loading branch information
David Black authored and knzai committed Feb 14, 2010
1 parent be3dcc4 commit d77c3b7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/exception_notifier_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,22 @@ def render_section(section)
end

def render_overridable(partial, options={})
if File.exist?(path = "#{APP_PATH}/_#{partial}.rhtml")
render(options.merge(:file => path, :use_full_path => false))
elsif File.exist?(path = "#{File.dirname(__FILE__)}/../#{VIEW_PATH}/_#{partial}.rhtml")
render(options.merge(:file => path, :use_full_path => false))
paths = partial_path(partial)
if path = paths.find {|p| File.exist?(p) }
render(options.merge(:file => p, :use_full_path => false))
else
""
end
end

def partial_paths(partial)
exts = %w{ rhtml html.erb }
exts.map {|ext|
[ "#{APP_PATH}/_#{partial}.#{ext}",
"#{File.dirname(__FILE__)}/../#{VIEW_PATH}/_#{partial}.#{ext}"]
}.flatten
end

def inspect_model_object(model, locals={})
render_overridable(:inspect_model,
:locals => { :inspect_model => model,
Expand Down
25 changes: 25 additions & 0 deletions test/path_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'test_helper'
require 'exception_notifier_helper'


class PathTest < Test::Unit::TestCase
include ExceptionNotifierHelper

# RAILS_ROOT = "/devel/myapp"
# VIEW_PATH = "views/stuff"
# APP_PATH = "#{RAILS_ROOT}/app/#{VIEW_PATH}"
THIS_DIR = File.dirname(__FILE__)

def test_partial_paths
paths = partial_paths("mypartial")
assert_equal(expected_paths.sort, paths.sort)
end

def expected_paths
["./../lib/../views/exception_notifier/_mypartial.html.erb",
"./../lib/../views/exception_notifier/_mypartial.rhtml",
"./app/views/exception_notifier/_mypartial.html.erb",
"./app/views/exception_notifier/_mypartial.rhtml"]
end
end

0 comments on commit d77c3b7

Please sign in to comment.