class Capybara::Server::AnimationDisabler

Constants

DISABLE_MARKUP_TEMPLATE

Attributes

disable_markup[R]

Public Class Methods

new(app) click to toggle source
# File lib/capybara/server/animation_disabler.rb, line 16
def initialize(app)
  @app = app
  @disable_markup = DISABLE_MARKUP_TEMPLATE % AnimationDisabler.selector_for(Capybara.disable_animation)
end
selector_for(css_or_bool) click to toggle source
# File lib/capybara/server/animation_disabler.rb, line 5
def self.selector_for(css_or_bool)
  case css_or_bool
  when String
    css_or_bool
  when true
    '*'
  else
    raise CapybaraError, 'Capybara.disable_animation supports either a String (the css selector to disable) or a boolean'
  end
end

Public Instance Methods

call(env) click to toggle source
# File lib/capybara/server/animation_disabler.rb, line 21
def call(env)
  @status, @headers, @body = @app.call(env)
  return [@status, @headers, @body] unless html_content?
  response = Rack::Response.new([], @status, @headers)

  @body.each { |html| response.write insert_disable(html) }
  @body.close if @body.respond_to?(:close)

  response.finish
end

Private Instance Methods

html_content?() click to toggle source
# File lib/capybara/server/animation_disabler.rb, line 36
def html_content?
  !!(@headers['Content-Type'] =~ /html/)
end
insert_disable(html) click to toggle source
# File lib/capybara/server/animation_disabler.rb, line 40
def insert_disable(html)
  html.sub(%r{(</head>)}, disable_markup + '\\1')
end