Sha256: 4915bea35321df9e96cb57beccf9043249b1e5f5c5255a99e3c95e2e13284ef4

Contents?: true

Size: 1.53 KB

Versions: 16

Compression:

Stored size: 1.53 KB

Contents

# coding: utf-8

module UzuUzu
  module Helper
    module Route
      def url_for_controller(controller, *args)
        route_string = request.env['SCRIPT_NAME'].clone
        application.controllers.each do |root_controller|
          re = Regexp.compile("^#{root_controller.name}::")
          if re =~ controller.name
            path = controller.name.gsub(re, '').gsub(/Controller$/, '').to_const_path
            route_string << "/#{path}" unless path == 'index'
            break
          end
        end
        if args[-1].kind_of?(Hash)
          query = query_string(args.pop)
        end
        args.each do |arg|
          route_string << "/#{arg}"
        end
        
        route_string << '/' if args.blank?
        route_string << query unless query.blank?
        route_string
      end
      alias :rf :url_for_controller
      
      def url_for(*args)
        route_string = route.clone
        if args[-1].kind_of?(Hash)
          query = query_string(args.pop)
        end
        args.each do |arg|
          route_string << "/#{arg}"
        end
        route_string << '/' if args.blank?
        route_string << query unless query.blank?
        route_string
      end
      alias :r :url_for
      
      def root_uri
        abs_uri = "#{request.scheme}://#{request.host}"
        if request.scheme == 'https' && request.port != 443 ||
        request.scheme == 'http' && request.port != 80
          abs_uri << ":#{request.port}"
        end
        abs_uri << "#{request.env['SCRIPT_NAME']}"
        abs_uri
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
uzuuzu-core-0.1.11 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.10 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.8 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.7 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.6 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.5 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.4 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.3 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.2.001 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.2 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.1 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.1.0 lib/uzuuzu-core/helper/route.rb
uzuuzu-core-0.0.15 lib/uzuuzu/helper/route.rb
uzuuzu-core-0.0.14 lib/uzuuzu/helper/route.rb
uzuuzu-core-0.0.13 lib/uzuuzu/helper/route.rb
uzuuzu-core-0.0.12 lib/uzuuzu/helper/route.rb