Module: Hiccdown::ViewHelpers::RenderingHelperOverrides

Defined in:
lib/hiccdown.rb

Class Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hiccdown.rb', line 35

def self.prepended(base)
  # This teaches the view renderer (which is different from the controller renderer,
  # h/t https://stackoverflow.com/questions/78801079/rails-custom-renderer-for-turbo-stream?noredirect=1#comment138933498_78801079)
  # to accept a `:hiccdown` option, thus enabling the rendering of hiccdown in turbo-stream
  # actions as well:
  # `turbo_stream.update(..., hiccdown: [:h1, 'hello world'])
  define_method(:render) do |options = {}, locals = {}, &block|
    if options.is_a?(Hash) && options.key?(:hiccdown)
      Hiccdown.to_html(options[:hiccdown]).html_safe
    else
      super(options, locals, &block)
    end
  end
end