aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/template
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-03-10 13:28:52 -0800
committerwycats <wycats@gmail.com>2010-03-10 13:28:52 -0800
commit4745b53bcda400cf2e8cb4f2c0bf068f6d13c0e5 (patch)
tree6f080f704435d22dbfee6ffd454529c12e5bb505 /actionpack/lib/action_view/template
parent7b622786fcc5046a06989ec7a3cbf46f92e04dea (diff)
parent84f6da45a19d335be320991cab44f492f61dc5c7 (diff)
downloadrails-4745b53bcda400cf2e8cb4f2c0bf068f6d13c0e5.tar.gz
rails-4745b53bcda400cf2e8cb4f2c0bf068f6d13c0e5.tar.bz2
rails-4745b53bcda400cf2e8cb4f2c0bf068f6d13c0e5.zip
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'actionpack/lib/action_view/template')
-rw-r--r--actionpack/lib/action_view/template/resolver.rb36
-rw-r--r--actionpack/lib/action_view/template/text.rb6
2 files changed, 18 insertions, 24 deletions
diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb
index 6e6c4c21ee..a43597e728 100644
--- a/actionpack/lib/action_view/template/resolver.rb
+++ b/actionpack/lib/action_view/template/resolver.rb
@@ -21,6 +21,7 @@ module ActionView
# Normalizes the arguments and passes it on to find_template.
def find_all(name, prefix=nil, partial=false, details={}, key=nil)
name, prefix = normalize_name(name, prefix)
+ details = details.merge(:handlers => default_handlers)
cached(key, prefix, name, partial) do
find_templates(name, prefix, partial, details)
@@ -33,6 +34,10 @@ module ActionView
@caching ||= !defined?(Rails.application) || Rails.application.config.cache_classes
end
+ def default_handlers
+ Template::Handlers.extensions + [nil]
+ end
+
# This is what child classes implement. No defaults are needed
# because Resolver guarantees that the arguments are present and
# normalized.
@@ -74,7 +79,7 @@ module ActionView
def find_templates(name, prefix, partial, details)
path = build_path(name, prefix, partial, details)
- query(path, EXTENSION_ORDER.map { |ext| details[ext] })
+ query(partial, path, EXTENSION_ORDER.map { |ext| details[ext] })
end
def build_path(name, prefix, partial, details)
@@ -84,34 +89,27 @@ module ActionView
path
end
- def query(path, exts)
+ def query(partial, path, exts)
query = File.join(@path, path)
+
exts.each do |ext|
query << '{' << ext.map {|e| e && ".#{e}" }.join(',') << '}'
end
Dir[query].reject { |p| File.directory?(p) }.map do |p|
- Template.new(File.read(p), File.expand_path(p), *path_to_details(p))
+ handler, format = extract_handler_and_format(p)
+ Template.new(File.read(p), File.expand_path(p), handler,
+ :partial => partial, :virtual_path => path, :format => format)
end
end
- # # TODO: fix me
- # # :api: plugin
- def path_to_details(path)
- # [:erb, :format => :html, :locale => :en, :partial => true/false]
- if m = path.match(%r'((^|.*/)(_)?[\w-]+)((?:\.[\w-]+)*)\.(\w+)$')
- partial = m[3] == '_'
- details = (m[4]||"").split('.').reject { |e| e.empty? }
- handler = Template.handler_class_for_extension(m[5])
+ def extract_handler_and_format(path)
+ pieces = File.basename(path).split(".")
+ pieces.shift
- format = Mime[details.last] && details.pop.to_sym
- locale = details.last && details.pop.to_sym
-
- virtual_path = (m[1].gsub("#{@path}/", "") << details.join("."))
-
- return handler, :format => format, :locale => locale, :partial => partial,
- :virtual_path => virtual_path
- end
+ handler = Template.handler_class_for_extension(pieces.pop)
+ format = pieces.last && Mime[pieces.last] && pieces.pop.to_sym
+ [handler, format]
end
end
diff --git a/actionpack/lib/action_view/template/text.rb b/actionpack/lib/action_view/template/text.rb
index 5978a8a3ac..df394b0fb0 100644
--- a/actionpack/lib/action_view/template/text.rb
+++ b/actionpack/lib/action_view/template/text.rb
@@ -7,10 +7,6 @@ module ActionView #:nodoc:
@content_type ||= Mime::TEXT
end
- def details
- {:formats => [@content_type.to_sym]}
- end
-
def identifier
'text template'
end
@@ -28,7 +24,7 @@ module ActionView #:nodoc:
end
def formats
- [mime_type]
+ [@content_type.to_sym]
end
def partial?