Class: SiteDiff::Webserver::ResultServer::SideBySideServlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/sitediff/webserver/resultserver.rb

Overview

Display two pages side by side

Instance Method Summary collapse

Constructor Details

#initialize(_server, cache, settings) ⇒ SideBySideServlet

Returns a new instance of SideBySideServlet.



34
35
36
37
# File 'lib/sitediff/webserver/resultserver.rb', line 34

def initialize(_server, cache, settings)
  @cache = cache
  @settings = settings
end

Instance Method Details

#do_GET(req, res) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/sitediff/webserver/resultserver.rb', line 47

def do_GET(req, res)
  path = req.path_info
  before, after = *urls(path)

  res['content-type'] = 'text/html'
  erb = File.join(SiteDiff::FILES_DIR, 'sidebyside.html.erb')
  res.body = ERB.new(File.read(erb)).result(binding)
end

#urls(path) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/sitediff/webserver/resultserver.rb', line 39

def urls(path)
  %w[before after].map do |tag|
    base = @settings[tag]
    base = "/cache/#{tag}" if @settings['cached'].include? tag
    base + path
  end
end