Skip to content

Commit

Permalink
Extract the template class to ha helper
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Jul 31, 2020
1 parent 4ede79f commit e6f1b25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/deface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@

module Deface
@before_rails_6 = ActionView.gem_version < Gem::Version.new('6.0.0')
@template_class = @before_rails_6 ? ActionView::CompiledTemplates : ActionDispatch::DebugView

def self.before_rails_6?
@before_rails_6
end

def self.template_class
@template_class
end

if defined?(ActiveSupport::Digest)
Deface::Digest.digest_class = ActiveSupport::Digest
end
Expand Down
4 changes: 1 addition & 3 deletions lib/deface/action_view_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def initialize(source, identifier, handler, details)
# view needs to be recompiled
#
def render(view, locals, buffer=nil, &block)
template_class = Deface.before_rails_6? ? ActionView::CompiledTemplates : ActionDispatch::DebugView

mod = view.is_a?(template_class) ? template_class : view.singleton_class
mod = view.is_a?(Deface.template_class) ? Deface.template_class : view.singleton_class

if @compiled && !mod.instance_methods.include?(method_name.to_sym)
@compiled = false
Expand Down
5 changes: 2 additions & 3 deletions lib/deface/override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,14 @@ def self.actions
# then remove the old method - this will allow the template to be
# recompiled the next time it is rendered (showing the latest changes).
def expire_compiled_template
template_class = Deface.before_rails_6? ? ActionView::CompiledTemplates : ActionDispatch::DebugView
virtual_path = args[:virtual_path]

method_name = template_class.instance_methods.detect do |name|
method_name = Deface.template_class.instance_methods.detect do |name|
name =~ /#{virtual_path.gsub(/[^a-z_]/, '_')}/
end

if method_name && method_name !~ /\A_#{self.class.digest(virtual_path: virtual_path)}_/
template_class.send :remove_method, method_name
Deface.template_class.send :remove_method, method_name
end
end
end
Expand Down

0 comments on commit e6f1b25

Please sign in to comment.