Class: Middleman::Extensions::MinifyCss::Rack
- Inherits:
-
Object
- Object
- Middleman::Extensions::MinifyCss::Rack
- Extended by:
- Memoist
- Includes:
- Contracts
- Defined in:
- lib/middleman-core/extensions/minify_css.rb
Overview
Rack middleware to look for CSS and compress it
Constant Summary collapse
- INLINE_CSS_REGEX =
/(<style[^>]*>\s*(?:\/\*<!\[CDATA\[\*\/\n)?)(.*?)((?:(?:\n\s*)?\/\*\]\]>\*\/)?\s*<\/style>)/m
Constants included from Contracts
Instance Method Summary collapse
-
#call(env) ⇒ Array
Rack interface.
-
#initialize(app, options = {}) ⇒ Rack
constructor
A new instance of Rack.
Methods included from Contracts
Constructor Details
#initialize(app, options = {}) ⇒ Rack
Returns a new instance of Rack.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/middleman-core/extensions/minify_css.rb', line 49 def initialize(app, ={}) @app = app @ignore = .fetch(:ignore) @inline = .fetch(:inline) @compressor = .fetch(:compressor) @compressor = @compressor.to_proc if @compressor.respond_to? :to_proc @compressor = @compressor.call if @compressor.is_a? Proc @content_types = [:content_types] @inline_content_types = [:inline_content_types] end |
Instance Method Details
#call(env) ⇒ Array
Rack interface
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/middleman-core/extensions/minify_css.rb', line 64 def call(env) status, headers, response = @app.call(env) content_type = headers['Content-Type'].try(:slice, /^[^;]*/) path = env['PATH_INFO'] minified = if @inline && minifiable_inline?(content_type) minify_inline(::Middleman::Util.extract_response_text(response)) elsif minifiable?(content_type) && !ignore?(path) minify(::Middleman::Util.extract_response_text(response)) end if minified headers['Content-Length'] = minified.bytesize.to_s response = [minified] end [status, headers, response] end |