roda 3.30.0 → 3.31.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.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/doc/release_notes/3.31.0.txt +11 -0
- data/lib/roda/plugins/assets.rb +7 -4
- data/lib/roda/plugins/path.rb +21 -4
- data/lib/roda/plugins/relative_path.rb +73 -0
- data/lib/roda/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d6d28c0f8b5197ab3d2a74726150921a435ccdcd8f18c6eb2c9bbe4d1cb2a14
|
|
4
|
+
data.tar.gz: f1464284c0cb20638bc7575769271c6ea39642ff3b1842fad33b92759db915cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4fca0abe3d0072e0a3e7201a089fd708610933ce4d461496bb0c13cbf7d84d2d10010c4007c460953972070d782742dba4d88799fd608f3df1ef7cca58cecef1
|
|
7
|
+
data.tar.gz: 189a647f809aa732baebc225ea313c59e543d0d0935c8008a85084694161753e0939a7cac4c1f9d010e03785ec792d49b6c3e5643925066e1cda12d0b7701237
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
= 3.31.0 (2020-04-15)
|
|
2
|
+
|
|
3
|
+
* Add :relative option to path method in path plugin, for generating a method returning relative paths (jeremyevans)
|
|
4
|
+
|
|
5
|
+
* Add relative_path plugin, for turning absolute paths to paths relative to the current request (jeremyevans)
|
|
6
|
+
|
|
1
7
|
= 3.30.0 (2020-03-13)
|
|
2
8
|
|
|
3
9
|
* Support :relative_paths assets plugin option to use relative paths for the assets (jeremyevans)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
= New Features
|
|
2
|
+
|
|
3
|
+
* A relative_paths plugin has been added, adding a relative_path
|
|
4
|
+
method that will take an absolute path and make it relative to the
|
|
5
|
+
current request by prepending an appropriate prefix. This is
|
|
6
|
+
helpful when using Roda as a static site generator to generate a
|
|
7
|
+
site that can be hosted at any subpath or directly from the
|
|
8
|
+
filesystem.
|
|
9
|
+
|
|
10
|
+
* In the path plugin, the path method now accepts a :relative
|
|
11
|
+
option for generating relative paths instead of absolute paths.
|
data/lib/roda/plugins/assets.rb
CHANGED
|
@@ -325,10 +325,14 @@ class Roda
|
|
|
325
325
|
|
|
326
326
|
# Load the render, caching, and h plugins, since the assets plugin
|
|
327
327
|
# depends on them.
|
|
328
|
-
def self.load_dependencies(app,
|
|
328
|
+
def self.load_dependencies(app, opts = OPTS)
|
|
329
329
|
app.plugin :render
|
|
330
330
|
app.plugin :caching
|
|
331
331
|
app.plugin :h
|
|
332
|
+
|
|
333
|
+
if opts[:relative_paths]
|
|
334
|
+
app.plugin :relative_path
|
|
335
|
+
end
|
|
332
336
|
end
|
|
333
337
|
|
|
334
338
|
# Setup the options for the plugin. See the Assets module RDoc
|
|
@@ -647,10 +651,9 @@ class Roda
|
|
|
647
651
|
end
|
|
648
652
|
end
|
|
649
653
|
|
|
650
|
-
if relative_paths
|
|
651
|
-
relative_prefix = "../" * (slash_count - 1)
|
|
654
|
+
if relative_paths
|
|
652
655
|
paths.map! do |path|
|
|
653
|
-
"#{relative_prefix}#{path
|
|
656
|
+
"#{relative_prefix}#{path}"
|
|
654
657
|
end
|
|
655
658
|
end
|
|
656
659
|
|
data/lib/roda/plugins/path.rb
CHANGED
|
@@ -55,6 +55,8 @@ class Roda
|
|
|
55
55
|
# :add_script_name :: Prefix the path generated with SCRIPT_NAME. This defaults to the app's
|
|
56
56
|
# :add_script_name option.
|
|
57
57
|
# :name :: Provide a different name for the method, instead of using <tt>*_path</tt>.
|
|
58
|
+
# :relative :: Generate paths relative to the current request instead of absolute paths by prepending
|
|
59
|
+
# an appropriate prefix. This implies :add_script_name.
|
|
58
60
|
# :url :: Create a url method in addition to the path method, which will prefix the string generated
|
|
59
61
|
# with the appropriate scheme, host, and port. If true, creates a <tt>*_url</tt>
|
|
60
62
|
# method. If a Symbol or String, uses the value as the url method name.
|
|
@@ -121,16 +123,31 @@ class Roda
|
|
|
121
123
|
|
|
122
124
|
meth = opts[:name] || "#{name}_path"
|
|
123
125
|
url = opts[:url]
|
|
126
|
+
url_only = opts[:url_only]
|
|
127
|
+
relative = opts[:relative]
|
|
124
128
|
add_script_name = opts.fetch(:add_script_name, self.opts[:add_script_name])
|
|
125
129
|
|
|
126
|
-
if
|
|
130
|
+
if relative
|
|
131
|
+
if (url || url_only)
|
|
132
|
+
raise RodaError, "cannot provide :url or :url_only option if using :relative option"
|
|
133
|
+
end
|
|
134
|
+
add_script_name = true
|
|
135
|
+
plugin :relative_path
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
if add_script_name || url || url_only || relative
|
|
127
139
|
_meth = "_#{meth}"
|
|
128
140
|
define_method(_meth, &block)
|
|
129
141
|
private _meth
|
|
130
142
|
end
|
|
131
143
|
|
|
132
|
-
unless
|
|
133
|
-
if
|
|
144
|
+
unless url_only
|
|
145
|
+
if relative
|
|
146
|
+
define_method(meth) do |*a, &blk|
|
|
147
|
+
# Allow calling private _method to get path
|
|
148
|
+
relative_path(request.script_name.to_s + send(_meth, *a, &blk))
|
|
149
|
+
end
|
|
150
|
+
elsif add_script_name
|
|
134
151
|
define_method(meth) do |*a, &blk|
|
|
135
152
|
# Allow calling private _method to get path
|
|
136
153
|
request.script_name.to_s + send(_meth, *a, &blk)
|
|
@@ -140,7 +157,7 @@ class Roda
|
|
|
140
157
|
end
|
|
141
158
|
end
|
|
142
159
|
|
|
143
|
-
if url ||
|
|
160
|
+
if url || url_only
|
|
144
161
|
url_meth = if url.is_a?(String) || url.is_a?(Symbol)
|
|
145
162
|
url
|
|
146
163
|
else
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
class Roda
|
|
5
|
+
module RodaPlugins
|
|
6
|
+
# The relative_path plugin adds a relative_path method that accepts
|
|
7
|
+
# an absolute path and returns a path relative to the current request
|
|
8
|
+
# by adding an appropriate prefix:
|
|
9
|
+
#
|
|
10
|
+
# plugin :relative_path
|
|
11
|
+
# route do |r|
|
|
12
|
+
# relative_path("/foo")
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# # GET /
|
|
16
|
+
# "./foo"
|
|
17
|
+
#
|
|
18
|
+
# # GET /bar
|
|
19
|
+
# "./foo"
|
|
20
|
+
#
|
|
21
|
+
# # GET /bar/
|
|
22
|
+
# "../foo"
|
|
23
|
+
#
|
|
24
|
+
# # GET /bar/baz/quux
|
|
25
|
+
# "../../foo"
|
|
26
|
+
#
|
|
27
|
+
# It also offers a relative_prefix method that returns a string that can
|
|
28
|
+
# be prepended to an absolute path. This can be more efficient if you
|
|
29
|
+
# need to convert multiple paths.
|
|
30
|
+
#
|
|
31
|
+
# This plugin is mostly designed for applications using Roda as a static
|
|
32
|
+
# site generator, where the generated site can be hosted at any subpath.
|
|
33
|
+
module RelativePath
|
|
34
|
+
module InstanceMethods
|
|
35
|
+
# Return a relative path for the absolute path based on the current path
|
|
36
|
+
# of the request by adding the appropriate prefix.
|
|
37
|
+
def relative_path(absolute_path)
|
|
38
|
+
relative_prefix + absolute_path
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Return a relative prefix to append to an absolute path to a relative path
|
|
42
|
+
# based on the current path of the request.
|
|
43
|
+
def relative_prefix
|
|
44
|
+
env = @_request.env
|
|
45
|
+
script_name = env["SCRIPT_NAME"]
|
|
46
|
+
path_info = env["PATH_INFO"]
|
|
47
|
+
|
|
48
|
+
# Check path begins with slash. All valid paths should, but in case this
|
|
49
|
+
# request is bad, just skip using a relative prefix.
|
|
50
|
+
case script_name.getbyte(0)
|
|
51
|
+
when nil # SCRIPT_NAME empty
|
|
52
|
+
unless path_info.getbyte(0) == 47 # PATH_INFO starts with /
|
|
53
|
+
return ''
|
|
54
|
+
end
|
|
55
|
+
when 47 # SCRIPT_NAME starts with /
|
|
56
|
+
# nothing
|
|
57
|
+
else
|
|
58
|
+
return ''
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
slash_count = script_name.count('/') + path_info.count('/')
|
|
62
|
+
if slash_count > 1
|
|
63
|
+
("../" * (slash_count - 2)) << ".."
|
|
64
|
+
else
|
|
65
|
+
"."
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
register_plugin(:relative_path, RelativePath)
|
|
72
|
+
end
|
|
73
|
+
end
|
data/lib/roda/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: roda
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.31.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeremy Evans
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-04-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|
|
@@ -206,6 +206,7 @@ extra_rdoc_files:
|
|
|
206
206
|
- doc/release_notes/3.28.0.txt
|
|
207
207
|
- doc/release_notes/3.29.0.txt
|
|
208
208
|
- doc/release_notes/3.30.0.txt
|
|
209
|
+
- doc/release_notes/3.31.0.txt
|
|
209
210
|
files:
|
|
210
211
|
- CHANGELOG
|
|
211
212
|
- MIT-LICENSE
|
|
@@ -237,6 +238,7 @@ files:
|
|
|
237
238
|
- doc/release_notes/3.29.0.txt
|
|
238
239
|
- doc/release_notes/3.3.0.txt
|
|
239
240
|
- doc/release_notes/3.30.0.txt
|
|
241
|
+
- doc/release_notes/3.31.0.txt
|
|
240
242
|
- doc/release_notes/3.4.0.txt
|
|
241
243
|
- doc/release_notes/3.5.0.txt
|
|
242
244
|
- doc/release_notes/3.6.0.txt
|
|
@@ -316,6 +318,7 @@ files:
|
|
|
316
318
|
- lib/roda/plugins/placeholder_string_matchers.rb
|
|
317
319
|
- lib/roda/plugins/precompile_templates.rb
|
|
318
320
|
- lib/roda/plugins/public.rb
|
|
321
|
+
- lib/roda/plugins/relative_path.rb
|
|
319
322
|
- lib/roda/plugins/render.rb
|
|
320
323
|
- lib/roda/plugins/render_each.rb
|
|
321
324
|
- lib/roda/plugins/render_locals.rb
|