Sha256: 23ed789409045dd4340f0246398bb65d7c7f3966cb75ac4e376cc3aa56b6147f

Contents?: true

Size: 955 Bytes

Versions: 3

Compression:

Stored size: 955 Bytes

Contents

module Nitro

# Router mixin. Typically used to generate 'nice' urls.
# Nice urls are considered (?) more Search Engine 
# friendly.
#
# However, due to the power of Nitro'w intelligent dispatching
# mechanism, routing is almost never used!
  
module Router
  
  # The route table maps 'nice URLs' to real URLs that
  # can be handled by the Dispatcher.

  attr_accessor :routes
  
  # Strip the beginning of the path, used by cgi adapter.
  
  setting :strip_path, :default => nil, :doc => 'Strip the beginning of the path, used by cgi adapter'

  # Apply routing rules to the path.

  def route(path, context)
    for rule, real_path, *params in @routes
      if md = path.match(rule)
        params.each_with_index do |p, idx|
          context[p] = md.captures[idx]
        end
        return real_path
      end
    end

    path.sub!(Router.strip_path, '') if Router.strip_path
    return path
  end

end

end

# * George Moschovitis  <gm@navel.gr>

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nitro-0.26.0 lib/nitro/routing.rb
nitro-0.27.0 lib/nitro/routing.rb
nitro-0.28.0 lib/nitro/routing.rb