routing-filter 0.0.1 → 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.
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routing-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Sven Fuchs
@@ -9,68 +15,89 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-08-26 09:00:00 +02:00
18
+ date: 2010-07-24 00:00:00 +02:00
13
19
  default_executable:
14
- dependencies: []
15
-
16
- description: routing-filter wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation.
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: actionpack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: test_declarative
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: Routing filters wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation.
17
50
  email: svenfuchs@artweb-design.de
18
51
  executables: []
19
52
 
20
53
  extensions: []
21
54
 
22
- extra_rdoc_files:
23
- - README.markdown
55
+ extra_rdoc_files: []
56
+
24
57
  files:
25
- - .gitignore
26
- - MIT-LICENSE
27
- - README.markdown
28
- - VERSION
29
- - init.rb
30
58
  - lib/routing_filter.rb
31
- - lib/routing_filter/base.rb
32
- - lib/routing_filter/force_extension.rb
33
- - lib/routing_filter/locale.rb
34
- - lib/routing_filter/pagination.rb
35
- - spec/force_extension_spec.rb
36
- - spec/generation_spec.rb
37
- - spec/pagination_extension_spec.rb
38
- - spec/recognition_spec.rb
39
- - spec/routing_filter_spec.rb
40
- - spec/spec.opts
41
- - spec/spec_helper.rb
42
- has_rdoc: false
59
+ - lib/routing_filter/adapters/rails_2.rb
60
+ - lib/routing_filter/adapters/rails_3.rb
61
+ - lib/routing_filter/chain.rb
62
+ - lib/routing_filter/filter.rb
63
+ - lib/routing_filter/filters/extension.rb
64
+ - lib/routing_filter/filters/locale.rb
65
+ - lib/routing_filter/filters/pagination.rb
66
+ - lib/routing_filter/filters/uuid.rb
67
+ - lib/routing_filter/version.rb
68
+ has_rdoc: true
43
69
  homepage: http://github.com/svenfuchs/routing-filter
44
70
  licenses: []
45
71
 
46
72
  post_install_message:
47
- rdoc_options:
48
- - --charset=UTF-8
73
+ rdoc_options: []
74
+
49
75
  require_paths:
50
76
  - lib
51
77
  required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
52
79
  requirements:
53
80
  - - ">="
54
81
  - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
55
85
  version: "0"
56
- version:
57
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
58
88
  requirements:
59
89
  - - ">="
60
90
  - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
61
94
  version: "0"
62
- version:
63
95
  requirements: []
64
96
 
65
- rubyforge_project:
66
- rubygems_version: 1.3.5
97
+ rubyforge_project: "[none]"
98
+ rubygems_version: 1.3.7
67
99
  signing_key:
68
100
  specification_version: 3
