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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hiccdown/railtie.rb +28 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17118bff652e5175c96b146254a53195f6c67094e87a242c56be8d2cd6eee3bf
4
- data.tar.gz: 4bf8a9ce13203c56dd2ae932a3f574bfc6507601643a0241e02f6d883b4eac06
3
+ metadata.gz: ead146bd91fca399a19ec892b1fb8848bc7f8e21bff02d6bd96a3c82c7d4cd96
4
+ data.tar.gz: 6776f3acc40034f2227b22258c6f4166070cda1d87ae43dda7800c120803ece1
5
5
  SHA512:
6
- metadata.gz: 64ecc32adb2249acaa85f94c6535e5128e0c384584a4117ccb6703c10c8a908ac3b8c27665007f93e4231773147c663f35b0a424d2c47434749e527d2927e4ac
7
- data.tar.gz: 81091e36fa8c1bb05e73229d7fc9072aa730371ecc19ca487480a024646ebba5b055dc2f45e46f59b61f3e82ed44e9e23b2d4ef7ac5f806ac6b340b45ad728d5
6
+ metadata.gz: 611b2b7e3811bdd54385bffa952115b2e6a89672825c1de619cfa2093ed31538dc475b87cb04c2315d48f7875c42193019a0fc47a4af84f486266005f379d087
7
+ data.tar.gz: bb3a2226add5a5c16fbdc46832ff44c24c0ef287b35fd2cf6b06f6a7f9343d362e683709a84ecba1581abd864231c48287272f30b7181a73a11e419d4ecdd937
@@ -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
- content = helper_module.instance_method(action_name).bind(view_context).call
49
- original_render({ html: Hiccdown::to_html(content).html_safe, layout: !request.format.turbo_stream? }.merge(options))
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiccdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Hackethal