Permalink
Browse files

no longer used

  • Loading branch information...
1 parent 3d25a35 commit 8413451cd18cbb24b19e213b7afe4ddc8d24935b Blake Mizerany committed Oct 4, 2007
Showing with 0 additions and 82 deletions.
  1. +0 −44 lib/sinatra/pretty_url.rb
  2. +0 −38 test/sinatra/pretty_url_test.rb
View
@@ -1,44 +0,0 @@
-module Sinatra
-
- class PrettyUrl
- attr_reader :path, :vars
-
- VALID_FORMATS = %w( xml html )
-
- def initialize(path)
- @path = path
- @param_keys = []
- @vars = {}
- @regex = create_regex_from_path(@path)
- end
-
- def matches?(path)
- !(path =~ @regex).nil?
- end
-
- def extract_params(path)
- if matches = path.to_s.scan(@regex).flatten
- @param_keys.each_with_index do |v, i|
- @vars[v] = matches[i]
- end
- end
- vars[:format] = extract_format(path)
- vars
- end
-
- private
-
- def extract_format(path)
- format = File.extname(path)[1..-1]
- VALID_FORMATS.include?(format) ? format : 'html'
- end
-
- def create_regex_from_path(path)
- path = path.dup
- path.gsub!(/:(\w+)/) { @param_keys << $1.intern; '([\w\d-]+)' }
- path.gsub!(/(\/\.)/) { "\#{$1}" }
- /^#{path}$/
- end
- end
-
-end
@@ -1,38 +0,0 @@
-require File.dirname(__FILE__) + '/../helper.rb'
-
-describe "When a PrettyUrl is created" do
- it "should remember its raw path" do
- Sinatra::PrettyUrl.new('/foo/:bar').path.should.equal '/foo/:bar'
- end
-
- it "should match a uri with one to many params" do
- Sinatra::PrettyUrl.new('/foo').matches?('/foo').should.equal true
- Sinatra::PrettyUrl.new('/foo/:name.:format').matches?('/foo/blake2-test.xml').should.equal true
- Sinatra::PrettyUrl.new('/foo/:name.:format').matches?('/foo/blake2-test..xml').should.equal false
- Sinatra::PrettyUrl.new('/index').matches?('/foo').should.equal false
- Sinatra::PrettyUrl.new('/').matches?('/bar').should.equal false
- end
-
- it "should extract vars as params" do
- url = Sinatra::PrettyUrl.new('/foo/:name.:format')
- params = url.extract_params('/foo/blake2-test.xml')
- params.should.equal :format => "xml", :name => 'blake2-test'
- end
-
- it "should always add a format" do
- url = Sinatra::PrettyUrl.new('/foo/:name')
- params = url.extract_params('/foo/blake')
- params[:format].should.equal "html"
- params = url.extract_params('/foo/blake.xml')
- params[:format].should.equal "xml"
- end
-
- it "should default to html format if not a valid format" do
- url = Sinatra::PrettyUrl.new('/foo/:name')
- params = url.extract_params('/foo/blake.mizerany')
- params[:format].should.equal "html"
- end
-
-end
-
-

0 comments on commit 8413451

Please sign in to comment.