hiccdown 1.1.3 → 1.2.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 +4 -4
- data/lib/hiccdown/railtie.rb +28 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ead146bd91fca399a19ec892b1fb8848bc7f8e21bff02d6bd96a3c82c7d4cd96
|
4
|
+
data.tar.gz: 6776f3acc40034f2227b22258c6f4166070cda1d87ae43dda7800c120803ece1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 611b2b7e3811bdd54385bffa952115b2e6a89672825c1de619cfa2093ed31538dc475b87cb04c2315d48f7875c42193019a0fc47a4af84f486266005f379d087
|
7
|
+
data.tar.gz: bb3a2226add5a5c16fbdc46832ff44c24c0ef287b35fd2cf6b06f6a7f9343d362e683709a84ecba1581abd864231c48287272f30b7181a73a11e419d4ecdd937
|
data/lib/hiccdown/railtie.rb
CHANGED
@@ -3,10 +3,34 @@ module Hiccdown
|
|
3
3
|
initializer 'hiccdown.action_controller' do
|
4
4
|
ActiveSupport.on_load(:action_controller) do
|
5
5
|
include CustomViewRendering
|
6
|
+
|
7
|
+
# Per https://stackoverflow.com/a/78783866/1371131
|
8
|
+
ActionController::Renderers.add :hiccdown do |src, options|
|
9
|
+
render({ html: Hiccdown.to_html(src).html_safe }.merge(options))
|
10
|
+
end
|
6
11
|
end
|
7
12
|
end
|
8
13
|
end
|
9
14
|
|
15
|
+
class Renderable
|
16
|
+
def initialize(helper_module, action_name)
|
17
|
+
@helper_module = helper_module
|
18
|
+
@action_name = action_name
|
19
|
+
end
|
20
|
+
|
21
|
+
# This is the view-bound view_context. Needed for `content_for` to work
|
22
|
+
# properly in helper, see https://stackoverflow.com/a/78783866/1371131
|
23
|
+
def render_in(view_context)
|
24
|
+
content = @helper_module.instance_method(@action_name).bind_call(view_context)
|
25
|
+
|
26
|
+
Hiccdown::to_html(content)
|
27
|
+
end
|
28
|
+
|
29
|
+
def format
|
30
|
+
:html
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
10
34
|
module CustomViewRendering
|
11
35
|
extend ActiveSupport::Concern
|
12
36
|
|
@@ -45,8 +69,10 @@ module Hiccdown
|
|
45
69
|
helper_module = helper_name.constantize
|
46
70
|
|
47
71
|
if helper_module.instance_methods(false).include?(action_name.to_sym)
|
48
|
-
|
49
|
-
|
72
|
+
original_render(
|
73
|
+
Hiccdown::Renderable.new(helper_module, action_name),
|
74
|
+
{ layout: !request.format.turbo_stream? }.merge(options)
|
75
|
+
)
|
50
76
|
else
|
51
77
|
original_render({ action: action_name }.merge(options))
|
52
78
|
end
|