Class: Middleman::Extensions::AssetHash::Middleware
- Inherits:
-
Object
- Object
- Middleman::Extensions::AssetHash::Middleware
- Defined in:
- lib/middleman-more/extensions/asset_hash.rb
Overview
The asset hash middleware is responsible for rewriting references to assets to include their new, hashed name.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
59 60 61 62 63 64 65 |
# File 'lib/middleman-more/extensions/asset_hash.rb', line 59 def initialize(app, ={}) @rack_app = app @exts = [:exts] @ignore = [:ignore] @exts_regex_text = @exts.map {|e| Regexp.escape(e) }.join('|') @middleman_app = [:middleman_app] end |
Instance Method Details
#call(env) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/middleman-more/extensions/asset_hash.rb', line 67 def call(env) status, headers, response = @rack_app.call(env) # We don't want to use this middleware when rendering files to figure out their hash! return [status, headers, response] if env["bypass_asset_hash"] == 'true' path = @middleman_app.full_path(env["PATH_INFO"]) if path =~ /(^\/$)|(\.(htm|html|php|css|js)$)/ body = ::Middleman::Util.extract_response_text(response) if body status, headers, response = Rack::Response.new(rewrite_paths(body, path), status, headers).finish end end [status, headers, response] end |