diff --git a/sinatra-contrib/README.md b/sinatra-contrib/README.md
index 9111240f..36a62749 100644
--- a/sinatra-contrib/README.md
+++ b/sinatra-contrib/README.md
@@ -58,9 +58,6 @@ existing APIs.
Currently included:
-* `sinatra/decompile`: Recreates path patterns from Sinatra's internal data
- structures (used by other extensions).
-
* `sinatra/reloader`: Automatically reloads Ruby files on code changes.
## Other Tools
diff --git a/sinatra-contrib/lib/sinatra/contrib.rb b/sinatra-contrib/lib/sinatra/contrib.rb
index 5c32fe08..2f61b297 100644
--- a/sinatra-contrib/lib/sinatra/contrib.rb
+++ b/sinatra-contrib/lib/sinatra/contrib.rb
@@ -26,7 +26,6 @@ module Sinatra
# Other extensions you don't want to be loaded unless needed.
module Custom
# register :Compass
- register :Decompile
register :Reloader
end
diff --git a/sinatra-contrib/lib/sinatra/decompile.rb b/sinatra-contrib/lib/sinatra/decompile.rb
deleted file mode 100644
index 41bfe3df..00000000
--- a/sinatra-contrib/lib/sinatra/decompile.rb
+++ /dev/null
@@ -1,127 +0,0 @@
-require 'sinatra/base'
-require 'backports'
-require 'uri'
-
-module Sinatra
-
- # = Sinatra::Decompile
- #
- # Sinatra::Decompile is an extension that provides a method,
- # conveniently called +decompile+, that will generate a String pattern for a
- # given route.
- #
- # == Usage
- #
- # === Classic Application
- #
- # To use the extension in a classic application all you need to do is require
- # it:
- #
- # require "sinatra"
- # require "sinatra/decompile"
- #
- # # Your classic application code goes here...
- #
- # This will add the +decompile+ method to the application/class scope, but
- # you can also call it as Sinatra::Decompile.decompile.
- #
- # === Modular Application
- #
- # To use the extension in a modular application you need to require it, and
- # then, tell the application you will use it:
- #
- # require "sinatra/base"
- # require "sinatra/decompile"
- #
- # class MyApp < Sinatra::Base
- # register Sinatra::Decompile
- #
- # # The rest of your modular application code goes here...
- # end
- #
- # This will add the +decompile+ method to the application/class scope. You
- # can choose not to register the extension, but instead of calling
- # +decompile+, you will need to call Sinatra::Decompile.decompile.
- #
- module Decompile
- extend self
-
- ##
- # Regenerates a string pattern for a given route
- #
- # Example:
- #
- # class Sinatra::Application
- # routes.each do |verb, list|
- # puts "#{verb}:"
- # list.each do |data|
- # puts "\t" << decompile(data)
- # end
- # end
- # end
- #
- # Will return the internal Regexp if it's unable to reconstruct the pattern,
- # which likely indicates that a Regexp was used in the first place.
- #
- # You can also use this to check whether you could actually use a string
- # pattern instead of your regexp:
- #
- # decompile /^/foo$/ # => '/foo'
- def decompile(pattern, keys = nil, *)
- # Everything in here is basically just the reverse of
- # Sinatra::Base#compile
- #
- # Sinatra 2.0 will come with a mechanism for this, making this obsolete.
- pattern, keys = pattern if pattern.respond_to? :to_ary
- keys, str = keys.try(:dup), pattern.inspect
- return pattern unless str.start_with? '/' and str.end_with? '/'
- str.gsub! /^\/(\^|\\A)?|(\$|\\z)?\/$/, ''
- str.gsub! encoded(' '), ' '
- return pattern if str =~ /^[\.\+]/
- str.gsub! '((?:[^\.\/?#%]|(?:%[^2].|%[2][^Ee]))+)', '([^\/?#]+)'
- str.gsub! '((?:[^\/?#%]|(?:%[^2].|%[2][^Ee]))+)', '([^\/?#]+)'
- str.gsub! /\([^\(\)]*\)|\([^\(\)]*\([^\(\)]*\)[^\(\)]*\)/ do |part|
- case part
- when '(.*?)'
- return pattern if keys.shift != 'splat'
- '*'
- when /^\(\?\:(\\*.)\|%[\w\[\]]+\)$/
- $1
- when /^\(\?\:(%\d+)\|([^\)]+|\([^\)]+\))\)$/
- URI.unescape($1)
- when '([^\/?#]+)'
- return pattern if keys.empty?
- ":" << keys.shift
- when /^\(\?\:\\?(.)\|/
- char = $1
- return pattern unless encoded(char) == part
- Regexp.escape(char)
- else
- return pattern
- end
- end
- str.gsub /(.)([\.\+\(\)\/])/ do
- return pattern if $1 != "\\"
- $2
- end
- end
-
- private
-
- def encoded(char)
- return super if defined? super
- enc = uri_parser.escape(char)
- enc = "(?:#{escaped(char, enc).join('|')})" if enc == char
- enc = "(?:#{enc}|#{encoded('+')})" if char == " "
- enc
- end
-
- def uri_parser
- #TODO: Remove check after dropping support for 1.8.7
- @_uri_parser ||= defined?(URI::Parser) ? URI::Parser.new : URI
- end
-
- end
-
- register Decompile
-end
diff --git a/sinatra-contrib/lib/sinatra/namespace.rb b/sinatra-contrib/lib/sinatra/namespace.rb
index d58902d6..f946c324 100644
--- a/sinatra-contrib/lib/sinatra/namespace.rb
+++ b/sinatra-contrib/lib/sinatra/namespace.rb
@@ -1,6 +1,5 @@
require 'backports'
require 'sinatra/base'
-require 'sinatra/decompile'
module Sinatra
@@ -163,7 +162,6 @@ module Sinatra
module NamespacedMethods
include SharedMethods
- include Sinatra::Decompile
attr_reader :base, :templates
def self.prefixed(*names)
diff --git a/sinatra-contrib/sinatra-contrib.gemspec b/sinatra-contrib/sinatra-contrib.gemspec
index 1648bbd0..04186b69 100644
--- a/sinatra-contrib/sinatra-contrib.gemspec
+++ b/sinatra-contrib/sinatra-contrib.gemspec
@@ -137,7 +137,6 @@ Gem::Specification.new do |s|
"lib/sinatra/contrib/version.rb",
"lib/sinatra/cookies.rb",
"lib/sinatra/custom_logger.rb",
- "lib/sinatra/decompile.rb",
"lib/sinatra/engine_tracking.rb",
"lib/sinatra/extension.rb",
"lib/sinatra/json.rb",
@@ -193,7 +192,6 @@ Gem::Specification.new do |s|
"spec/content_for_spec.rb",
"spec/cookies_spec.rb",
"spec/custom_logger_spec.rb",
- "spec/decompile_spec.rb",
"spec/extension_spec.rb",
"spec/json_spec.rb",
"spec/link_header_spec.rb",
diff --git a/sinatra-contrib/spec/decompile_spec.rb b/sinatra-contrib/spec/decompile_spec.rb
deleted file mode 100644
index d3686a1c..00000000
--- a/sinatra-contrib/spec/decompile_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require 'spec_helper'
-
-RSpec::Matchers.define :decompile do |path|
- match do |app|
- @compiled, @keys = app.send :compile, path
- @decompiled = app.decompile(@compiled, @keys)
- @decompiled.should == path
- end
-
- failure_message_for_should do |app|
- values = [app, @compiled, @keys, path, @decompiled].map(&:inspect)
- "expected %s to decompile %s with %s to %s, but was %s" % values
- end
-end
-
-describe Sinatra::Decompile do
- subject { Sinatra::Application }
- it { should decompile("") }
- it { should decompile("/") }
- it { should decompile("/?") }
- it { should decompile("/foo") }
- it { should decompile("/:name") }
- it { should decompile("/:name?") }
- it { should decompile("/:foo/:bar") }
- it { should decompile("/page/:id/edit") }
- it { should decompile("/hello/*") }
- it { should decompile("/*/foo/*") }
- it { should decompile("*") }
- it { should decompile(":name.:format") }
- it { should decompile("a b") }
- it { should decompile("a+b") }
- it { should decompile(/./) }
- it { should decompile(/f(oo)/) }
- it { should decompile(/ba+r/) }
-
- it 'just returns strings' do
- subject.decompile('/foo').should == '/foo'
- end
-
- it 'just decompile simple regexps without keys' do
- subject.decompile(%r{/foo}).should == '/foo'
- end
-end