Skip to content

Instantly share code, notes, and snippets.

@shawn42
Created October 25, 2010 14:16
Show Gist options
  • Save shawn42/645019 to your computer and use it in GitHub Desktop.
Save shawn42/645019 to your computer and use it in GitHub Desktop.
rails3 template/resolver.rb
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