Class: Amber::StaticPageServlet

Inherits:
WEBrick::HTTPServlet::FileHandler
  • Object
show all
Defined in:
lib/amber/server.rb

Constant Summary collapse

RENDERABLE_ASSET_RE =
/(#{Amber::Render::Asset::SOURCE_MAP.keys.join('|')})$/
ASSET_RE =
/\.(jpg|jpeg|png|gif|webm|css|js|ico)$/

Instance Method Summary collapse

Constructor Details

#initialize(http_server, amber_server) ⇒ StaticPageServlet

Returns a new instance of StaticPageServlet.



37
38
39
40
41
# File 'lib/amber/server.rb', line 37

def initialize(http_server, amber_server)
  @logger = http_server.logger
  @server = amber_server
  super(http_server, @server.site.dest_dir, {:FanyIndexing => true})
end

Instance Method Details

#do_GET(request, response) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/amber/server.rb', line 43

def do_GET(request, response)
  if path_needs_to_be_prefixed?(request.path)
    redirect_with_prefix(request, response)
    return
  end

  path = strip_locale_and_prefix(request.path)

  if renderable_asset?(path)
    @logger.info "Rendering asset file %s" % asset_source_file(path)
    render_asset(path, request, response)
    super(request, response)
  elsif static_file_exists?(request.path)
    @logger.info "Serve static file %s" % static_file_path(request.path)
    super(request, response)
  elsif static_file_exists?(path)
    request = request.clone
    request.instance_variable_set(:@path_info, "/"+path)
    @logger.info "Serve static file with locale prefix %s" % static_file_path(path)
    super(request, response)
  elsif path !~ ASSET_RE
    render_page(path, request, response)
  else
    super(request, response)
  end
end