class Middleman::TemplateRenderer
def self.resolve_template(app, request_path, options={})
def self.resolve_template(app, request_path, options={}) # Find the path by searching relative_path = Util.strip_leading_slash(request_path.to_s) # By default, any engine will do preferred_engines = [] # If we're specifically looking for a preferred engine if options.key?(:preferred_engine) extension_class = ::Middleman::Util.tilt_class(options[:preferred_engine]) # Get a list of extensions for a preferred engine preferred_engines += ::Tilt.default_mapping.extensions_for(extension_class) end preferred_engines << '*' preferred_engines << nil if options[:try_static] found_template = nil preferred_engines.each do |preferred_engine| path_with_ext = relative_path.dup path_with_ext << ('.' + preferred_engine) unless preferred_engine.nil? globbing = preferred_engine == '*' # Cache lookups in build mode only file = if app.build? cache.fetch(path_with_ext, preferred_engine) do app.files.find(:source, path_with_ext, globbing) end else app.files.find(:source, path_with_ext, globbing) end found_template = file if file && (preferred_engine.nil? || ::Middleman::Util.tilt_class(file[:full_path].to_s)) break if found_template end # If we found one, return it found_template end