Sha256: 2a47d5f5be3f39474fdcc3884149f8b476006941b35adfed63cd5716152ee354

Contents?: true

Size: 886 Bytes

Versions: 3

Compression:

Stored size: 886 Bytes

Contents

# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)

# Serves theme files from the theme directory without touching Rails too much
class ThemeServer

  def initialize(app)
    @app = app
  end

  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

end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
jacobat-refinerycms-0.9.6.14 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.14 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.13 vendor/plugins/themes/lib/theme_server.rb