rack-rewrite-dynamic 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,8 @@ module Rack
|
|
23
23
|
def scoped_slug_type?(slug_name, slug_type, prev_slug)
|
24
24
|
association_name = slug_type.downcase.pluralize
|
25
25
|
prev_slug.sluggable.send(association_name).find(slug_name) if prev_slug
|
26
|
+
rescue
|
27
|
+
nil
|
26
28
|
end
|
27
29
|
def find_sluggable(friendly_id)
|
28
30
|
slug_klass.find(friendly_id)
|
@@ -41,9 +43,9 @@ module Rack
|
|
41
43
|
def route_generator_klass
|
42
44
|
@route_generator_klass ||= @opts[:route_generator_name].constantize
|
43
45
|
end
|
44
|
-
def slug_path_if_present(slug, rack_env)
|
46
|
+
def slug_path_if_present(slug, rack_env, opts={})
|
45
47
|
if slug
|
46
|
-
route_generator_klass.route_for slug
|
48
|
+
route_generator_klass.route_for slug, opts
|
47
49
|
else
|
48
50
|
original_path(rack_env)
|
49
51
|
end
|
@@ -27,9 +27,9 @@ module Rack
|
|
27
27
|
slugs.each do |s|
|
28
28
|
add_filter_param(filter_params, s)
|
29
29
|
end
|
30
|
-
return "/#{@opts[:target]}?#{filter_params.to_query}" if filter_params.length > 0
|
31
30
|
end
|
32
|
-
|
31
|
+
|
32
|
+
return "/#{@opts[:target]}?#{filter_params.to_query}" if filter_params.length > 0
|
33
33
|
end
|
34
34
|
original_path(rack_env)
|
35
35
|
end
|
@@ -2,11 +2,11 @@ module Rack
|
|
2
2
|
class Rewrite
|
3
3
|
module Dynamic
|
4
4
|
class RailsRouteGenerator
|
5
|
-
def self.route_for
|
5
|
+
def self.route_for(slug, opts={})
|
6
6
|
if slug.kind_of?(Slug)
|
7
|
-
Rails.application.routes.url_helpers.send("#{slug[:sluggable_type].underscore}_path", slug[:sluggable_id])
|
7
|
+
Rails.application.routes.url_helpers.send("#{slug[:sluggable_type].underscore}_path", slug[:sluggable_id], opts)
|
8
8
|
else
|
9
|
-
Rails.application.routes.url_helpers.send("#{slug.class.name.underscore}_path", slug.id)
|
9
|
+
Rails.application.routes.url_helpers.send("#{slug.class.name.underscore}_path", slug.id, opts)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -28,21 +28,29 @@ module Rack
|
|
28
28
|
scope_slug = nil
|
29
29
|
slugs = url_parts.each_with_index.map do |url_part, index|
|
30
30
|
if url_part[1] == 'slug'
|
31
|
-
scope_slug = slug_type?(match[index+1]
|
31
|
+
scope_slug = slug_type?(match[index+1], url_part[0])
|
32
32
|
elsif url_part[1] == 'scoped_slug'
|
33
|
-
scope_slug = scoped_slug_type?(match[index+1]
|
33
|
+
scope_slug = scoped_slug_type?(match[index+1], url_part[0], scope_slug)
|
34
34
|
else
|
35
35
|
'static'
|
36
36
|
end
|
37
37
|
end
|
38
|
+
slugs.reject!{|s| s == 'static'}
|
38
39
|
if !slugs.include?(nil)
|
39
|
-
slug_path_if_present(slugs[url_parts.length-1], rack_env)
|
40
|
+
slug_path_if_present(slugs[url_parts.reject{|k, v| v == 'static' }.length-1], rack_env, static: static_match(url_parts, match))
|
40
41
|
else
|
41
42
|
nil
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
46
|
private
|
47
|
+
def static_match(url_parts, match)
|
48
|
+
static_index = url_parts.values.index('static')
|
49
|
+
if static_index
|
50
|
+
match[static_index+1]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
46
54
|
def build_match_string
|
47
55
|
match_string = "^\/"
|
48
56
|
match_string << @opts[:url_parts].first.map do |url_value, url_type|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-rewrite-dynamic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack-rewrite
|