Sha256: a1823cc4643335ed4277f8ca5a545614d426cc313d4b7c85402f3c36a9529ef4

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

module ActionController
  module Routing
    class RouteSet
      class Mapper
        # Modifies your route set to produce TML-compatible routes. Also connects the default
        # TML request (/index.tml) to the options you provide, if any.
        #
        # Unlike the rest of Rails routing, if you call #connect_rtml multiple times with different
        # options, the /index.tml path will be updated to reflect the new options.
        #
        # To use, just add the following to your /config/routes.rb file:
        # map.connect_rtml :controller => "start_page"
        #
        def connect_rtml(options = {})
          make_rtml_connection('/:controller/:action.:format', '/rtml/index.rtml')
          make_rtml_connection('/:controller/:action.:id.:format', '/rtml/index.1.rtml')
          make_rtml_connection('/:controller/:action/:id', '/rtml/index/1')

          connect_options = !options.empty?
          ActionController::Routing::Routes.routes.each do |route|
            segs = route.segments.to_s[0...-1]
            if segs =~ /^\/index.tml(\/|)$/ && connect_options
              route.requirements.merge! options.reverse_merge(:format => 'rtml')
              connect_options = false
            end
          end

          if connect_options
            connect '/index.tml', options.reverse_merge(:format => 'rtml') unless options.empty?
          end
        end

        private
        def make_rtml_connection(connection, example)
          ActionController::Routing::Routes.recognize_path(example)
        rescue ActionController::RoutingError
          connect connection
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rtml-2.0.3 lib/extensions/action_controller/routing/route_set.rb
rtml-2.0.2 lib/extensions/action_controller/routing/route_set.rb
rtml-2.0.1 lib/extensions/action_controller/routing/route_set.rb
rtml-2.0.0.alpha.1 lib/extensions/action_controller/routing/route_set.rb