ratalada-contrib 3.0.0 → 3.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.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bfdfa2c6c7ee4b7dc67028882e3de270a3d4b54c32d540fc89ba8e7e0ba50ab5
|
|
4
|
+
data.tar.gz: ca771c956b1c2ee771f316e1e84d45d6d709154884d856059867fb7307693e38
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7a78f852ced399d457e904e3d2e3bd2b7c2a70083339b05b22d136042fb24f083436765cfe49365c3036f70dab830b793d7573c04bc3187fbbff92f34b2ee602
|
|
7
|
+
data.tar.gz: 6c6bdd43c7901c61198c1f83654af50e4a4dc100d6983659627f86fa61120545bbba63e13607e8dd7054e59d3dd0e656465c042b71eb530c9fdcb145cb50cceb
|
|
@@ -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,21 +12,25 @@ module Ratalada
|
|
|
12
12
|
|
|
13
13
|
module_function
|
|
14
14
|
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
end
|
|
15
|
+
# Evaluates every route file in the directory into an app class, under
|
|
16
|
+
# the prefix its path spells. That class is the frontend's own, so this
|
|
17
|
+
# is what a Server.run block calls: the block is already being evaluated
|
|
18
|
+
# into it, and `self` is it. Requiring the frontend's adapter is what
|
|
19
|
+
# teaches the class `route_prefix`.
|
|
20
|
+
#
|
|
21
|
+
# Server.run { Ratalada::Contrib::Router::FileBased.mount(self, "app") }
|
|
22
|
+
def mount(app, directory)
|
|
23
|
+
build_map(directory).each do |prefix, paths|
|
|
24
|
+
app.route_prefix = prefix
|
|
25
|
+
paths.each { |path| app.class_eval(File.read(path), path, 1) }
|
|
27
26
|
end
|
|
27
|
+
end
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
# The same, as a whole app built by whichever Ratalada frontend is in
|
|
30
|
+
# use — for mounting a directory somewhere other than the server's own
|
|
31
|
+
# run block.
|
|
32
|
+
def build(directory)
|
|
33
|
+
Ratalada.frontend.build(proc { FileBased.mount(self, directory) })
|
|
30
34
|
end
|
|
31
35
|
|
|
32
36
|
# A hash of route => the files that serve it, ordered most specific
|
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.0
|
|
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
|