aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/template_handlers.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-12-15 18:22:35 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2008-12-15 18:22:35 -0800
commit89056885b030b981193d73ebde56cf60829a924c (patch)
tree9d432f7226754115ac4d2ef8aa1134221ff294bb /actionpack/lib/action_view/template_handlers.rb
parent19be3d35b38b6685789d8d343617d465a3652717 (diff)
parent43ac42c46a462e1453b1b97da00e11bff7bba55d (diff)
downloadrails-89056885b030b981193d73ebde56cf60829a924c.tar.gz
rails-89056885b030b981193d73ebde56cf60829a924c.tar.bz2
rails-89056885b030b981193d73ebde56cf60829a924c.zip
Merge branch 'master' of git@github.com:rails/rails
Diffstat (limited to 'actionpack/lib/action_view/template_handlers.rb')
-rw-r--r--actionpack/lib/action_view/template_handlers.rb25
1 files changed, 24 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/template_handlers.rb b/actionpack/lib/action_view/template_handlers.rb
index d06ddd5fb5..c50a51b0d1 100644
--- a/actionpack/lib/action_view/template_handlers.rb
+++ b/actionpack/lib/action_view/template_handlers.rb
@@ -28,6 +28,10 @@ module ActionView #:nodoc:
@@template_handlers[extension.to_sym] = klass
end
+ def valid_extension?(extension)
+ template_handler_extensions.include?(extension) || init_path_for_extension(extension)
+ end
+
def template_handler_extensions
@@template_handlers.keys.map(&:to_s).sort
end
@@ -38,7 +42,26 @@ module ActionView #:nodoc:
end
def handler_class_for_extension(extension)
- (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers
+ (extension && @@template_handlers[extension.to_sym] || autoload_handler_class(extension)) ||
+ @@default_template_handlers
end
+
+ private
+ def autoload_handler_class(extension)
+ return if Gem.loaded_specs[extension]
+ return unless init_path = init_path_for_extension(extension)
+ Gem.activate(extension)
+ load(init_path)
+ handler_class_for_extension(extension)
+ end
+
+ # Returns the path to the rails/init.rb file for the given extension,
+ # or nil if no gem provides it.
+ def init_path_for_extension(extension)
+ return unless spec = Gem.searcher.find(extension.to_s)
+ returning File.join(spec.full_gem_path, 'rails', 'init.rb') do |path|
+ return unless File.file?(path)
+ end
+ end
end
end