69
- summary: routing-filter wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation.
70
- test_files:
71
- - spec/force_extension_spec.rb
72
- - spec/generation_spec.rb
73
- - spec/pagination_extension_spec.rb
74
- - spec/recognition_spec.rb
75
- - spec/routing_filter_spec.rb
76
- - spec/spec_helper.rb
101
+ summary: Routing filters wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation
102
+ test_files: []
103
+
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- vendor
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2008 Sven Fuchs
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/README.markdown DELETED
@@ -1,123 +0,0 @@
1
- ## Routing Filter
2
-
3
- This plugin is a wild hack that wraps around the complex beast that the Rails
4
- routing system is to allow for unseen flexibility and power in Rails URL
5
- recognition and generation.
6
-
7
- As powerful and awesome the Rails' routes are, when you need to design your
8
- URLs in a manner that only slightly leaves the paved cowpaths of Rails
9
- conventions, you're usually unable to use all the goodness of helpers and
10
- convenience that Rails ships with.
11
-
12
- ## Usage
13
-
14
- This plugin comes with a locale routing filter that demonstrates the
15
- implementation of a custom filter.
16
-
17
- The following would be a sceleton of an empty filter:
18
-
19
- module RoutingFilter
20
- class Awesomeness < Base
21
- def around_recognize(route, path, env)
22
- # Alter the path here before it gets recognized.
23
- # Make sure to yield (calls the next around filter if present and
24
- # eventually `recognize_path` on the routeset):
25
- returning yield do |params|
26
- # You can additionally modify the params here before they get passed
27
- # to the controller.
28
- end
29
- end
30
-
31
- def around_generate(controller, *args, &block)
32
- # Alter arguments here before they are passed to `url_for`.
33
- # Make sure to yield (calls the next around filter if present and
34
- # eventually `url_for` on the controller):
35
- returning yield do |result|
36
- # You can change the generated url_or_path here. Make sure to use
37
- # one of the "in-place" modifying String methods though (like sub!
38
- # and friends).
39
- end
40
- end
41
- end
42
- end
43
-
44
- You then have to specify the filter explicitely in your routes.rb:
45
-
46
- ActionController::Routing::Routes.draw do |map|
47
- map.filter 'awesomeness'
48
- end
49
-
50
- (I am not sure if it makes sense to provide more technical information than
51
- this because the usage of this plugin definitely requires some advanced
52
- knowledge about Rails internals and especially its routing system. So, I
53
- figure, anyone who could use this should also be able to read the code and
54
- figure out what it's doing much better then from any lengthy documentation.
55
-
56
- If I'm mistaken on this please drop me an email with your suggestions.)
57
-
58
-
59
- ## Rationale: Two example usecases
60
-
61
- An early usecase from which this originated was the need to define a locale
62
- at the beginning of an URL in a way so that
63
-
64
- * the locale can be omitted when it is the default locale
65
- * all the url\_helpers that are generated by named routes continue to work in
66
- a concise manner (i.e. without specifying all parameters again and again)
67
- * ideally also plays nicely with default route helpers in tests/specs
68
-
69
- You can read about this struggle and two possible, yet unsatisfying solutions
70
- [here](http://www.artweb-design.de/2007/5/13/concise-localized-rails-url-helpers-solved-twice).
71
- The conclusion so far is that Rails itself does not provide the tools to solve
72
- this problem in a clean and dry way.
73
-
74
- Another usecase that eventually spawned the manifestation of this plugin was
75
- the need to map an arbitrary count of path segments to a certain model
76
- instance. In an application that I've been working on recently I needed to
77
- map URL paths to a nested tree of models like so:
78
-
79
- root
80
- + docs
81
- + api
82
- + wiki
83
-
84
- E.g. the docs section should map to the path `/docs`, the api section to
85
- the path `/docs/api` and so on. Furthermore, after these paths there need to be
86
- more things to be specified. E.g. the wiki needs to define a whole Rails
87
- resource with URLs like `/docs/wiki/pages/1/edit`.
88
-
89
- The only way to solve this problem with Rails' routing toolkit is to map
90
- a big, bold `/*everything` catch-all ("globbing") route and process the whole
91
- path in a custom dispatcher.
92
-
93
- This, of course, is a really unsatisfying solution because one has to
94
- reimplement everything that Rails routes are here to help with: regarding both
95
- URL recognition (like parameter mappings, resources, ...) and generation
96
- (url\_helpers).
97
-
98
- ## Solution
99
-
100
- This plugin offers a solution that takes exactly the opposite route.
101
-
102
- Instead of trying to change things *between* the URL recognition and
103
- generation stages to achieve the desired result it *wraps around* the whole
104
- routing system and allows to pre- and post-filter both what goes into it
105
- (URL recognition) and what comes out of it (URL generation).
106
-
107
- This way we can leave *everything* else completely untouched.
108
-
109
- * We can tinker with the URLs that we receive from the server and feed URLs to
110
- Rails that perfectly match the best breed of Rails' conventions.
111
- * Inside of the application we can use all the nice helper goodness and
112
- conveniences that rely on these conventions being followed.
113
- * Finally we can accept URLs that have been generated by the url\_helpers and,
114
- again, mutate them in the way that matches our requirements.
115
-
116
- So, even though the plugin itself is a blatant monkey-patch to one of the
117
- most complex area of Rails internals, this solution seems to be effectively
118
- less intrusive and pricey than others are.
119
-
120
- ## Etc
121
-
122
- Authors: [Sven Fuchs](http://www.artweb-design.de) <svenfuchs at artweb-design dot de>
123
- License: MIT
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.2
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'routing_filter'
@@ -1,31 +0,0 @@
1
- module RoutingFilter
2
- class Base
3
- class_inheritable_accessor :active
4
- self.active = true
5
-
6
- attr_accessor :chain, :options
7
-
8
- def initialize(options = {})
9
- @options = options
10
- options.each { |name, value| instance_variable_set :"@#{name}", value }
11
- end
12
-
13
- def run(method, *args, &block)
14
- _next = successor ? lambda { successor.run(method, *args, &block) } : block
15
- active ? send(method, *args, &_next) : _next.call(*args)
16
- end
17
-
18
- def run_reverse(method, *args, &block)
19
- _prev = predecessor ? lambda { predecessor.run(method, *args, &block) } : block
20
- active ? send(method, *args, &_prev) : _prev.call(*args)
21
- end
22
-
23
- def predecessor
24
- @chain.predecessor(self)
25
- end
26
-
27
- def successor
28
- @chain.successor(self)
29
- end
30
- end
31
- end
@@ -1,33 +0,0 @@
1
- require 'routing_filter/base'
2
-
3
- module RoutingFilter
4
- class Pagination < Base
5
- def around_recognize(path, env, &block)
6
- page = extract_page!(path)
7
- returning yield(path, env) do |params|
8
- params[:page] = page.to_i if page
9
- end
10
- end
11
-
12
- def around_generate(*args, &block)
13
- page = args.extract_options!.delete(:page)
14
- returning yield do |result|
15
- if page && page != 1
16
- url = result.is_a?(Array) ? result.first : result
17
- append_page!(url, page)
18
- end
19
- end
20
- end
21
-
22
- protected
23
-
24
- def extract_page!(path)
25
- path.sub! %r(/pages/([\d]+)/?$), ''
26
- $1
27
- end
28
-
29
- def append_page!(url, page)
30
- url.sub!(/($|\?)/) { "/pages/#{page}#{$1}" }
31
- end
32
- end
33
- end
@@ -1,65 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- describe 'RoutingFilter::ForceExtension' do
4
- include RoutingFilterHelpers
5
-
6
- before :each do
7
- setup_environment(:force_extension)
8
- end
9
-
10
- describe 'url recognition' do
11
- it 'recognizes the path /sections/1.html' do
12
- should_recognize_path '/sections/1.html', @section_params
13
- end
14
-
15
- it 'recognizes the path /sections/1/articles/1.html' do
16
- should_recognize_path '/sections/1/articles/1.html', @article_params
17
- end
18
-
19
- it 'does not recognize the path /sections/1/articles/1.foobar' do
20
- lambda { @set.recognize_path('/sections/1/articles/1.foobar', {}) }.should raise_error(ActionController::RoutingError)
21
- end
22
- end
23
-
24
- describe 'url generation' do
25
- it 'appends the .html extension to generated paths (section_path)' do
26
- section_path(:id => 1).should == '/sections/1.html'
27
- end
28
-
29
- it 'appends the .html extension to generated paths (section_article_path)' do
30
- section_article_path(:section_id => 1, :id => 1).should == '/sections/1/articles/1.html'
31
- end
32
-
33
- it 'appends the .html extension to generated paths (admin_articles_path)' do
34
- admin_articles_path.should == '/admin/articles.html'
35
- end
36
-
37
- it 'does not replace or add on an existing extension' do
38
- section_path(:id => 1, :format => 'xml').should == '/sections/1.xml'
39
- end
40
-
41
- it 'works with url query params' do
42
- section_path(:id => 1, :foo => 'bar').should == '/sections/1.html?foo=bar'
43
- end
44
-
45
- it 'excludes / by default' do
46
- home_path.should == '/'
47
- end
48
-
49
- it 'excludes http://test.host/ by default' do
50
- home_url.should == 'http://test.host/'
51
- end
52
-
53
- it 'excludes with custom regexp' do
54
- setup_environment { |map| map.filter :force_extension, :exclude => %r(^/(admin|$)) }
55
- home_path.should == '/'
56
- admin_articles_path.should == '/admin/articles'
57
- section_path(:id => 1).should == '/sections/1.html'
58
- end
59
-
60
- it 'does not exclude / when :exclude => false was passed' do
61
- setup_environment { |map| map.filter :force_extension, :exclude => false }
62
- home_path.should == '/.html'
63
- end
64
- end
65
- end