Class: ThemeServer
- Inherits:
-
Object
- Object
- ThemeServer
- Defined in:
- vendor/plugins/themes/lib/theme_server.rb
Overview
Serves theme files from the theme directory without touching Rails too much
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ThemeServer
constructor
A new instance of ThemeServer.
Constructor Details
#initialize(app) ⇒ ThemeServer
Returns a new instance of ThemeServer.
7 8 9 |
# File 'vendor/plugins/themes/lib/theme_server.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'vendor/plugins/themes/lib/theme_server.rb', line 11 def call(env) if env["PATH_INFO"] =~ /^\/theme/ env["PATH_INFO"].gsub!(/^\/theme\//, '') if (file_path = (dir=Rails.root.join("themes", RefinerySetting[:theme])).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 |