Created
October 25, 2010 14:16
-
-
Save shawn42/645019 to your computer and use it in GitHub Desktop.
rails3 template/resolver.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionView | |
# = Action View Resolver | |
class Resolver | |
... | |
def find_templates(name, prefix, partial, details) | |
path = build_path(name, prefix, partial, details) | |
query(path, EXTENSION_ORDER.map { |ext| details[ext] }, details[:formats]) | |
end | |
def query(path, exts, formats) | |
query = File.join(@path, path) | |
exts.each do |ext| | |
query << '{' << ext.map {|e| e && ".#{e}" }.join(',') << ',}' | |
end | |
query.gsub!(/\{\.html,/, "{.html,.text.html,") | |
query.gsub!(/\{\.text,/, "{.text,.text.plain,") | |
# this is the same as Dir.glob .. | |
Dir[query].reject { |p| File.directory?(p) }.map do |p| | |
handler, format = extract_handler_and_format(p, formats) | |
contents = File.open(p, "rb") {|io| io.read } | |
Template.new(contents, File.expand_path(p), handler, | |
:virtual_path => path, :format => format) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment