rack-rewrite_root_filter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-rewrite_root_filter.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1 @@
1
+ require "rack/rewrite_root_filter"
@@ -0,0 +1,41 @@
1
+ require "rack/rewrite_root_filter/version"
2
+
3
+ module Rack
4
+ class RewriteRootFilter
5
+ def initialize app, from, to
6
+ @app = app
7
+ @from = from
8
+ @to = to
9
+ end
10
+
11
+ def call env
12
+ env = rewrite_request env
13
+ status, headers, body = @app.call env
14
+
15
+ body = rewrite_body body
16
+ [status, headers, body]
17
+ end
18
+
19
+ private
20
+
21
+ def rewrite_request env
22
+ interpreted_to = env['REQUEST_URI'].sub /^#{@to}/, @from
23
+ env['REQUEST_URI'] = interpreted_to
24
+ if q_index = interpreted_to.index('?')
25
+ env['PATH_INFO'] = interpreted_to[0..q_index-1]
26
+ env['QUERY_STRING'] = interpreted_to[q_index+1..interpreted_to.size-1]
27
+ else
28
+ env['PATH_INFO'] = interpreted_to
29
+ env['QUERY_STRING'] = ''
30
+ end
31
+ env
32
+ end
33
+
34
+ def rewrite_body body
35
+ new_body = ""
36
+ body.each { |part| new_body << part }
37
+ new_body.gsub! /(["'])#{@from}/, "\\1#{@to}"
38
+ [new_body]
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class RewriteRootFilter
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack/rewrite_root_filter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rack-rewrite_root_filter"
7
+ s.version = Rack::RewriteRootFilter::VERSION
8
+ s.authors = ["Micah Geisel"]
9
+ s.email = ["micah@botandrose.com"]
10
+ s.homepage = "http://github.com/botandrose/rack-rewrite_root_filter"
11
+ s.summary = %q{Rack middleware to rewrite the links on both the request and the response.}
12
+ s.description = %q{Rack middleware to rewrite the links on both the request and the response.}
13
+
14
+ s.rubyforge_project = "rack-rewrite_root_filter"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-rewrite_root_filter
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Micah Geisel
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-17 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Rack middleware to rewrite the links on both the request and the response.
22
+ email:
23
+ - micah@botandrose.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - Rakefile
34
+ - lib/rack-rewrite_root_filter.rb
35
+ - lib/rack/rewrite_root_filter.rb
36
+ - lib/rack/rewrite_root_filter/version.rb
37
+ - rack-rewrite_root_filter.gemspec
38
+ homepage: http://github.com/botandrose/rack-rewrite_root_filter
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project: rack-rewrite_root_filter
67
+ rubygems_version: 1.8.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Rack middleware to rewrite the links on both the request and the response.
71
+ test_files: []
72
+