class SiteDiff::Webserver::ResultServer::SideBySideServlet

Display two pages side by side.

Public Class Methods

new(_server, cache, settings) click to toggle source

Creates a Side By Side Servlet.

# File lib/sitediff/webserver/resultserver.rb, line 43
def initialize(_server, cache, settings)
  @cache = cache
  @settings = settings
end

Public Instance Methods

do_GET(req, res) click to toggle source

Performs a GET request.

# File lib/sitediff/webserver/resultserver.rb, line 60
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) click to toggle source

Generates URLs for a given path.

# File lib/sitediff/webserver/resultserver.rb, line 50
def urls(path)
  %w[before after].map do |tag|
    base = @settings[tag]
    base = "/cache/#{tag}" if @settings['cached'].include? tag
    base + path
  end
end