Skip to content

Commit

Permalink
Update patched method to reflect changes in Deface 1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Nov 21, 2024
1 parent de399aa commit 3ca97c0
Showing 1 changed file with 28 additions and 47 deletions.
75 changes: 28 additions & 47 deletions lib/applicator_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,45 @@ module Deface
module Applicator
module ClassMethods

# applies all applicable overrides to given source
#
def apply(source, details, log = true, syntax = :erb)
overrides = find(details)
# applies specified overrides to given source
def apply_overrides(source, overrides:, log: true)

if log && overrides.size > 0
Rails.logger.debug "\e[1;32mDeface:\e[0m #{overrides.size} overrides found for '#{details[:virtual_path]}'"
end
doc = Deface::Parser.convert(source)

unless overrides.empty?
case syntax
when :haml
#convert haml to erb before parsing before
source = Deface::HamlConverter.new(source.to_param).result
when :slim
source = Deface::SlimConverter.new(source.to_param).result
overrides.each do |override|
if override.disabled?
Rails.logger.debug("\e[1;32mDeface:\e[0m '#{override.name}' is disabled") if log
next
end

doc = Deface::Parser.convert(source)

overrides.each do |override|
if override.disabled?
Rails.logger.debug("\e[1;32mDeface:\e[0m '#{override.name}' is disabled") if log
next
end
override.parsed_document = doc
matches = override.matcher.matches(doc, log)

override.parsed_document = doc
matches = override.matcher.matches(doc, log)
if log
Rails.logger.send(matches.size == 0 ? :error : :debug, "\e[1;32mDeface:\e[0m '#{override.name}' matched #{matches.size} times with '#{override.selector}'")

if log
Rails.logger.send(matches.size == 0 ? :error : :debug, "\e[1;32mDeface:\e[0m '#{override.name}' matched #{matches.size} times with '#{override.selector}'")

# temporarily check and notify on use of old selector styles.
#
if matches.empty? && override.selector.match(/code|erb-loud|erb-silent/)
Rails.logger.error "\e[1;32mDeface: [WARNING]\e[0m Override '#{override.name}' may be using an invalid selector of '#{override.selector}', <code erb-loud|silent> tags are now <erb loud|silent>"
end
end

if matches.empty?
override.failure = "failed to match :#{override.action} selector '#{override.selector}'"
else
override.failure = nil
matches.each { |match| override.execute_action match }
# temporarily check and notify on use of old selector styles.
#
if matches.empty? && override.selector.match(/code|erb-loud|erb-silent/)
Rails.logger.error "\e[1;32mDeface: [WARNING]\e[0m Override '#{override.name}' may be using an invalid selector of '#{override.selector}', <code erb-loud|silent> tags are now <erb loud|silent>"
end
end

# Prevents any caching by rails in development mode.
details[:updated_at] = Time.now if Deface.before_rails_6?
if matches.empty?
override.failure = "failed to match :#{override.action} selector '#{override.selector}'"
else
override.failure = nil
matches.each {|match| override.execute_action match }
end
end

###############################
### START PATCH
source = CGI.unescapeHTML doc.to_s
### END PATCH
###############################
###############################
### START PATCH
source = CGI.unescapeHTML doc.to_s
### END PATCH
###############################

Deface::Parser.undo_erb_markup!(source)
end
Deface::Parser.undo_erb_markup!(source)

source
end
Expand Down

0 comments on commit 3ca97c0

Please sign in to comment.