markdowndocs 0.2.1 → 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: cebbfbc9bd8562902775c6661f2241c7c5556b1ccecdc4cc6b993804d4c58e02
4
- data.tar.gz: af7ab61db222e6dbd9dbecb557cc713068809fdd26604ed629c7b6a49c122e42
3
+ metadata.gz: 1a94678490cfbf0ad5351412ccb04dcf9938d0bfae47184b333a18f06d8a605c
4
+ data.tar.gz: 9214f78fe1209a67c633909bbe8abd2e09af3fc229e3aee016cbb59604e79b77
5
5
  SHA512:
6
- metadata.gz: 5389780ce9d8ad500df799b93bc5790cbca71651f2d320249be1d77cccb85124a484fc519c889e3fd2d8a8d1ec4458d9b65ba0925e706af2835261468e65bbdf
7
- data.tar.gz: 9ccbdda3525cc1bd2268214dd684643d5c200da356495cdeeb8f99fa364bee4615910ad20334ee943dd95b75502bc20afb8a5888ab95ed7f45cb0baa0b92804e
6
+ metadata.gz: 24d803af2159fc9deedb4a2b681d2689b4329a88fb384391e820df9adeff787ca9c2206bfae41f511340b0b78d4c0066f1639b0f48462ab42fcb2e80b021ec90
7
+ data.tar.gz: '02359d490827c09532c4e063e6fc1596cbdaa89b0632404fe18d40cdb16513780f4b19029e60e9b3619174f8f3cc1f4186b91f476b7d799a3d833e41ee4f7b35'
data/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.2.2] - 2026-03-18
9
+
10
+ ### Changed
11
+
12
+ - Stimulus controllers now auto-register via a single JS entry point (`import "markdowndocs"`), following the ActionText/Trix pattern. Host apps no longer need to pin individual controllers in their importmap.
13
+ - Install generator adds `import "markdowndocs"` to the host app's `application.js` instead of injecting importmap pins.
14
+ - Added engine and generator specs for the new JS registration flow.
15
+
8
16
  ## [0.2.1] - 2026-02-21
9
17
 
10
18
  ### Fixed
@@ -76,6 +84,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
76
84
  - i18n support for all UI strings
77
85
  - Install generator (`rails generate markdowndocs:install`)
78
86
 
87
+ [0.2.2]: https://github.com/dschmura/markdowndocs/releases/tag/v0.2.2
79
88
  [0.2.1]: https://github.com/dschmura/markdowndocs/releases/tag/v0.2.1
80
89
  [0.2.0]: https://github.com/dschmura/markdowndocs/releases/tag/v0.2.0
81
90
  [0.1.5]: https://github.com/dschmura/markdowndocs/releases/tag/v0.1.5
@@ -0,0 +1,11 @@
1
+ import DocsSearchController from "markdowndocs/controllers/docs_search_controller"
2
+ import DocsModeController from "markdowndocs/controllers/docs_mode_controller"
3
+
4
+ // Auto-register if Stimulus application exists on window, otherwise
5
+ // the host app can import and register these controllers manually.
6
+ if (window.Stimulus) {
7
+ window.Stimulus.register("docs-search", DocsSearchController)
8
+ window.Stimulus.register("docs-mode", DocsModeController)
9
+ }
10
+
11
+ export { DocsSearchController, DocsModeController }
@@ -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
data/config/importmap.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  # Importmap pins for Markdowndocs engine.
4
4
  # These are automatically registered with the host app when importmap-rails is present.
5
5
 
6
+ pin "markdowndocs", to: "markdowndocs/application.js"
6
7
  pin "markdowndocs/controllers/docs_search_controller", to: "markdowndocs/controllers/docs_search_controller.js"
7
8
  pin "markdowndocs/controllers/docs_mode_controller", to: "markdowndocs/controllers/docs_mode_controller.js"
8
9
  pin "minisearch", to: "markdowndocs/vendor/minisearch.min.js"
@@ -20,25 +20,18 @@ module Markdowndocs
20
20
  route 'mount Markdowndocs::Engine, at: "/docs"'
21
21
  end
22
22
 
