rewritten 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +126 -0
- data/lib/rewritten/rails/url_helpers.rb +12 -0
- data/lib/rewritten/rails.rb +1 -0
- data/lib/rewritten/version.rb +1 -1
- data/rewritten.gemspec +1 -0
- data/test/test_helper.rb +3 -0
- metadata +19 -3
- data/README.rdoc +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a44ade38a5b5052b5d98a4424fc444e7b4208939
|
4
|
+
data.tar.gz: 6ddaf0da53b50cca46e91c6d4a77a90003abfeb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2c287f97d495e2a7f566baba6ab2a9c266f05f984daa5eca6d76cd74a0961c5fc0e62d08517ddf616612468dc2c74f1253b50f2ceefde2f3eb61e3ff59f9986
|
7
|
+
data.tar.gz: 0ca027f2379473fbf9602fcaf04c33d62e00b3f56c3628d903e99b372e1b83102c78da4ee5aee4bac9644b69a005ee29ce469df5d4b8ec14061c2fc9139aa2b5
|
data/README.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
Rewritten [![Build Status](https://travis-ci.org/learnjin/rewritten.png?branch=master)](https://travis-ci.org/learnjin/rewritten/) [![Code Climate](https://codeclimate.com/github/learnjin/rewritten.png)](https://codeclimate.com/github/learnjin/rewritten) [![Coverage Status](https://coveralls.io/repos/learnjin/rewritten/badge.png)](https://coveralls.io/r/learnjin/rewritten)
|
2
|
+
=========
|
3
|
+
|
4
|
+
Rewritten is a lookup-based rewriting engine that rewrites requested URLs on
|
5
|
+
the fly. The URL manipulations depend on translations found in a redis
|
6
|
+
database. URLs without translations are passed through while URLs with
|
7
|
+
translations result in a either redirection or ultimatively in a modification
|
8
|
+
of path and request parameters. The gem is compromised of several parts:
|
9
|
+
|
10
|
+
1. A Ruby library for creating, modifying and querying translations.
|
11
|
+
2. A Sinatra app for displaying and managing translations
|
12
|
+
3. A Rack app for rewriting and redirecting requests (Rack::Rewritten::Url)
|
13
|
+
4. A Rack app for substituting URLs in HTML pages with their current translation (Rack::Rewritten::Html)
|
14
|
+
5. A Rack app for recording requests (Rack::Rewritten::Record)
|
15
|
+
6. A Rack app for identifying subdomains (Rack::Rewritten::Subdomain)
|
16
|
+
|
17
|
+
Part 1. and 2. are based heavily on parts from the Resque codebase.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
gem install rewritten
|
22
|
+
|
23
|
+
On Rails add Rewritten to your Gemfile:
|
24
|
+
|
25
|
+
gem 'rewritten'
|
26
|
+
|
27
|
+
Rewritten works completely transparent and decoupled as Rack middleware. Add it to your rack stack.
|
28
|
+
|
29
|
+
# config.ru
|
30
|
+
require 'rewritten'
|
31
|
+
|
32
|
+
Rewritten.redis = Redis.new(host: 'host', port: 'port', password: 'password' )
|
33
|
+
|
34
|
+
map "/" do
|
35
|
+
use Rack::Rewritten::Url
|
36
|
+
use Rack::Rewritten::Html
|
37
|
+
run MyApp::Application
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
This will translate pretty/SEO requests to the language that MyApp speaks and translate the HTML-Output of
|
42
|
+
MyApp to the desired pretty/SEO language.
|
43
|
+
|
44
|
+
On Rails the HTML translation can also be achieved by including the following to your <tt>application_controller.rb</tt>:
|
45
|
+
|
46
|
+
require 'rewritten/rails'
|
47
|
+
|
48
|
+
class ApplicationController < Action:Controller::Base
|
49
|
+
|
50
|
+
include Rewritten::Rails::UrlHelper
|
51
|
+
|
52
|
+
# ....
|
53
|
+
#
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
This way all routes helpers will be translated.
|
58
|
+
|
59
|
+
|
60
|
+
## Managing Vocabulary
|
61
|
+
|
62
|
+
To manage the vocabulary from within your Rack app you need to establish a connection to the same
|
63
|
+
redis db (on Rails put this into an initializer).
|
64
|
+
|
65
|
+
include 'rewritten'
|
66
|
+
Rewritten.redis = Redis.new(host: 'host', port: 'port', password: 'password' )
|
67
|
+
|
68
|
+
The ruby library allows you to successively add and remove vocabulary:
|
69
|
+
|
70
|
+
Rewritten.add_translation('/apple-computer/newton', '/products/4e4d3c6a1d41c811e8000009')
|
71
|
+
Rewritten.add_translation('/apple/ipad', '/products/4e4d3c6a1d41c811e8000009')
|
72
|
+
|
73
|
+
Rewritten.remove_translation('/failed-computer/newton', '/products/4e4d3c6a1d41c811e8000009')
|
74
|
+
|
75
|
+
|
76
|
+
To query for the current "trade language" use:
|
77
|
+
|
78
|
+
Rewritten.get_current_translation('/products/4e4d3c6a1d41c811e8000009') # => "/apple/ipad"
|
79
|
+
|
80
|
+
|
81
|
+
## The web front end
|
82
|
+
|
83
|
+
Rewritten comes with a Sinatra-based front end for dislaying and
|
84
|
+
managing your URL translations (layout taken from Resque). Include it in your Rack stack with:
|
85
|
+
|
86
|
+
require 'rewritten/server'
|
87
|
+
|
88
|
+
map "/rewritten" do
|
89
|
+
use Rack::Auth::Basic do |username, password|
|
90
|
+
username == 'user' and password == 'password'
|
91
|
+
end
|
92
|
+
run Rewritten::Server
|
93
|
+
end
|
94
|
+
|
95
|
+
### Standalone
|
96
|
+
|
97
|
+
Running the gem in standalone mode is easy as well:
|
98
|
+
|
99
|
+
$ rewritten-web
|
100
|
+
|
101
|
+
It's based on Vegas, a thin layer around rackup, and as such configurable as well:
|
102
|
+
|
103
|
+
$ rewritten-web -p 8282
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rewritten/rails/url_helpers'
|
data/lib/rewritten/version.rb
CHANGED
data/rewritten.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.add_development_dependency "rake"
|
26
26
|
s.add_development_dependency "minitest"
|
27
27
|
s.add_development_dependency "pry"
|
28
|
+
s.add_development_dependency "coveralls"
|
28
29
|
|
29
30
|
s.description = <<description
|
30
31
|
Rewritten is a lookup-based rewriting engine that rewrites requested
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rewritten
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kai Rubarth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-namespace
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: coveralls
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: |2
|
112
126
|
Rewritten is a lookup-based rewriting engine that rewrites requested
|
113
127
|
URLs on the fly. The URL manipulations depend on translations found in
|
@@ -137,7 +151,7 @@ files:
|
|
137
151
|
- .gitignore
|
138
152
|
- Gemfile
|
139
153
|
- HISTORY.rdoc
|
140
|
-
- README.
|
154
|
+
- README.md
|
141
155
|
- Rakefile
|
142
156
|
- bin/rewritten-dump.rb
|
143
157
|
- bin/rewritten-import.rb
|
@@ -151,6 +165,8 @@ files:
|
|
151
165
|
- lib/rewritten.rb
|
152
166
|
- lib/rewritten/config.ru
|
153
167
|
- lib/rewritten/helpers.rb
|
168
|
+
- lib/rewritten/rails.rb
|
169
|
+
- lib/rewritten/rails/url_helpers.rb
|
154
170
|
- lib/rewritten/server.rb
|
155
171
|
- lib/rewritten/server/public/favicon.ico
|
156
172
|
- lib/rewritten/server/public/idle.png
|
data/README.rdoc
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
= Rewritten
|
2
|
-
|
3
|
-
Rewritten is a lookup-based rewriting engine that rewrites requested
|
4
|
-
URLs on the fly. The URL manipulations depend on translations found in
|
5
|
-
a redis database.
|
6
|
-
|
7
|
-
If a matching translation is found, the result of a request is either a
|
8
|
-
redirection or a modification of path and request parameters. For URLs
|
9
|
-
without translation entries the request is left unmodified.
|
10
|
-
|
11
|
-
Rewritten takes larges parts from the Resque codebase (which rocks). The
|
12
|
-
gem is compromised of six parts:
|
13
|
-
|
14
|
-
1. A Ruby library for creating, modifying and querying translations
|
15
|
-
2. A Sinatra app for displaying and managing translations
|
16
|
-
3. A Rack app for identifying subdomains (Rack::Rewritten::Subdomain)
|
17
|
-
4. A Rack app for rewriting and redirecting request (Rack::Rewritten::Url)
|
18
|
-
5. A Rack app for substituting URLs in HTML pages with their current translation (Rack::Rewritten::Html)
|
19
|
-
6. A Rack app for recording requests (Rack::Rewritten::Record)
|
20
|
-
|
21
|
-
|
22
|
-
== New Relic Notice
|
23
|
-
|
24
|
-
There seem to be unresolved issues when Rack::Rewritten::Html is used
|
25
|
-
in conjunction with the New Relic gem (being a rack app as well).
|
26
|
-
Unfortunately the only workaround so far is either disabling New Relic
|
27
|
-
or Rack::Rewritten::Html (pointers in the right debugging direction or
|
28
|
-
pull requests are welcome).
|
29
|
-
|
30
|
-
|
31
|
-
== Overview
|
32
|
-
|
33
|
-
The Rewritten library allows you to create new URL translations and
|
34
|
-
then query for the current "trade language" of an URL.
|
35
|
-
|
36
|
-
Rewritten.add_translation('/apple-computer/newton', '/products/4e4d3c6a1d41c811e8000009')
|
37
|
-
Rewritten.add_translation('/apple/ipad', '/products/4e4d3c6a1d41c811e8000009')
|
38
|
-
Rewritten.get_current_translation('/products/4e4d3c6a1d41c811e8000009') # => "/apple/ipad"
|
39
|
-
|
40
|
-
Translations are removed in a similar fashion.
|
41
|
-
|
42
|
-
Rewritten.remove_translation('/apple-computer/newton', '/products/4e4d3c6a1d41c811e8000009')
|
43
|
-
|
44
|
-
|
45
|
-
== Usage in your Rack stack
|
46
|
-
|
47
|
-
To take full advantage of the engine you would be using at least
|
48
|
-
the following stack:
|
49
|
-
|
50
|
-
use Rack::Rewritten::Subdomain, "example.com", "lvh.me" # only needed for subdomain support
|
51
|
-
use Rack::Rewritten::Url
|
52
|
-
use Rack::Rewritten::Html
|
53
|
-
run Your::App
|
54
|
-
|
55
|
-
This way the URL rewriting and generation is stays decoupled from your
|
56
|
-
app. For a Rails app, for instance, you wouldn't need to mess with your
|
57
|
-
<tt>routes.rb</tt> or path helpers when dealing with custom URLs.
|
58
|
-
|
59
|
-
|
60
|
-
== The Front End
|
61
|
-
|
62
|
-
Rewritten comes with a Sinatra-based front end for dislaying and
|
63
|
-
managing your URL translations (in the familiar Resque layout).
|
64
|
-
|
65
|
-
[IMAGE]
|
66
|
-
|
67
|
-
|
68
|
-
=== Standalone
|
69
|
-
|
70
|
-
Running Rewritten as a gem in standalone mode is easy:
|
71
|
-
|
72
|
-
$ rewritten-web
|
73
|
-
|
74
|
-
It's based on Vegas, a thin layer around rackup, and as such configurable as well:
|
75
|
-
|
76
|
-
$ rewritten-web -p 8282
|
77
|
-
|
78
|
-
|
79
|
-
=== Rack::URLMap
|
80
|
-
|
81
|
-
To load Rewritten on a subpath alongside other apps you can make use of URLMap:
|
82
|
-
|
83
|
-
run Rack::URLMap.new \
|
84
|
-
"/" => Your::App.new,
|
85
|
-
"/resque" => Rewritten::Server.new
|
86
|
-
|
87
|
-
Check lib/test.ru for a functional example.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|