class Rack::DisableCSSAnimations
Constants
- VERSION
Public Class Methods
new(app)
click to toggle source
# File lib/rack/disable_css_animations.rb, line 5 def initialize app @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/disable_css_animations.rb, line 9 def call env @status, @headers, @body = @app.call(env) return [@status, @headers, @body] unless html? response = Rack::Response.new([], @status, @headers) @body.each do |fragment| response.write inject(fragment) end @body.close if @body.respond_to?(:close) response.finish end
Private Instance Methods
html?()
click to toggle source
# File lib/rack/disable_css_animations.rb, line 24 def html? @headers["Content-Type"] =~ /html/ end
inject(response)
click to toggle source
# File lib/rack/disable_css_animations.rb, line 28 def inject response markup = <<-CSS <style> * { #{with_prefixes "animation-delay: 0s !important;"} #{with_prefixes "animation-duration: 0.01s !important;"} #{with_prefixes "transition-delay: 0s !important;"} #{with_prefixes "transition-duration: 0.01s !important;"} } </style> CSS response.gsub(%r{</head>}, "#{markup}</head>") end
with_prefixes(rule, prefixes = ["", "-webkit-", "-moz-", "-o-"])
click to toggle source
# File lib/rack/disable_css_animations.rb, line 42 def with_prefixes rule, prefixes = ["", "-webkit-", "-moz-", "-o-"] prefixes.map do |prefix| prefix + rule end.join("\n") end