sdoc_live 0.1.7 → 0.1.8

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: 1653429aed4ce0456d7df0c26da4d8ccdde41967cfd91ab2824c24c5da7dc975
4
- data.tar.gz: a22e7b188e50c419cf7160dbc2c2b32160320ca46015306cf19e08efde37dc11
3
+ metadata.gz: 2c58eaf82f18b4feb7c431156e8ba8be018e22eb57b8b62d69e0e0c503e2085c
4
+ data.tar.gz: 372965feda50bdc4bc08b196d3acbbc43af6fe2b7fb4461b622bbb4f80c0befa
5
5
  SHA512:
6
- metadata.gz: 4c592cd42c497602bbb49b90e9f1603c407139e8c00e0f093f26bfc412a5c160b1de729ce70c4db14a5efbe89967e51eceda9bca695273f7e252c83e6dfd639a
7
- data.tar.gz: 87c2c8adc1768ed43cba4aad88b425a16279920893ab5e326c63555e5653c1bce416980d868eb1e17d52162277ce80bc009466df465e38743ba266f8c081df79
6
+ metadata.gz: 224cc2e187603628bb1e76664ef87ff8f6c33640d34512d38e7f262b1e96490a3e05dc07ed2cc08f78e372adf8a016bae6c55199f2a9de3c57ebbcc1ea2e5bfb
7
+ data.tar.gz: dc1222d122c5992e1e9505e752305a28b164b0d55dff3bbdc3f3b19aae4d630c76d6940be15fd45201426e1c548172bea7722b61cf6f3f95eb4ffec2ef02c2f2
@@ -21,20 +21,30 @@ module SdocLive
21
21
  end
22
22
  end
23
23
 
24
- initializer "sdoc_live.trailing_slash" do
25
- SdocLive::Engine.middleware.use(Class.new do
26
- def initialize(app)
27
- @app = app
24
+ initializer "sdoc_live.trailing_slash", after: :add_routing_paths do |app|
25
+ mount_path = nil
26
+
27
+ app.routes.routes.each do |route|
28
+ if route.app.respond_to?(:app) && route.app.app == SdocLive::Engine
29
+ mount_path = route.path.spec.to_s.gsub("(.:format)", "").chomp("/")
30
+ break
28
31
  end
32
+ end
29
33
 
30
- def call(env)
31
- if env["PATH_INFO"] == ""
32
- [301, { "location" => "#{ env['SCRIPT_NAME'] }/", "content-type" => "text/html" }, ["Redirecting..."]]
33
- else
34
- @app.call(env)
34
+ if mount_path && !mount_path.empty?
35
+ app.middleware.use(Class.new do
36
+ define_method(:initialize) { |a| @app = a }
37
+
38
+ define_method(:call) do |env|
39
+ if env["PATH_INFO"] == mount_path && !env["PATH_INFO"].end_with?("/")
40
+ query = env["QUERY_STRING"].to_s.empty? ? "" : "?#{ env['QUERY_STRING'] }"
41
+ [301, { "location" => "#{ mount_path }/#{ query }", "content-type" => "text/html" }, ["Redirecting..."]]
42
+ else
43
+ @app.call(env)
44
+ end
35
45
  end
36
- end
37
- end)
46
+ end)
47
+ end
38
48
  end
39
49
 
40
50
  end
@@ -1,5 +1,5 @@
1
1
  module SdocLive
2
2
 
3
- VERSION = "0.1.7"
3
+ VERSION = "0.1.8"
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdoc_live
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - 16554289+optimuspwnius@users.noreply.github.com