Class: Asset::Router
- Inherits:
-
Object
- Object
- Asset::Router
- Defined in:
- lib/assets/router.rb
Constant Summary collapse
- MIME =
Mime types
{ 'js' => 'application/javascript; charset=UTF-8', 'css' => 'text/css; charset=UTF-8', 'txt' => 'text/plain; charset=UTF-8' }
Instance Method Summary collapse
-
#call(env) ⇒ Object
Call.
-
#initialize(app) ⇒ Router
constructor
Init.
Constructor Details
#initialize(app) ⇒ Router
Init
12 13 14 |
# File 'lib/assets/router.rb', line 12 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
Call
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/assets/router.rb', line 17 def call(env) # Setting up request @request = Rack::Request.new(env) # The routes case @request.path_info # Match /assets?/:type/path when /^(\/assets)?\/(js|css)\/(.+)/ type, path = $2, $3 path =~ /(-[a-f0-9]{1,32})/ path = path.gsub($1, '') if $1 item = ::Asset.manifest.find{|i| i.path == path and i.type == type} # Not found if no item, wrong key or no content return not_found if !item or ($1 and $1 != item.key) or !item.content(!!$1) found(item) # Bounce favicon requests when /^\/favicon\.ico$/ not_found # Return a standard robots.txt when /^\/robots\.txt$/ robots else # No routes found, pass down the middleware stack @app.call(env) end end |