Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit c883cb06384948d988bae35c5b043561212abc5d @tenderlove tenderlove committed
Showing with 229 additions and 0 deletions.
  1. +8 −0 .autotest
  2. +6 −0 CHANGELOG.rdoc
  3. +8 −0 Manifest.txt
  4. +48 −0 README.rdoc
  5. +18 −0 Rakefile
  6. +33 −0 lib/rack/router.rb
  7. +20 −0 lib/rack/router/strexp.rb
  8. +23 −0 lib/rack/router/utils.rb
  9. +33 −0 rack-router.gemspec
  10. +32 −0 test/router/test_strexp.rb
8 .autotest
@@ -0,0 +1,8 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+Autotest.add_hook :initialize do |at|
+ at.testlib = 'minitest/autorun'
+ at.find_directories = ARGV unless ARGV.empty?
+end
6 CHANGELOG.rdoc
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2011-03-08
+
+* 1 major enhancement
+
+ * Birthday!
+
8 Manifest.txt
@@ -0,0 +1,8 @@
+.autotest
+CHANGELOG.rdoc
+Manifest.txt
+README.rdoc
+Rakefile
+lib/rack/router.rb
+rack-router.gemspec
+test/test_rack_router.rb
48 README.rdoc
@@ -0,0 +1,48 @@
+= rack_router
+
+* FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* FIX (sudo gem install, anything else)
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2011 Aaron Patterson
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 Rakefile
@@ -0,0 +1,18 @@
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+
+Hoe.plugins.delete :rubyforge
+Hoe.plugin :minitest
+Hoe.plugin :gemspec # `gem install hoe-gemspec`
+Hoe.plugin :git # `gem install hoe-git`
+
+Hoe.spec 'rack-router' do
+ developer('Aaron Patterson', 'aaron@tenderlovemaking.com')
+ self.readme_file = 'README.rdoc'
+ self.history_file = 'CHANGELOG.rdoc'
+ self.extra_rdoc_files = FileList['*.rdoc']
+end
+
+# vim: syntax=ruby
33 lib/rack/router.rb
@@ -0,0 +1,33 @@
+require 'rack/router/utils'
+require 'rack/router/strexp'
+
+module Rack
+ class Router
+ VERSION = '1.0.0'
+
+ def initialize options
+ @options = options
+ end
+
+ def add_route app, conditions, defaults, name
+ end
+
+ class RegexpWithNamedGroups
+ def initialize thing
+ case thing
+ when Regexp, String
+ @thing = Regexp.new(thing)
+ else
+ @thing = thing
+ end
+ end
+
+ def names
+ @thing.names
+ end
+ end
+ end
+
+ Mount = Router
+ Mount::RouteSet = Router
+end
20 lib/rack/router/strexp.rb
@@ -0,0 +1,20 @@
+module Rack
+ class Router
+ class Strexp
+ class << self
+ alias :compile :new
+ end
+
+ def initialize path, requirements, separators, anchor = true
+ @path = path
+ @requirements = requirements
+ @separators = separators
+ @anchor = anchor
+ end
+
+ def names
+ @path.scan(/:\w+/).map { |s| s.tr(':', '') }
+ end
+ end
+ end
+end
23 lib/rack/router/utils.rb
@@ -0,0 +1,23 @@
+require 'uri'
+
+module Rack
+ class Router
+ class Utils
+ # Normalizes URI path.
+ #
+ # Strips off trailing slash and ensures there is a leading slash.
+ #
+ # normalize_path("/foo") # => "/foo"
+ # normalize_path("/foo/") # => "/foo"
+ # normalize_path("foo") # => "/foo"
+ # normalize_path("") # => "/"
+ def self.normalize_path(path)
+ path = "/#{path}"
+ path.squeeze!('/')
+ path.sub!(%r{/+\Z}, '')
+ path = '/' if path == ''
+ path
+ end
+ end
+ end
+end
33 rack-router.gemspec
@@ -0,0 +1,33 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{rack-router}
+ s.version = "1.0.0.20110308150354"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Aaron Patterson"]
+ s.date = %q{2011-03-08}
+ s.description = %q{FIX (describe your package)}
+ s.email = ["aaron@tenderlovemaking.com"]
+ s.extra_rdoc_files = ["Manifest.txt", "CHANGELOG.rdoc", "README.rdoc"]
+ s.files = [".autotest", "CHANGELOG.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "lib/rack/router.rb", "rack-router.gemspec", "test/test_rack_router.rb", ".gemtest"]
+ s.homepage = %q{FIX (url)}
+ s.rdoc_options = ["--main", "README.rdoc"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{rack-router}
+ s.rubygems_version = %q{1.6.0}
+ s.summary = %q{FIX (describe your package)}
+ s.test_files = ["test/test_rack_router.rb"]
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<hoe>, [">= 2.9.1"])
+ else
+ s.add_dependency(%q<hoe>, [">= 2.9.1"])
+ end
+ else
+ s.add_dependency(%q<hoe>, [">= 2.9.1"])
+ end
+end
32 test/router/test_strexp.rb
@@ -0,0 +1,32 @@
+require 'rubygems'
+require 'minitest/autorun'
+require 'rack/router'
+
+module Rack
+ class Router
+ class TestStrexp < MiniTest::Unit::TestCase
+ def test_many_names
+ exp = Strexp.new(
+ "/:controller(/:action(/:id(.:format)))",
+ {:controller=>/.+?/},
+ ["/", ".", "?"],
+ true)
+
+ assert_equal ["controller", "action", "id", "format"], exp.names
+ end
+
+ def test_names
+ {
+ "/bar(.:format)" => %w{ format },
+ ":format" => %w{ format },
+ ":format-" => %w{ format },
+ ":format0" => %w{ format0 },
+ ":format1,:format2" => %w{ format1 format2 },
+ }.each do |string, expected|
+ exp = Strexp.new(string, {}, ["/", ".", "?"])
+ assert_equal expected, exp.names
+ end
+ end
+ end
+ end
+end

0 comments on commit c883cb0

Please sign in to comment.
Something went wrong with that request. Please try again.