Instance methods related to recognizing and processing routes and serving static files.
Return the request format, this is useful when we need to respond to a given Content-Type.
@param [Symbol, nil] type
@param [Hash] params
@example
get :index, :provides => :any do case content_type when :js then ... when :json then ... when :html then ... end end
# File lib/padrino-core/application/routing.rb, line 885 def content_type(type=nil, params={}) unless type.nil? super(type, params) @_content_type = type end @_content_type end
Returns the current path within a route from specified path_params.
# File lib/padrino-core/application/routing.rb, line 824 def current_path(*path_params) if path_params.last.is_a?(Hash) path_params[-1] = params.merge(path_params[-1]) else path_params << params end @route.url(*path_params) end
Returns the recognized path for a route.
# File lib/padrino-core/application/routing.rb, line 817 def recognize_path(path) settings.recognize_path(path) end
Returns the current route
@example
-if route.controller == :press %li=show_article
# File lib/padrino-core/application/routing.rb, line 840 def route @route end
Method for deliver static files.
# File lib/padrino-core/application/routing.rb, line 860 def static! if path = static_file?(request.path_info) env['sinatra.static_file'] = path cache_control *settings.static_cache_control if settings.static_cache_control? send_file(path, :disposition => nil) end end
This is mostly just a helper so request.path_info isn’t changed when serving files from the public directory.
# File lib/padrino-core/application/routing.rb, line 848 def static_file?(path_info) return if (public_dir = settings.public_folder).nil? public_dir = File.expand_path(public_dir) path = File.expand_path(public_dir + unescape(path_info)) return if path[0, public_dir.length] != public_dir return unless File.file?(path) return path end
Instance method for url generation.
@example
url(:show, :id => 1) url(:show, :name => :test) url(:show, 1) url("/foo")
@see Padrino::Routing::ClassMethods#url
# File lib/padrino-core/application/routing.rb, line 804 def url(*args) # Delegate to Sinatra 1.2 for simple url("/foo") # http://www.sinatrarb.com/intro#Generating%20URLs return super if args.first.is_a?(String) && !args[1].is_a?(Hash) # Delegate to Padrino named route url generation settings.url(*args) end
Generated with the Darkfish Rdoc Generator 2.