laserlemon-router_bits 0.1.0
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/MIT-LICENSE +20 -0
- data/Manifest +10 -0
- data/README.rdoc +28 -0
- data/Rakefile +14 -0
- data/VERSION.yml +4 -0
- data/init.rb +1 -0
- data/lib/router_bits.rb +26 -0
- data/router_bits.gemspec +32 -0
- data/test/router_bits_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +69 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Steve Richert
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
= router_bits
|
2
|
+
|
3
|
+
<tt>router_bits</tt> extends Rails routing conditions beyond the request's method. Conditions are created for commonly used attributes of <tt>ActionController::AbstractRequest</tt> such as: <tt>host</tt>, <tt>domain</tt>, <tt>subdomains</tt> and <tt>xhr?</tt>.
|
4
|
+
|
5
|
+
== Example
|
6
|
+
|
7
|
+
Conditionally route requests based on domain name:
|
8
|
+
|
9
|
+
map.with_options :controller => 'example', :conditions => {:domain => 'example.com'} do |map|
|
10
|
+
map.root
|
11
|
+
end
|
12
|
+
|
13
|
+
map.with_options :controller => 'sample', :conditions => {:domain => 'sample.com'} do |map|
|
14
|
+
map.root
|
15
|
+
end
|
16
|
+
|
17
|
+
Differentiate Ajax and non-Ajax requests:
|
18
|
+
|
19
|
+
map.with_options :controller => 'users' do |map|
|
20
|
+
map.profile 'user/:id', :action => 'profile', :conditions => {:xhr => false}
|
21
|
+
map.mini_profile 'user/:id', :action => 'mini_profile', :conditions => {:xhr => true}
|
22
|
+
end
|
23
|
+
|
24
|
+
== Tips
|
25
|
+
|
26
|
+
* Only extends routing conditions; not used in URL generation
|
27
|
+
* Although often equivalent, <tt>host</tt> and <tt>domain</tt> represent two separate pieces of information. For a request to www.sub.domain.com the value for <tt>host</tt> is <tt>"www.sub.domain.com"</tt> while the value for <tt>domain</tt> is <tt>"domain.com"</tt>.
|
28
|
+
* The value for <tt>subdomains</tt> always returns an array. In the above case, <tt>subdomains</tt> would be <tt>["www", "sub"]</tt>.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('router_bits', '0.1.0') do |g|
|
6
|
+
g.description = %(Extend Rails routing conditions)
|
7
|
+
g.url = 'http://github.com/laserlemon/router_bits'
|
8
|
+
g.author = 'Steve Richert'
|
9
|
+
g.email = 'steve@laserlemon.com'
|
10
|
+
g.ignore_pattern = %w(tmp/* script/*)
|
11
|
+
g.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each{|t| load t }
|
data/VERSION.yml
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'router_bits'
|
data/lib/router_bits.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module LaserLemon
|
2
|
+
module RouterBits
|
3
|
+
module RouteSet
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval { alias_method_chain :extract_request_environment, :router_bits }
|
6
|
+
end
|
7
|
+
|
8
|
+
def extract_request_environment_with_router_bits(request)
|
9
|
+
extract_request_environment_without_router_bits(request).merge(:host => request.host, :domain => request.domain, :subdomains => request.subdomains, :xhr => request.xhr?)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Route
|
14
|
+
def self.included(base)
|
15
|
+
base.class_eval { alias_method_chain :recognition_conditions, :router_bits }
|
16
|
+
end
|
17
|
+
|
18
|
+
def recognition_conditions_with_router_bits
|
19
|
+
recognition_conditions_without_router_bits + [:host, :domain, :subdomains, :xhr].delete_if{|c| conditions[c].nil? }.map{|c| "conditions[#{c.inspect}] === env[#{c.inspect}]" }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
ActionController::Routing::RouteSet.send(:include, LaserLemon::RouterBits::RouteSet)
|
26
|
+
ActionController::Routing::Route.send(:include, LaserLemon::RouterBits::Route)
|
data/router_bits.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{router_bits}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Steve Richert"]
|
9
|
+
s.date = %q{2009-04-28}
|
10
|
+
s.description = %q{Extend Rails routing conditions}
|
11
|
+
s.email = %q{steve@laserlemon.com}
|
12
|
+
s.extra_rdoc_files = ["lib/router_bits.rb", "README.rdoc"]
|
13
|
+
s.files = ["init.rb", "lib/router_bits.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README.rdoc", "router_bits.gemspec", "test/router_bits_test.rb", "test/test_helper.rb", "VERSION.yml"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/laserlemon/router_bits}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Router_bits", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{router_bits}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Extend Rails routing conditions}
|
21
|
+
s.test_files = ["test/router_bits_test.rb", "test/test_helper.rb"]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: laserlemon-router_bits
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Richert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-28 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Extend Rails routing conditions
|
17
|
+
email: steve@laserlemon.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- lib/router_bits.rb
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- init.rb
|
27
|
+
- lib/router_bits.rb
|
28
|
+
- Manifest
|
29
|
+
- MIT-LICENSE
|
30
|
+
- Rakefile
|
31
|
+
- README.rdoc
|
32
|
+
- router_bits.gemspec
|
33
|
+
- test/router_bits_test.rb
|
34
|
+
- test/test_helper.rb
|
35
|
+
- VERSION.yml
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/laserlemon/router_bits
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --line-numbers
|
41
|
+
- --inline-source
|
42
|
+
- --title
|
43
|
+
- Router_bits
|
44
|
+
- --main
|
45
|
+
- README.rdoc
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "1.2"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project: router_bits
|
63
|
+
rubygems_version: 1.2.0
|
64
|
+
signing_key:
|
65
|
+
specification_version: 2
|
66
|
+
summary: Extend Rails routing conditions
|
67
|
+
test_files:
|
68
|
+
- test/router_bits_test.rb
|
69
|
+
- test/test_helper.rb
|