Bill-route_name_for 0.0.1 → 0.0.2
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.
- data/History.txt +5 -0
- data/Manifest.txt +3 -0
- data/README.txt +60 -26
- data/lib/init.rb +1 -0
- data/lib/rails/init.rb +7 -0
- data/lib/route_name_for/version.rb +1 -1
- data/lib/route_name_for.rb +48 -15
- data/route_name_for.gemspec +36 -0
- data/website/index.html +141 -11
- metadata +9 -6
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.0.2 2008-08-28
|
2
|
+
|
3
|
+
* 1 major enhancement:
|
4
|
+
* route_name_for now takes request.request_uri and (empty) environment hash, instead of :controller, :action. It was wrong to ever take :controller, :action since that combination is often ambiguous.
|
5
|
+
|
1
6
|
== 0.0.1 2008-08-21
|
2
7
|
|
3
8
|
* 1 major enhancement:
|
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -4,45 +4,79 @@ http://thoughtpropulsion.com
|
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
|
-
|
7
|
+
Rails helper to look up (named) route name given current request URI. Adds route_name_for method to controllers and views.
|
8
8
|
|
9
9
|
== FEATURES/PROBLEMS:
|
10
10
|
|
11
|
-
|
11
|
+
It only finds named routes of course, so sometimes it'll return nothing (if you give a path for which there)
|
12
|
+
is no named route.
|
12
13
|
|
13
14
|
== SYNOPSIS:
|
14
15
|
|
15
|
-
|
16
|
+
If you have routes like this:
|
16
17
|
|
17
|
-
|
18
|
+
map.home '', :controller => 'home'
|
19
|
+
map.login 'login', :controller => 'home'
|
18
20
|
|
19
|
-
|
21
|
+
You might like to define this helper in your ApplicationController:
|
20
22
|
|
21
|
-
|
23
|
+
def body_class
|
24
|
+
route_name_for request.request_uri, {}
|
25
|
+
end
|
22
26
|
|
23
|
-
|
27
|
+
And then call it from your application layout like this:
|
24
28
|
|
25
|
-
|
29
|
+
<body class='<%=body_class%>'>
|
30
|
+
|
31
|
+
So that when you browse to '/login', your page will have:
|
32
|
+
|
33
|
+
<body class='login'>…
|
34
|
+
|
35
|
+
And when you you browse to '' or '/', your page will have:
|
36
|
+
|
37
|
+
<body class='home'>…
|
38
|
+
|
39
|
+
Then you can match that in your CSS rules with a selector like this:
|
26
40
|
|
27
|
-
|
41
|
+
body.login … { … }
|
28
42
|
|
29
|
-
|
43
|
+
== REQUIREMENTS:
|
44
|
+
|
45
|
+
Rails 2.1.0 or later.
|
30
46
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
-
permit persons to whom the Software is furnished to do so, subject to
|
37
|
-
the following conditions:
|
47
|
+
Also note: this code is highly dependent upon Rails' implementation of the ActionController::Routing::RouteSet implementation. In particular, the optimization to that class found in recognition_optimisation.rb (sic). The upside of this tight coupling is that this add-on performs as well as Rails native routing. The downside is that Rails may (will) change and this RubyGem will have to track those changes.
|
48
|
+
|
49
|
+
== INSTALL:
|
38
50
|
|
39
|
-
|
40
|
-
|
51
|
+
sudo gem install Bill-route_name_for
|
52
|
+
|
53
|
+
See also http://gems.github.com/
|
54
|
+
|
55
|
+
== LICENSE:
|
41
56
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
57
|
+
(The BSD License)
|
58
|
+
|
59
|
+
* Copyright (c) 2008, Thought Propulsion
|
60
|
+
* All rights reserved.
|
61
|
+
*
|
62
|
+
* Redistribution and use in source and binary forms, with or without
|
63
|
+
* modification, are permitted provided that the following conditions are met:
|
64
|
+
* * Redistributions of source code must retain the above copyright
|
65
|
+
* notice, this list of conditions and the following disclaimer.
|
66
|
+
* * Redistributions in binary form must reproduce the above copyright
|
67
|
+
* notice, this list of conditions and the following disclaimer in the
|
68
|
+
* documentation and/or other materials provided with the distribution.
|
69
|
+
* * Neither the name of the Thought Propulsion nor the
|
70
|
+
* names of its contributors may be used to endorse or promote products
|
71
|
+
* derived from this software without specific prior written permission.
|
72
|
+
*
|
73
|
+
* THIS SOFTWARE IS PROVIDED BY Thought Propulsion ''AS IS'' AND ANY
|
74
|
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
75
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
76
|
+
* DISCLAIMED. IN NO EVENT SHALL Thought Propulsion BE LIABLE FOR ANY
|
77
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
78
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
79
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
80
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
81
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
82
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/lib/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init"
|
data/lib/rails/init.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
[ActionController::Routing::RouteSet].each do |c|
|
2
|
+
c.send( :include, RouteNameFor::RouteSetMethods)
|
3
|
+
end
|
4
|
+
# Optional, but recommended for Rails
|
5
|
+
ActionController::Base.send(:include, RouteNameFor::Helpers)
|
6
|
+
# Include this module into views, too.
|
7
|
+
ActionController::Base.helper(RouteNameFor::Helpers)
|
data/lib/route_name_for.rb
CHANGED
@@ -2,22 +2,55 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module RouteNameFor
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
|
6
|
+
module RouteSetMethods
|
7
|
+
def recognized_route( path, env)
|
8
|
+
recognized_route_optimized( path, env)
|
9
|
+
end
|
10
|
+
|
11
|
+
def recognized_route_optimized( path, env)
|
12
|
+
write_recognized_route_optimized( path, env)
|
13
|
+
recognized_route_optimized(path, env)
|
14
|
+
end
|
15
|
+
|
16
|
+
def write_recognized_route_optimized( path, env)
|
17
|
+
# This does a reverse-lookup to find the named route (name) from the current
|
18
|
+
# controller and action. The is preferrable to just munging the controller name since often
|
19
|
+
# your named routes (names) evolve somewhat independently of your controller names over time.
|
20
|
+
# See write_recognize_optimized in Rails' recognition_optimisation.rb (sic) (that's where I stole)
|
21
|
+
# this code from. It's important to steal this optimized (dynamically-compiled) code lest
|
22
|
+
# we defeat the Rails optimization.
|
23
|
+
|
24
|
+
tree = segment_tree(routes)
|
25
|
+
body = generate_code(tree)
|
26
|
+
instance_eval %{
|
27
|
+
def recognized_route_optimized(path, env)
|
28
|
+
segments = to_plain_segments(path)
|
29
|
+
index = #{body}
|
30
|
+
return nil unless index
|
31
|
+
while index < routes.size
|
32
|
+
routes[index].recognize(path, env) and return routes[index]
|
33
|
+
index += 1
|
34
|
+
end
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
}, __FILE__, __LINE__
|
13
38
|
end
|
14
|
-
(found && found[0]) || ''
|
15
39
|
end
|
40
|
+
|
41
|
+
module Helpers
|
42
|
+
def route_name_for( path, env)
|
43
|
+
r = ActionController::Routing::Routes.recognized_route( path, {})
|
44
|
+
ActionController::Routing::Routes.named_routes.routes.invert[r].to_s
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
16
48
|
end
|
17
49
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
50
|
+
[ActionController::Routing::RouteSet].each do |c|
|
51
|
+
c.send( :include, RouteNameFor::RouteSetMethods)
|
52
|
+
end
|
53
|
+
# Optional, but recommended for Rails
|
54
|
+
ActionController::Base.send(:include, RouteNameFor::Helpers)
|
55
|
+
# Include this module into views, too.
|
56
|
+
ActionController::Base.helper(RouteNameFor::Helpers)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{route_name_for}
|
3
|
+
s.version = "0.0.2"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Bill Burcham"]
|
7
|
+
s.date = %q{2008-08-28}
|
8
|
+
s.description = %q{Rails helper to look up (named) route name given current request URI. Adds route_name_for method to controllers and views.}
|
9
|
+
s.email = ["propeller@thoughtpropulsion.com"]
|
10
|
+
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "website/index.txt"]
|
11
|
+
s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "lib/init.rb", "lib/rails/init.rb", "lib/route_name_for.rb", "lib/route_name_for/version.rb", "route_name_for.gemspec", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/test_helper.rb", "test/test_route_name_for.rb", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.html.erb"]
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.homepage = %q{http://github.com/Bill/route_name_for/tree/master}
|
14
|
+
s.post_install_message = %q{
|
15
|
+
For more information on route_name_for, see http://github.com/Bill/route_name_for/tree/master
|
16
|
+
}
|
17
|
+
s.rdoc_options = ["--main", "README.txt"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{route_name_for}
|
20
|
+
s.rubygems_version = %q{1.2.0}
|
21
|
+
s.summary = %q{description of gem}
|
22
|
+
s.test_files = ["test/test_helper.rb", "test/test_route_name_for.rb"]
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
+
s.specification_version = 2
|
27
|
+
|
28
|
+
if current_version >= 3 then
|
29
|
+
s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<hoe>, [">= 1.7.0"])
|
32
|
+
end
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<hoe>, [">= 1.7.0"])
|
35
|
+
end
|
36
|
+
end
|
data/website/index.html
CHANGED
@@ -1,11 +1,141 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
+
<title>
|
8
|
+
route_name_for
|
9
|
+
</title>
|
10
|
+
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
|
+
<style>
|
12
|
+
|
13
|
+
</style>
|
14
|
+
<script type="text/javascript">
|
15
|
+
window.onload = function() {
|
16
|
+
settings = {
|
17
|
+
tl: { radius: 10 },
|
18
|
+
tr: { radius: 10 },
|
19
|
+
bl: { radius: 10 },
|
20
|
+
br: { radius: 10 },
|
21
|
+
antiAlias: true,
|
22
|
+
autoPad: true,
|
23
|
+
validTags: ["div"]
|
24
|
+
}
|
25
|
+
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
26
|
+
versionBox.applyCornersToAll();
|
27
|
+
}
|
28
|
+
</script>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="main">
|
32
|
+
|
33
|
+
<h1>route_name_for</h1>
|
34
|
+
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/route_name_for"; return false'>
|
35
|
+
<p>Get Version</p>
|
36
|
+
<a href="http://rubyforge.org/projects/route_name_for" class="numbers">0.0.2</a>
|
37
|
+
</div>
|
38
|
+
<h1>→ ‘route_name_for’</h1>
|
39
|
+
|
40
|
+
|
41
|
+
<h2>What</h2>
|
42
|
+
|
43
|
+
|
44
|
+
<h2>Installing</h2>
|
45
|
+
|
46
|
+
|
47
|
+
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">route_name_for</span></pre></p>
|
48
|
+
|
49
|
+
|
50
|
+
<h2>The basics</h2>
|
51
|
+
|
52
|
+
|
53
|
+
<h2>Demonstration of usage</h2>
|
54
|
+
|
55
|
+
|
56
|
+
<h2>Forum</h2>
|
57
|
+
|
58
|
+
|
59
|
+
<p><a href="http://groups.google.com/group/route_name_for">http://groups.google.com/group/route_name_for</a></p>
|
60
|
+
|
61
|
+
|
62
|
+
<p><span class="caps">TODO</span> – create Google Group – route_name_for</p>
|
63
|
+
|
64
|
+
|
65
|
+
<h2>How to submit patches</h2>
|
66
|
+
|
67
|
+
|
68
|
+
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
|
69
|
+
|
70
|
+
|
71
|
+
<p><span class="caps">TODO</span> – pick <span class="caps">SVN</span> or Git instructions</p>
|
72
|
+
|
73
|
+
|
74
|
+
<p>The trunk repository is <code>svn://rubyforge.org/var/svn/route_name_for/trunk</code> for anonymous access.</p>
|
75
|
+
|
76
|
+
|
77
|
+
<p><span class="caps">OOOORRRR</span></p>
|
78
|
+
|
79
|
+
|
80
|
+
<p>You can fetch the source from either:</p>
|
81
|
+
|
82
|
+
|
83
|
+
<ul>
|
84
|
+
<li>rubyforge: <span class="caps">MISSING IN ACTION</span></li>
|
85
|
+
</ul>
|
86
|
+
|
87
|
+
|
88
|
+
<p><span class="caps">TODO</span> – You can not created a RubyForge project, OR have not run <code>rubyforge config</code>
|
89
|
+
yet to refresh your local rubyforge data with this projects’ id information.</p>
|
90
|
+
|
91
|
+
|
92
|
+
<p>When you do this, this message will magically disappear!</p>
|
93
|
+
|
94
|
+
|
95
|
+
<p>Or you can hack website/index.txt and make it all go away!!</p>
|
96
|
+
|
97
|
+
|
98
|
+
<ul>
|
99
|
+
<li>github: <a href="http://github.com/GITHUB_USERNAME/route_name_for/tree/master">http://github.com/GITHUB_USERNAME/route_name_for/tree/master</a></li>
|
100
|
+
</ul>
|
101
|
+
|
102
|
+
|
103
|
+
<pre>git clone git://github.com/GITHUB_USERNAME/route_name_for.git</pre>
|
104
|
+
|
105
|
+
<p><span class="caps">TODO</span> – add “github_username: username” to ~/.rubyforge/user-config.yml and newgem will reuse it for future projects.</p>
|
106
|
+
|
107
|
+
|
108
|
+
<ul>
|
109
|
+
<li>gitorious: <a href="git://gitorious.org/route_name_for/mainline.git">git://gitorious.org/route_name_for/mainline.git</a></li>
|
110
|
+
</ul>
|
111
|
+
|
112
|
+
|
113
|
+
<pre>git clone git://gitorious.org/route_name_for/mainline.git</pre>
|
114
|
+
|
115
|
+
<h3>Build and test instructions</h3>
|
116
|
+
|
117
|
+
|
118
|
+
<pre>cd route_name_for
|
119
|
+
rake test
|
120
|
+
rake install_gem</pre>
|
121
|
+
|
122
|
+
<h2>License</h2>
|
123
|
+
|
124
|
+
|
125
|
+
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
126
|
+
|
127
|
+
|
128
|
+
<h2>Contact</h2>
|
129
|
+
|
130
|
+
|
131
|
+
<p>Comments are welcome. Send an email to <a href="mailto:FIXME"><span class="caps">FIXME</span> full name</a> email via the <a href="http://groups.google.com/group/route_name_for">forum</a></p>
|
132
|
+
<p class="coda">
|
133
|
+
<a href="FIXME email">FIXME full name</a>, 21st August 2008<br>
|
134
|
+
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
135
|
+
</p>
|
136
|
+
</div>
|
137
|
+
|
138
|
+
<!-- insert site tracking codes here, like Google Urchin -->
|
139
|
+
|
140
|
+
</body>
|
141
|
+
</html>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Bill-route_name_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Burcham
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-08-
|
12
|
+
date: 2008-08-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 1.7.0
|
23
23
|
version:
|
24
|
-
description:
|
24
|
+
description: Rails helper to look up (named) route name given current request URI. Adds route_name_for method to controllers and views.
|
25
25
|
email:
|
26
26
|
- propeller@thoughtpropulsion.com
|
27
27
|
executables: []
|
@@ -44,8 +44,11 @@ files:
|
|
44
44
|
- Rakefile
|
45
45
|
- config/hoe.rb
|
46
46
|
- config/requirements.rb
|
47
|
+
- lib/init.rb
|
48
|
+
- lib/rails/init.rb
|
47
49
|
- lib/route_name_for.rb
|
48
50
|
- lib/route_name_for/version.rb
|
51
|
+
- route_name_for.gemspec
|
49
52
|
- script/console
|
50
53
|
- script/destroy
|
51
54
|
- script/generate
|
@@ -62,10 +65,10 @@ files:
|
|
62
65
|
- website/stylesheets/screen.css
|
63
66
|
- website/template.html.erb
|
64
67
|
has_rdoc: true
|
65
|
-
homepage: http://
|
68
|
+
homepage: http://github.com/Bill/route_name_for/tree/master
|
66
69
|
post_install_message: |
|
67
70
|
|
68
|
-
For more information on route_name_for, see http://
|
71
|
+
For more information on route_name_for, see http://github.com/Bill/route_name_for/tree/master
|
69
72
|
|
70
73
|
rdoc_options:
|
71
74
|
- --main
|
@@ -90,7 +93,7 @@ rubyforge_project: route_name_for
|
|
90
93
|
rubygems_version: 1.2.0
|
91
94
|
signing_key:
|
92
95
|
specification_version: 2
|
93
|
-
summary:
|
96
|
+
summary: description of gem
|
94
97
|
test_files:
|
95
98
|
- test/test_helper.rb
|
96
99
|
- test/test_route_name_for.rb
|