engines/editor/lib/hocus_pocus/editor/railtie.rb in hocus_pocus-0.4.0 vs engines/editor/lib/hocus_pocus/editor/railtie.rb in hocus_pocus-0.4.1
- old
+ new
@@ -5,19 +5,33 @@
EDITOR = :__hocus_pocus_editor__
VIEW_FILENAME = :__hocus_pocus_view_filename__
PARTIAL_FILENAMES = :__hocus_pocus_partial_filenames__
module PartialRendererExtension
- def render_partial
- (Thread.current[HocusPocus::Editor::PARTIAL_FILENAMES] ||= []) << @template unless @view.controller.class.name.starts_with?('HocusPocus::')
- super
+ if ::ActionView::PartialRenderer.instance_method(:render_partial).arity == 2 # Rails 6
+ def render_partial(view, template)
+ (Thread.current[HocusPocus::Editor::PARTIAL_FILENAMES] ||= []) << template unless view.controller.class.name.starts_with?('HocusPocus::')
+ super
+ end
+ else
+ def render_partial
+ (Thread.current[HocusPocus::Editor::PARTIAL_FILENAMES] ||= []) << @template unless @view.controller.class.name.starts_with?('HocusPocus::')
+ super
+ end
end
end
module TemplateRendererExtension
- def render_template(template, layout_name = nil, locals = {})
- Thread.current[HocusPocus::Editor::VIEW_FILENAME] = template.virtual_path if @view.controller.try(:request).try(:format).try(:html?) && !@view.controller.class.name.starts_with?('HocusPocus::')
- super
+ if ::ActionView::TemplateRenderer.instance_method(:render_template).arity == 4 # Rails 6
+ def render_template(view, template, layout_name, locals)
+ Thread.current[HocusPocus::Editor::VIEW_FILENAME] = template.virtual_path if view.controller.try(:request).try(:format).try(:html?) && !view.controller.class.name.starts_with?('HocusPocus::')
+ super
+ end
+ else
+ def render_template(template, layout_name = nil, locals = {})
+ Thread.current[HocusPocus::Editor::VIEW_FILENAME] = template.virtual_path if @view.controller.try(:request).try(:format).try(:html?) && !@view.controller.class.name.starts_with?('HocusPocus::')
+ super
+ end
end
end
class Railtie < ::Rails::Railtie #:nodoc:
initializer 'hocus_pocus.editor' do |app|