def find_template(url, options = {})
      orig_path, qs, anch = strip_query_string_and_anchor(url.to_s)

      options = {
        :exact_match => false,
        :preferred_extension => "html"  
      }.update(options)

      paths = self.load_paths.map{|base| File.join(base, orig_path) }
  
      paths.find do |path|
        if options[:exact_match] && File.exist?(path)
          return Pathname.new(path)
        end      
        
        # It's a directory, add "/index"
        if File.directory?(path)
          path = File.join(path, "index")
        end
        
        # 2. If it's preferred_extension, we strip of the extension
        if path =~ /\.#{options[:preferred_extension]}\Z/
          path.sub!(/\.#{options[:preferred_extension]}\Z/, "")
        end
        
        extensions = Tilt.default_mapping.template_map.keys + Tilt.default_mapping.lazy_map.keys

        # We have to re-add preferred_extension again as we have stripped it in in step 2!
        extensions += extensions.map{|ext| "#{options[:preferred_extension]}.#{ext}"}

        if found_extension = extensions.find { |ext| File.exist?(path + "." + ext) }
          return Pathname.new(path + "." + found_extension)
        end

        false #Next iteration
      end
    end
def find_template(url, options = {})
      orig_path, qs, anch = strip_query_string_and_anchor(url.to_s)

      options = {
        :exact_match => false,
        :preferred_extension => "html"  
      }.update(options)

      paths = self.load_paths.map{|base| File.join(base, orig_path) }
  
      paths.find do |path|
        if options[:exact_match] && File.exist?(path)
          return Pathname.new(path)
        end      
        
        # It's a directory, add "/index"
        if File.directory?(path)
          path = File.join(path, "index")
        end
        
        # 2. If it's preferred_extension, we strip of the extension
        if path =~ /\.#{options[:preferred_extension]}\Z/
          path.sub!(/\.#{options[:preferred_extension]}\Z/, "")
        end
        
        extensions = Tilt.default_mapping.template_map.keys + Tilt.default_mapping.lazy_map.keys

        # We have to re-add preferred_extension again as we have stripped it in in step 2!
        extensions += extensions.map{|ext| "#{options[:preferred_extension]}.#{ext}"}

        if found_extension = extensions.find { |ext| File.exist?(path + "." + ext) }
          return Pathname.new(path + "." + found_extension)
        end

        false #Next iteration
      end
    end
@param [String] url The url to resolve to a path
 @param [Hash] options Options

 @option options [true,false] :exact_match Wether or not to match exact paths, this is mainly used in the path_to_url method to match .js, .css, etc files.
 @option options [String] :preferred_extension The part to chop off and re-add to search for more complex double-extensions. (Makes it possible to have context aware partials)