Class: JavascriptFeatures::TestCase::Servlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/javascript_features/test_case/servlet.rb

Instance Method Summary collapse

Constructor Details

#initialize(server, pages) ⇒ Servlet

Returns a new instance of Servlet.



4
5
6
7
# File 'lib/javascript_features/test_case/servlet.rb', line 4

def initialize(server, pages)
  super server
  @pages = pages
end

Instance Method Details

#service(req, res) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/javascript_features/test_case/servlet.rb', line 9

def service(req, res)
  page = @pages[req.path]
  if page
    res.status = 200
    res['Content-Type'] = 'text/html'
    if page.is_a?(Hash)
      page[:headers].each{ |k,v| res[k] = v }
      res.body = page[:body]
    else
      res.body = page
    end
  elsif req.path =~ %r[^/javascripts/packaged/([^/]+).js$]
    res.status = 200
    res['Content-Type'] = 'text/javascript'
    res.body = JavascriptFeatures::Compiler.compile(:package => $1)
  else
    res.status = 404
    res['Content-Type'] = 'text/plain'
    res.body = 'Not found'
  end
end