Sha256: 0abf71f884ca25406fd41b6b523f97c1de61d0dcc64ddb40f2d8a5a32dfb836a

Contents?: true

Size: 919 Bytes

Versions: 11

Compression:

Stored size: 919 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/ and (theme = Theme.current_theme(env)).present?
      env["PATH_INFO"].gsub!(/^\/theme\//, '')
      if (file_path = (dir = Rails.root.join("themes", 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

11 entries across 11 versions & 1 rubygems

Version Path
refinerycms-0.9.6.34 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.33 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.32 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.31 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.30 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.29 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.28 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.27 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.26 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.25 vendor/plugins/themes/lib/theme_server.rb
refinerycms-0.9.6.24 vendor/plugins/themes/lib/theme_server.rb