class ActionView::PathResolver
def build_path(name, prefix, partial, details)
def build_path(name, prefix, partial, details) path = "" path << "#{prefix}/" unless prefix.empty? path << (partial ? "_#{name}" : name) path end
def escape_entry(entry)
def escape_entry(entry) entry.gsub(/(\*|\[|\]|\{|\}|\?)/, "\\\\\\1") end
def extract_handler_and_format(path, default_formats)
from the path, or the handler, we should return the array of formats given
Extract handler and formats from path. If a format cannot be a found neither
def extract_handler_and_format(path, default_formats) pieces = File.basename(path).split(".") pieces.shift handler = Template.handler_class_for_extension(pieces.pop) if pieces.last == "html" && pieces[-2] == "text" correct_path = path.gsub(/\.text\.html/, ".html") ActiveSupport::Deprecation.warn "The file `#{path}` uses the deprecated format `text.html`. Please rename it to #{correct_path}", caller end if pieces.last == "plain" && pieces[-2] == "text" correct_path = path.gsub(/\.text\.plain/, ".text") pieces.pop ActiveSupport::Deprecation.warn "The file `#{path}` uses the deprecated format `text.plain`. Please rename it to #{correct_path}", caller end format = pieces.last && Mime[pieces.last] && pieces.pop.to_sym format ||= handler.default_format if handler.respond_to?(:default_format) format ||= default_formats [handler, format] end
def find_templates(name, prefix, partial, details)
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)
def query(path, exts, formats) query = escape_entry 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,") templates = [] sanitizer = Hash.new { |h,k| h[k] = Dir["#{File.dirname(k)}/*"] } Dir[query].each do |p| next if File.directory?(p) || !sanitizer[p].include?(p) handler, format = extract_handler_and_format(p, formats) contents = File.open(p, "rb") {|io| io.read } templates << Template.new(contents, File.expand_path(p), handler, :virtual_path => path, :format => format) end templates end
def to_s
def to_s @path.to_s end