ratalada-contrib 3.0.1 → 3.1.1
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/lib/ratalada/contrib/inertia/json_params_middleware.rb +35 -0
- data/lib/ratalada/contrib/inertia.rb +1 -0
- data/lib/ratalada/contrib/router/file_based/sinatra_adapter.rb +16 -2
- data/lib/ratalada/contrib/router/file_based.rb +18 -4
- data/lib/ratalada/contrib/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c8ff8bfec43fee16d7f6446cc1ac53f039125bee25e1cc7dd462cb98eeeae89
|
|
4
|
+
data.tar.gz: dd36a545190b503028691a3f4fb990dccc35f01a72781ada06c28b4408d31e16
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 98cabcf0bd20feadefb01d536414d7715105682779b38b272d5bdab4c61333329a83495df3974b384df84163b0d98d346bcd31fee2d443230ec68a9845adbb40
|
|
7
|
+
data.tar.gz: e03df9995ff21f5539b7c1134c50c4170bb8eee9cba7cd9e0a5ee349a3179cd55386e2c310cddd0b8de0ddbe9a9eda47a7833fe3a121358825b458e5e58279ed
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module Ratalada
|
|
6
|
+
module Contrib
|
|
7
|
+
module Inertia
|
|
8
|
+
# The Inertia client posts JSON, which Sinatra does not read into `params`.
|
|
9
|
+
# This parses the body into the hash Rack::Request builds `params` from.
|
|
10
|
+
class JsonParamsMiddleware
|
|
11
|
+
def initialize(app) = @app = app
|
|
12
|
+
|
|
13
|
+
def call(env)
|
|
14
|
+
if env["CONTENT_TYPE"].to_s.start_with?("application/json")
|
|
15
|
+
body = env["rack.input"]&.read
|
|
16
|
+
env["rack.input"]&.rewind
|
|
17
|
+
|
|
18
|
+
begin
|
|
19
|
+
parsed = JSON.parse(body.to_s)
|
|
20
|
+
rescue JSON::ParserError
|
|
21
|
+
parsed = nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
if parsed.is_a?(Hash)
|
|
25
|
+
env["rack.request.form_hash"] = parsed
|
|
26
|
+
env["rack.request.form_input"] = env["rack.input"]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
@app.call(env)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -26,6 +26,7 @@ require_relative "inertia/core_ext"
|
|
|
26
26
|
require_relative "inertia/response"
|
|
27
27
|
require_relative "inertia/middleware"
|
|
28
28
|
require_relative "inertia/csrf_middleware"
|
|
29
|
+
require_relative "inertia/json_params_middleware"
|
|
29
30
|
require_relative "inertia/helpers"
|
|
30
31
|
|
|
31
32
|
# LazyProp reports deprecation through code that's tied to rails.
|
|
@@ -12,12 +12,26 @@ module Ratalada
|
|
|
12
12
|
# hangs off it, which is how a route file's own `get "/members"` lands
|
|
13
13
|
# under the prefix its path spelled.
|
|
14
14
|
module SinatraAdapter
|
|
15
|
+
# Expo spelling, kept all the way to the pattern. Sinatra's own
|
|
16
|
+
# syntax has no way to say `[user-id]`: `:user-id` reads as the
|
|
17
|
+
# capture `user` followed by the literal `-id`, so a hyphenated
|
|
18
|
+
# parameter silently routes nowhere. Mustermann::Expo is the pattern
|
|
19
|
+
# the file path already is.
|
|
20
|
+
SPELLING = {placeholder: "[%s]", catch_all: "[...%s]"}.freeze
|
|
21
|
+
|
|
22
|
+
def route_spelling = SPELLING
|
|
23
|
+
|
|
15
24
|
def route(verb, path, options = {}, &block)
|
|
16
25
|
unless route_prefix.to_s.empty?
|
|
17
|
-
path = FileBased.join(route_prefix, path)
|
|
26
|
+
path = Mustermann.new(FileBased.join(route_prefix, path), type: :expo)
|
|
18
27
|
end
|
|
19
28
|
|
|
20
|
-
super
|
|
29
|
+
super(
|
|
30
|
+
verb,
|
|
31
|
+
path,
|
|
32
|
+
options,
|
|
33
|
+
&block
|
|
34
|
+
)
|
|
21
35
|
end
|
|
22
36
|
end
|
|
23
37
|
end
|
|
@@ -20,7 +20,15 @@ module Ratalada
|
|
|
20
20
|
#
|
|
21
21
|
# Server.run { Ratalada::Contrib::Router::FileBased.mount(self, "app") }
|
|
22
22
|
def mount(app, directory)
|
|
23
|
-
|
|
23
|
+
# The adapter says how its frontend spells a placeholder; the default
|
|
24
|
+
# is `:name`, which is what hanami and grape read.
|
|
25
|
+
if app.respond_to?(:route_spelling)
|
|
26
|
+
spelling = app.route_spelling
|
|
27
|
+
else
|
|
28
|
+
spelling = {}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
build_map(directory, **spelling).each do |prefix, paths|
|
|
24
32
|
app.route_prefix = prefix
|
|
25
33
|
paths.each { |path| app.class_eval(File.read(path), path, 1) }
|
|
26
34
|
end
|
|
@@ -75,12 +83,18 @@ module Ratalada
|
|
|
75
83
|
"#{prefix}#{route.delete_suffix("/")}".sub(/\A\z/, "/")
|
|
76
84
|
end
|
|
77
85
|
|
|
86
|
+
# Least specific last. A segment that is PARTLY literal beats a bare
|
|
87
|
+
# capture: `[index].[diffType]` and `[index]` both match "7.diff", and
|
|
88
|
+
# the one that spells the dot is the one that means it -- so the
|
|
89
|
+
# patterns are anchored to a single capture rather than to the whole
|
|
90
|
+
# segment, which `[index].[diffType]` would also satisfy.
|
|
78
91
|
def specificity(route)
|
|
79
92
|
route.split("/").drop(1).map do |segment|
|
|
80
93
|
case segment
|
|
81
|
-
when "[...#{Mustermann::Expo::NOT_FOUND_CAPTURE}]" then
|
|
82
|
-
when /\A\[
|
|
83
|
-
when /\A\[
|
|
94
|
+
when "[...#{Mustermann::Expo::NOT_FOUND_CAPTURE}]" then 4
|
|
95
|
+
when /\A\[\.\.\.[^\[\]]+\]\z/ then 3
|
|
96
|
+
when /\A\[[^\[\]]+\]\z/ then 2
|
|
97
|
+
when /\[.+\]/ then 1
|
|
84
98
|
else 0
|
|
85
99
|
end
|
|
86
100
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ratalada-contrib
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan K
|
|
@@ -53,6 +53,7 @@ files:
|
|
|
53
53
|
- lib/ratalada/contrib/inertia/csrf_middleware.rb
|
|
54
54
|
- lib/ratalada/contrib/inertia/errors.rb
|
|
55
55
|
- lib/ratalada/contrib/inertia/helpers.rb
|
|
56
|
+
- lib/ratalada/contrib/inertia/json_params_middleware.rb
|
|
56
57
|
- lib/ratalada/contrib/inertia/middleware.rb
|
|
57
58
|
- lib/ratalada/contrib/inertia/response.rb
|
|
58
59
|
- lib/ratalada/contrib/router/file_based.rb
|