padrino-relative 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/padrino-relative.rb +93 -0
- metadata +62 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
# Copy/pasta from https://github.com/padrino/padrino-framework
|
2
|
+
# File is padrino-core/lib/padrino-core/application/routing.rb
|
3
|
+
# Modified based on https://github.com/kylewlacy/padrino-framework
|
4
|
+
module Padrino
|
5
|
+
module Routing
|
6
|
+
module ClassMethods
|
7
|
+
def parse_route(path, options, verb)
|
8
|
+
# We need save our originals path/options so we can perform correctly cache.
|
9
|
+
original = [path, options.dup]
|
10
|
+
|
11
|
+
# options for the route directly
|
12
|
+
route_options = {}
|
13
|
+
|
14
|
+
# We need check if path is a symbol, if that it's a named route
|
15
|
+
map = options.delete(:map)
|
16
|
+
|
17
|
+
relative_path = false
|
18
|
+
if map == :index
|
19
|
+
map = '/'
|
20
|
+
relative_path = true
|
21
|
+
end
|
22
|
+
|
23
|
+
if path.kind_of?(Symbol) # path i.e :index or :show
|
24
|
+
name = path # The route name
|
25
|
+
path = map ? map.dup : (path == :index ? '/' : path.to_s) # The route path
|
26
|
+
end
|
27
|
+
|
28
|
+
# Build our controller
|
29
|
+
controller = Array(@_controller).map { |c| c.to_s }
|
30
|
+
|
31
|
+
case path
|
32
|
+
when String # path i.e "/index" or "/show"
|
33
|
+
# Now we need to parse our 'with' params
|
34
|
+
if with_params = options.delete(:with)
|
35
|
+
path = process_path_for_with_params(path, with_params)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Now we need to parse our provides
|
39
|
+
options.delete(:provides) if options[:provides].nil?
|
40
|
+
|
41
|
+
if @_use_format or format_params = options[:provides]
|
42
|
+
process_path_for_provides(path, format_params)
|
43
|
+
options[:matching] ||= {}
|
44
|
+
options[:matching][:format] = /[^\.]+/
|
45
|
+
end
|
46
|
+
|
47
|
+
absolute_map = map && map[0] == ?/
|
48
|
+
|
49
|
+
unless controller.empty?
|
50
|
+
# Now we need to add our controller path only if not mapped directly
|
51
|
+
if !absolute_map or relative_path
|
52
|
+
controller_path = controller.join("/")
|
53
|
+
path.gsub!(%r{^\(/\)|/\?}, "")
|
54
|
+
path = File.join(controller_path, path)
|
55
|
+
end
|
56
|
+
# Here we build the correct name route
|
57
|
+
end
|
58
|
+
|
59
|
+
# Now we need to parse our 'parent' params and parent scope
|
60
|
+
if !absolute_map and parent_params = options.delete(:parent) || @_parents
|
61
|
+
parent_params = Array(@_parents) + Array(parent_params)
|
62
|
+
path = process_path_for_parent_params(path, parent_params)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Add any controller level map to the front of the path
|
66
|
+
path = "#{@_map}/#{path}".squeeze('/') unless absolute_map or @_map.blank?
|
67
|
+
|
68
|
+
# Small reformats
|
69
|
+
path.gsub!(%r{/\?$}, '(/)') # Remove index path
|
70
|
+
path.gsub!(%r{//$}, '/') # Remove index path
|
71
|
+
path[0,0] = "/" if path !~ %r{^\(?/} # Paths must start with a /
|
72
|
+
path.sub!(%r{/(\))?$}, '\\1') if path != "/" # Remove latest trailing delimiter
|
73
|
+
path.gsub!(/\/(\(\.|$)/, '\\1') # Remove trailing slashes
|
74
|
+
path.squeeze!('/')
|
75
|
+
when Regexp
|
76
|
+
route_options[:path_for_generation] = options.delete(:generate_with) if options.key?(:generate_with)
|
77
|
+
end
|
78
|
+
|
79
|
+
name = options.delete(:route_name) if name.nil? && options.key?(:route_name)
|
80
|
+
name = options.delete(:name) if name.nil? && options.key?(:name)
|
81
|
+
if name
|
82
|
+
controller_name = controller.join("_")
|
83
|
+
name = "#{controller_name}_#{name}".to_sym unless controller_name.blank?
|
84
|
+
end
|
85
|
+
|
86
|
+
# Merge in option defaults
|
87
|
+
options.reverse_merge!(:default_values => @_defaults)
|
88
|
+
|
89
|
+
[path, name, options, route_options]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: padrino-relative
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kyle Lacy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: padrino
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.7
|
30
|
+
description: Enables relative controller paths in Padrino (for DRYness)
|
31
|
+
email: kylelacy@me.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- lib/padrino-relative.rb
|
37
|
+
homepage: http://github.com/kylewlacy/timerizer
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.24
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Relative controller paths in Padrino
|
61
|
+
test_files: []
|
62
|
+
has_rdoc:
|