23
- def pin_importmap_assets
24
- importmap_file = Rails.root.join("config/importmap.rb").to_s
25
- return unless File.exist?(importmap_file)
26
-
27
- importmap_content = File.read(importmap_file)
28
-
29
- pins = {
30
- 'pin "markdowndocs/controllers/docs_search_controller", to: "markdowndocs/controllers/docs_search_controller.js"' => "docs_search_controller",
31
- 'pin "markdowndocs/controllers/docs_mode_controller", to: "markdowndocs/controllers/docs_mode_controller.js"' => "docs_mode_controller",
32
- 'pin "minisearch", to: "markdowndocs/vendor/minisearch.min.js"' => "minisearch"
33
- }
34
-
35
- pins.each do |pin_line, name|
36
- if importmap_content.include?(pin_line)
37
- say_status :skip, "importmap pin for #{name} already present", :yellow
38
- else
39
- append_to_file importmap_file, "\n#{pin_line}\n"
40
- say_status :pin, name, :green
41
- end
23
+ def add_markdowndocs_import
24
+ js_file = Rails.root.join("app/javascript/application.js").to_s
25
+ return unless File.exist?(js_file)
26
+
27
+ js_content = File.read(js_file)
28
+ import_line = 'import "markdowndocs"'
29
+
30
+ if js_content.include?(import_line)
31
+ say_status :skip, "markdowndocs import already present in application.js", :yellow
32
+ else
33
+ append_to_file js_file, "\n#{import_line}\n"
34
+ say_status :import, "markdowndocs in application.js", :green
42
35
  end
43
36
  end
44
37
 
@@ -76,10 +69,8 @@ module Markdowndocs
76
69
  say " @source \"#{Markdowndocs::Engine.root.join("app", "views")}/**/*.erb\";"
77
70
  say ""
78
71
  end
79
- say " Stimulus controllers are auto-registered via importmap.", :green
80
- say " If you use a custom Stimulus setup, register these controllers:"
81
- say " - markdowndocs/controllers/docs_mode_controller"
82
- say " - markdowndocs/controllers/docs_search_controller (when search is enabled)"
72
+ say " Stimulus controllers are auto-registered via: import \"markdowndocs\"", :green
73
+ say " If this was not added automatically, add it to app/javascript/application.js"
83
74
  say ""
84
75
  end
85
76
 
@@ -19,5 +19,14 @@ module Markdowndocs
19
19
  app.config.importmap.paths << root.join("config/importmap.rb")
20
20
  end
21
21
  end
22
+
23
+ initializer "markdowndocs.stimulus" do
24
+ Rails.application.config.after_initialize do
25
+ if defined?(Importmap)
26
+ # The pin is already added via importmap.rb
27
+ # Host app just needs: import "markdowndocs" in their application.js
28
+ end
29
+ end
30
+ end
22
31
  end
23
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Markdowndocs
4
- VERSION = "0.2.1"
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.1
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-02-21 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
@@ -78,6 +77,7 @@ files:
78
77
  - CHANGELOG.md
79
78
  - README.md
80
79
  - Rakefile
80
+ - app/assets/javascripts/markdowndocs/application.js
81
81
  - app/assets/javascripts/markdowndocs/controllers/docs_mode_controller.js
82
82
  - app/assets/javascripts/markdowndocs/controllers/docs_search_controller.js
83
83
  - app/assets/javascripts/markdowndocs/vendor/minisearch.min.js
@@ -111,7 +111,6 @@ metadata:
111
111
  homepage_uri: https://github.com/dschmura/markdowndocs
112
112
  source_code_uri: https://github.com/dschmura/markdowndocs
113
113
  changelog_uri: https://github.com/dschmura/markdowndocs/blob/main/CHANGELOG.md
114
- post_install_message:
115
114
  rdoc_options: []
116
115
  require_paths:
117
116
  - lib
@@ -126,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
125
  - !ruby/object:Gem::Version
127
126
  version: '0'
128
127
  requirements: []
129
- rubygems_version: 3.4.19
130
- signing_key:
128
+ rubygems_version: 3.6.9
131
129
  specification_version: 4
132
130
  summary: A drop-in markdown documentation site for Rails apps
133
131
  test_files: []