lib/deface/action_view_extensions.rb in deface-1.0.0.rc2 vs lib/deface/action_view_extensions.rb in deface-1.0.0.rc3
- old
+ new
@@ -1,15 +1,19 @@
ActionView::Template.class_eval do
alias_method :initialize_without_deface, :initialize
def initialize(source, identifier, handler, details)
- if Rails.application.config.deface.enabled && should_be_defaced?(handler)
- haml = handler.to_s == "Haml::Plugin"
+ syntax = determine_syntax(handler)
- processed_source = Deface::Override.apply(source, details, true, haml )
+ if Rails.application.config.deface.enabled && should_be_defaced?(syntax)
- if haml && processed_source != source
+ processed_source = Deface::Override.apply(source, details, true, syntax)
+
+ # force change in handler before continuing to original Rails method
+ # as we've just converted some other template language into ERB!
+ #
+ if [:slim, :haml].include?(syntax) && processed_source != source
handler = ActionView::Template::Handlers::ERB
end
else
processed_source = source
end
@@ -51,11 +55,23 @@
"_#{Digest::MD5.new.update("#{deface_hash}_#{method_name_without_deface}").hexdigest}"
end
private
- def should_be_defaced?(handler)
- handler.to_s.demodulize == "ERB" || handler.class.to_s.demodulize == "ERB" || handler.to_s == "Haml::Plugin"
+ def should_be_defaced?(syntax)
+ syntax != :unknown
+ end
+
+ def determine_syntax(handler)
+ if handler.to_s == "Haml::Plugin"
+ :haml
+ elsif handler.class.to_s == "Slim::RailsTemplate"
+ :slim
+ elsif handler.to_s.demodulize == "ERB" || handler.class.to_s.demodulize == "ERB"
+ :erb
+ else
+ :unknown
+ end
end
end
#fix for Rails 3.1 not setting virutal_path anymore (BOO!)
if defined?(ActionView::Resolver::Path)