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/
NOT_FOUND_PATH =
"#{PUBLIC_ROOT}/404.html"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



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

def initialize(app)
  @app = app
end

Instance Method Details

#_call(env) ⇒ Object



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

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



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

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