Class: Tep::Assets

Inherits:
Object
  • Object
show all
Defined in:
lib/tep/assets.rb

Class Method Summary collapse

Class Method Details

._add(path, body, mime) ⇒ Object



28
29
30
# File 'lib/tep/assets.rb', line 28

def self._add(path, body, mime)
  Tep::APP.add_asset(path, body, mime)
end

.has?(path) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/tep/assets.rb', line 32

def self.has?(path)
  Tep::APP.asset_bodies.has_key?(path)
end

.serve(path, res) ⇒ Object

Serve ‘path` if it’s known. Sets Content-Type / body and returns true; returns false if the path isn’t bundled.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tep/assets.rb', line 38

def self.serve(path, res)
  if !Tep::APP.asset_bodies.has_key?(path)
    return false
  end
  res.headers["Content-Type"] = Tep::APP.asset_mimes[path]
  res.headers["Cache-Control"] = "public, max-age=3600"
  # Content-hash ETag (#152): lets the browser revalidate with
  # If-None-Match and get a 304 (handled by the server's
  # Tep::Cache short-circuit) instead of re-downloading the body.
  res.etag(Tep::APP.asset_etags[path])
  res.set_body_if_empty(Tep::APP.asset_bodies[path])
  true
end