Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 318709463ef4a77da9b090dea5e7775fcbbf4297 @joshbuddy committed May 25, 2010
@@ -0,0 +1,60 @@
+= HTTP Router
+
+== Introduction
+
+When I wrote Usher, I made a few compromised in design that I wasn't totally happy with. More and more features got added to it, and eventually, it became harder to maintain. I took a few moments to work in Node.js, and wrote a router there called Sherpa, which I was happier with. But I felt that by losing more abstraction, and tackling just the problem of HTTP routing, I could come up with something even better.
+
+== Features
+
+* Supports variables, and globbing.
+* Regex support for variables.
+* Request condition support.
+* Partial matches.
+* Supports interstitial variables (e.g. /my-:variable-brings.all.the.boys/yard).
+* Very fast and small code base (~600 loc).
+* Sinatra compatibility.
+
+== Usage
+
+=== <tt>HttpRouter.new</tt>
+
+Takes the following options:
+
+* <tt>:default_app</tt> - The default #call made on non-matches. Defaults to a 404 generator.
+* <tt>:ignore_trailing_slash</tt> - Ignores the trailing slash when matching. Defaults to true.
+* <tt>:redirect_trailing_slash</tt> - Redirect on trailing slash matches to non-trailing slash paths. Defaults to false.
+
+=== <tt>#add(name, options)</tt>
+
+Maps a route. The format for variables in paths is:
+ :variable
+ *glob
+
+Everything else is treated literally. Optional parts are surrounded by brackets. Partially matching paths have a trailing <tt>*</tt>. Optional trailing slash matching is done with <tt>/?</tt>.
+
+Once you have a route object, use <tt>HttpRouter::Route#to</tt> to add a destination and <tt>HttpRouter::Route#name</tt> to name it.
+
+e.g.
+
+ r = HttpRouter.new
+ r.add('/test/:variable(.:format)').name(:my_test_path).to {|env| [200, {}, "Hey dude #{env['router.params'][:variable]}"]}
+ r.add('/test').redirect_to("http://www.google.com")
+ r.add('/static').serves_static_from('/my_file_system')
+
+As well, you can support regex matching and request conditions. To add a regex match, use <tt>:matches_with => { :id => /\d+/ }</tt>.
+To match on a request condition you can use <tt>:conditions => {:request_method => %w(POST HEAD)}</tt>.
+
+There are convenience methods HttpRouter#get, HttpRouter#post, etc for each request method.
+
+=== <tt>#url(name or route, *args)</tt>
+
+Generates a route. The args can either be a hash, a list, or a mix of both.
+
+=== <tt>#call(env or Rack::Request)</tt>
+
+Recognizes and dispatches the request.
+
+=== <tt>#recognize(env or Rack::Request)</tt>
+
+Only performs recognition.
+
@@ -0,0 +1,32 @@
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |s|
+ s.name = "http_router"
+ s.description = s.summary = "A kick-ass HTTP router for use in Rack & Sinatra"
+ s.email = "joshbuddy@gmail.com"
+ s.homepage = "http://github.com/joshbuddy/http_router"
+ s.authors = ["Joshua Hull"]
+ s.files = FileList["[A-Z]*", "{lib,spec}/**/*"]
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+end
+
+require 'spec'
+require 'spec/rake/spectask'
+Spec::Rake::SpecTask.new(:spec) do |t|
+ t.spec_opts ||= []
+ t.ruby_opts << "-rrubygems"
+ t.ruby_opts << "-Ilib"
+ t.ruby_opts << "-rhttp_router"
+ t.ruby_opts << "-rspec/spec_helper"
+ t.spec_opts << "--options" << "spec/spec.opts"
+ t.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+begin
+ require 'code_stats'
+ CodeStats::Tasks.new
+rescue LoadError
+end
@@ -0,0 +1 @@
+0.0.1
@@ -0,0 +1,57 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{http_router}
+ s.version = "0.0.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Joshua Hull"]
+ s.date = %q{2010-05-25}
+ s.description = %q{A kick-ass HTTP router for use in Rack & Sinatra}
+ s.email = %q{joshbuddy@gmail.com}
+ s.extra_rdoc_files = [
+ "README.rdoc"
+ ]
+ s.files = [
+ "README.rdoc",
+ "Rakefile",
+ "VERSION",
+ "lib/http_router.rb",
+ "lib/http_router/glob.rb",
+ "lib/http_router/node.rb",
+ "lib/http_router/path.rb",
+ "lib/http_router/response.rb",
+ "lib/http_router/root.rb",
+ "lib/http_router/route.rb",
+ "lib/http_router/sinatra.rb",
+ "lib/http_router/variable.rb",
+ "lib/rack/uri_escape.rb",
+ "spec/generate_spec.rb",
+ "spec/rack/dispatch_spec.rb",
+ "spec/rack/generate_spec.rb",
+ "spec/rack/route_spec.rb",
+ "spec/recognize_spec.rb",
+ "spec/sinatra/recognize_spec.rb",
+ "spec/spec.opts",
+ "spec/spec_helper.rb"
+ ]
+ s.homepage = %q{http://github.com/joshbuddy/http_router}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.6}
+ s.summary = %q{A kick-ass HTTP router for use in Rack & Sinatra}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
+
Oops, something went wrong.

0 comments on commit 3187094

Please sign in to comment.