Class: Refinery::ThemeServer

Inherits:
Object
  • Object
show all
Defined in:
lib/refinery/theme_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ThemeServer

Returns a new instance of ThemeServer.



5
6
7
# File 'lib/refinery/theme_server.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/refinery/theme_server.rb', line 9

def call(env)
  if env["PATH_INFO"] =~ /^\/theme\/(stylesheets|javascripts|images)/ and (theme = Theme.current_theme(env)).present?
    env["PATH_INFO"].gsub!(/^\/theme\//, '')
    if (file_path = (dir = Theme.current_theme_dir).join(env["PATH_INFO"])).exist?
      etag = Digest::MD5.hexdigest("#{file_path.to_s}#{file_path.mtime}")
      unless (etag == env["HTTP_IF_NONE_MATCH"])
        status, headers, body = Rack::File.new(dir).call(env)
        [status, headers.update({"ETag" => etag}), body]
      else
        [304, {"ETag" => etag}, []]
      end
    else
      [404, {}, []]
    end
  else
    @app.call(env)
  end
end