Sha256: 8b900af6d056bc60672bc8a1c6c1f96913e412586cb828b4cafbea39525c7934

Contents?: true

Size: 974 Bytes

Versions: 1

Compression:

Stored size: 974 Bytes

Contents

require "rack/disable_css_animations/version"

module Rack
  class DisableCSSAnimations
    def initialize app
      @app = app
    end

    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

    def html?
      @headers["Content-Type"] =~ /html/
    end

    def inject response
      markup = <<-CSS
        <style>
          * {
            animation-delay: 0s !important;
            animation-duration: 0.01s !important;
            transition-delay: 0s !important;
            transition-duration: 0.01s !important;
            scroll-behavior: auto !important;
          }
        </style>
      CSS
      response.gsub(%r{</head>}, "#{markup}</head>")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-disable_css_animations-0.3.0 lib/rack/disable_css_animations.rb