Sha256: eb493c56f8c5be20d382b9dc01864b934b6da94990f4e80436e6859224fa3e2c

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

require 'nitro/dispatcher'

module Nitro

# Specialize the Dispatcher to handle general urls. This is 
# useful for PHP/ASP style programming.

class Dispatcher
  
  # An alternative dispatching algorithm that handles
  # general urls. Action containing '/' separators look for
  # templates in subdirectories. The '/' char is converted
  # to '__' to find the actual action.
  
  def dispatch(path, context = nil)
    path = route(path, context)

    parts = path.split('/')
    parts.shift

    case parts.size
      when 0
        # / -> root.index
        base = '/' 
        klass = controller_class_for(base)
        action = 'index'
      
      when 1 
        base = "/#{parts[0]}"
        if klass = controller_class_for(base)
          # controller/ -> controller.index
          action = 'index'
        else
          # action/ -> root.action
          base = '/'
          klass = controller_class_for(base)
          action = parts[0]
        end
        
      else
        base = "/#{parts[0]}"
        if klass = controller_class_for(base)
          # controller/action -> controller.action
          parts.shift
          action = parts.join('__')
        else
          # action/ -> root.action
          base = '/'
          klass = controller_class_for(base)
          action = parts.join('__')
        end
    end

    return klass, "#{action}_action", base
  end
end

Dispatcher.mode = :general

end

# * George Moschovitis <gm@navel.gr>

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nitro-0.21.2 lib/nitro/dispatcher/general.rb
nitro-0.22.0 lib/nitro/dispatcher/general.rb
nitro-0.23.0 lib/nitro/dispatcher/general.rb
nitro-0.24.0 lib/nitro/dispatcher/general.rb
nitro-0.25.0 lib/nitro/dispatcher/general.rb