class Middleman::Extensions::MinifyCss::Rack
Rack
middleware to look for CSS and compress it
Constants
- INLINE_CSS_REGEX
Public Class Methods
new(app, options={})
click to toggle source
Init @param [Class] app @param [Hash] options
# File lib/middleman-more/extensions/minify_css.rb, line 37 def initialize(app, options={}) @app = app @compressor = options[:compressor] @ignore = options[:ignore] @inline = options[:inline] end
Public Instance Methods
call(env)
click to toggle source
Rack
interface @param [Rack::Environmemt] env @return [Array]
# File lib/middleman-more/extensions/minify_css.rb, line 47 def call(env) status, headers, response = @app.call(env) if inline_html_content?(env['PATH_INFO']) minified = ::Middleman::Util.extract_response_text(response) minified.gsub!(INLINE_CSS_REGEX) do $1 << @compressor.compress($2) << $3 end headers['Content-Length'] = ::Rack::Utils.bytesize(minified).to_s response = [minified] elsif standalone_css_content?(env['PATH_INFO']) minified_css = @compressor.compress(::Middleman::Util.extract_response_text(response)) headers['Content-Length'] = ::Rack::Utils.bytesize(minified_css).to_s response = [minified_css] end [status, headers, response] end
Private Instance Methods
inline_html_content?(path)
click to toggle source
# File lib/middleman-more/extensions/minify_css.rb, line 70 def inline_html_content?(path) (path.end_with?('.html') || path.end_with?('.php')) && @inline end
standalone_css_content?(path)
click to toggle source
# File lib/middleman-more/extensions/minify_css.rb, line 74 def standalone_css_content?(path) path.end_with?('.css') && @ignore.none? { |ignore| Middleman::Util.path_match(ignore, path) } end