lib/jb/action_view_monkeys.rb in jb-0.8.1 vs lib/jb/action_view_monkeys.rb in jb-0.8.2

- old
+ new

@@ -11,19 +11,22 @@ rendered_template end end end + # A wrapper class for template result that makes `to_s` method do nothing + class TemplateResult < SimpleDelegator + def to_s + __getobj__ + end + end + # Rails 7.1+: A monkey-patch not to stringify rendered object from JB templates - module BaseToSCanceller + module TemlateResultCaster def _run(method, template, *, **) val = super - if template.respond_to?(:handler) && (template.handler == Jb::Handler) - def val.to_s - self - end - end + val = Jb::TemplateResult.new val if template.respond_to?(:handler) && (template.handler == Jb::Handler) val end end # Rails 6.1+: A monkey-patch for jb template collection result's `body` not to return a String but an Array @@ -56,10 +59,10 @@ end end end ::ActionView::TemplateRenderer.prepend ::Jb::TemplateRenderer::JSONizer -::ActionView::Base.prepend ::Jb::BaseToSCanceller if (ActionView::VERSION::MAJOR >= 7) && (ActionView::VERSION::MINOR >= 1) +::ActionView::Base.prepend ::Jb::TemlateResultCaster if (ActionView::VERSION::MAJOR >= 7) && (ActionView::VERSION::MINOR >= 1) begin # ActionView::CollectionRenderer is a newly added class since 6.1 ::ActionView::CollectionRenderer.prepend ::Jb::CollectionRendererExtension rescue NameError ::ActionView::PartialRenderer.prepend ::Jb::PartialRendererExtension