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

Creates a Side By Side Servlet.



44
45
46
47
48
# File 'lib/sitediff/webserver/resultserver.rb', line 44

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

Instance Method Details

#do_GET(req, res) ⇒ Object

Performs a GET request.



62
63
64
65
66
67
68
69
# File 'lib/sitediff/webserver/resultserver.rb', line 62

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

Generates URLs for a given path.



52
53
54
55
56
57
58
# File 'lib/sitediff/webserver/resultserver.rb', line 52

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