Class: Jekyll::Commands::Serve::SkipAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/commands/serve/servlet.rb

Overview

This class is used to determine if the Servlet should modify a served file to insert the LiveReload script tags

Constant Summary collapse

BAD_USER_AGENTS =
[%r!MSIE!].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response, options) ⇒ SkipAnalyzer

Returns a new instance of SkipAnalyzer.


17
18
19
20
21
# File 'lib/jekyll/commands/serve/servlet.rb', line 17

def initialize(request, response, options)
  @options = options
  @request = request
  @response = response
end

Class Method Details

.skip_processing?(request, response, options) ⇒ Boolean

Returns:

  • (Boolean)

13
14
15
# File 'lib/jekyll/commands/serve/servlet.rb', line 13

def self.skip_processing?(request, response, options)
  new(request, response, options).skip_processing?
end

Instance Method Details

#bad_browser?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/jekyll/commands/serve/servlet.rb', line 35

def bad_browser?
  BAD_USER_AGENTS.any? { |pattern| pattern.match?(@request["User-Agent"]) }
end

#chunked?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/jekyll/commands/serve/servlet.rb', line 27

def chunked?
  @response["Transfer-Encoding"] == "chunked"
end

#html?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/jekyll/commands/serve/servlet.rb', line 39

def html?
  @response["Content-Type"].to_s.include?("text/html")
end

#inline?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/jekyll/commands/serve/servlet.rb', line 31

def inline?
  @response["Content-Disposition"].to_s.start_with?("inline")
end

#skip_processing?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/jekyll/commands/serve/servlet.rb', line 23

def skip_processing?
  !html? || chunked? || inline? || bad_browser?
end