markdowndocs 0.2.2 → 0.2.3

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: a6f2f9ae54ee9769434428aec5808626c4bcc08a55137c339c9310df30fe5973
4
- data.tar.gz: c8e029017e1b6739c2b3f2740a016bdf42ff02e87d5935330601ea5f6bd2fb0e
3
+ metadata.gz: 1a94678490cfbf0ad5351412ccb04dcf9938d0bfae47184b333a18f06d8a605c
4
+ data.tar.gz: 9214f78fe1209a67c633909bbe8abd2e09af3fc229e3aee016cbb59604e79b77
5
5
  SHA512:
6
- metadata.gz: 751e5771036b40187003bbbdeaa0fc9ed27142b9d3e542a1e712d74b9f02ac174e82ae8f9ebb1a32b29b42fe3083c2990c746a92aac04fb50a31914a638bb66d
7
- data.tar.gz: 22e8544a817e4402d071163c5fc809f316d90a13f7239f50d37e6d3756fd182535f869af85f34d594b94a566445ca799092fc2f0e6558b088b7749384a50fcf7
6
+ metadata.gz: 24d803af2159fc9deedb4a2b681d2689b4329a88fb384391e820df9adeff787ca9c2206bfae41f511340b0b78d4c0066f1639b0f48462ab42fcb2e80b021ec90
7
+ data.tar.gz: '02359d490827c09532c4e063e6fc1596cbdaa89b0632404fe18d40cdb16513780f4b19029e60e9b3619174f8f3cc1f4186b91f476b7d799a3d833e41ee4f7b35'
@@ -4,37 +4,19 @@ module Markdowndocs
4
4
  class ApplicationController < ::ApplicationController
5
5
  protect_from_forgery with: :exception
6
6
 
7
- # Delegate unresolved route helpers to the host app via main_app.
8
- # isolate_namespace blocks host helpers by default, and the commonly-used
9
- # `helper Rails.application.routes.url_helpers` doesn't reliably win the
10
- # method-lookup race so host-app links like about_path can resolve
11
- # against the engine's catch-all :slug route instead. This delegation
12
- # ensures host app route helpers always work correctly in engine views.
13
- helper do
14
- # Explicitly delegate root_path/root_url to the host app.
15
- # The engine defines its own root route, so these helpers exist in the
16
- # engine scope and method_missing won't intercept them but they resolve
17
- # to /docs/ instead of /. Engine views use markdowndocs.root_path directly.
18
- def root_path(*args)
19
- main_app.root_path(*args)
20
- end
21
-
22
- def root_url(*args)
23
- main_app.root_url(*args)
24
- end
25
-
26
- def method_missing(method, *args, &block)
27
- if main_app.respond_to?(method)
28
- main_app.send(method, *args, &block)
29
- else
30
- super
31
- end
32
- end
33
-
34
- def respond_to_missing?(method, include_private = false)
35
- main_app.respond_to?(method, include_private) || super
36
- end
37
- end
7
+ # Fix route helper isolation caused by isolate_namespace.
8
+ #
9
+ # The problem: host app route helpers (about_path, contact_path, etc.)
10
+ # exist in the view context but resolve against the engine's namespace,
11
+ # so about_path returns "/docs/about" instead of "/about".
12
+ #
13
+ # method_missing doesn't help because the methods already exist —
14
+ # they just resolve wrong. We need to override them explicitly.
15
+ #
16
+ # This before_action builds a helper module on first request (when
17
+ # routes are fully loaded) that defines every host app route helper
18
+ # as a delegation to main_app.
19
+ before_action :ensure_host_route_helpers
38
20
 
39
21
  # Support Rails 8 built-in authentication (allow_unauthenticated_access)
40
22
  # without requiring it — works with any auth system or none at all
@@ -44,5 +26,21 @@ module Markdowndocs
44
26
 
45
27
  # Resume session if the host app supports it (Rails 8 auth)
46
28
  before_action :resume_session, if: -> { respond_to?(:resume_session, true) }
29
+
30
+ private
31
+
32
+ def ensure_host_route_helpers
33
+ return if self.class.instance_variable_get(:@host_routes_delegated)
34
+
35
+ helper_module = Module.new do
36
+ Rails.application.routes.named_routes.names.each do |name|
37
+ define_method(:"#{name}_path") { |*args, **kwargs| main_app.send(:"#{name}_path", *args, **kwargs) }
38
+ define_method(:"#{name}_url") { |*args, **kwargs| main_app.send(:"#{name}_url", *args, **kwargs) }
39
+ end
40
+ end
41
+
42
+ self.class.helper(helper_module)
43
+ self.class.instance_variable_set(:@host_routes_delegated, true)
44
+ end
47
45
  end
48
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Markdowndocs
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdowndocs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Chmura
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2026-03-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -112,7 +111,6 @@ metadata:
112
111
  homepage_uri: https://github.com/dschmura/markdowndocs
113
112
  source_code_uri: https://github.com/dschmura/markdowndocs
114
113
  changelog_uri: https://github.com/dschmura/markdowndocs/blob/main/CHANGELOG.md
115
- post_install_message:
116
114
  rdoc_options: []
117
115
  require_paths:
118
116
  - lib
@@ -127,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
125
  - !ruby/object:Gem::Version
128
126
  version: '0'
129
127
  requirements: []
130
- rubygems_version: 3.4.19
131
- signing_key:
128
+ rubygems_version: 3.6.9
132
129
  specification_version: 4
133
130
  summary: A drop-in markdown documentation site for Rails apps
134
131
  test_files: []