Class: Jammit::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/jammit/middleware.rb

Overview

Rack Middle that allows Jammit to integrate with any Rack compatible web framework. It takes responsibility for /assets, and dynamically packages any missing or uncached asset packages.

Constant Summary collapse

VALID_FORMATS =
[:css, :js]
SUFFIX_STRIPPER =
/-(datauri|mhtml)\Z/
PUBLIC_ROOT =
defined?(Jammit.public_root) ? Jammit.public_root : PUBLIC_ROOT
NOT_FOUND_PATH =
"#{PUBLIC_ROOT}/404.html"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



16
17
18
# File 'lib/jammit/middleware.rb', line 16

def initialize(app)
  @app = app
end

Instance Method Details

#_call(env) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/jammit/middleware.rb', line 24

def _call(env)
  if matches = %r(^/#{Jammit.package_path}/(.*)\.(.*)).match(env['PATH_INFO'])
    package(matches[1].to_s, matches[2] || "none")
  else
    @app.call(env)
  end
end

#call(env) ⇒ Object



20
21
22
# File 'lib/jammit/middleware.rb', line 20

def call(env)
  dup._call(env)
end