Files

Padrino::Routing::InstanceMethods

Instance methods related to recognizing and processing routes and serving static files.

Public Instance Methods

content_type(type=nil, params={}) click to toggle source

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
current_path(*path_params) click to toggle source

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
recognize_path(path) click to toggle source

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
route() click to toggle source

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
static!() click to toggle source

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
static_file?(path_info) click to toggle source

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
url(*args) click to toggle source

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
Also aliased as: url_for
url_for(*args) click to toggle source
Alias for: url

[Validate]

Generated with the Darkfish Rdoc Generator 2.