Class: Middleman::Autoprefixer::Extension::Rack
- Inherits:
-
Object
- Object
- Middleman::Autoprefixer::Extension::Rack
- Defined in:
- lib/middleman-autoprefixer/extension.rb
Overview
Rack middleware to look for CSS and apply prefixes.
Constant Summary collapse
- INLINE_CSS_REGEX =
/(<style[^>]*>\s*(?:\/\*<!\[CDATA\[\*\/\n)?)(.*?)((?:(?:\n\s*)?\/\*\]\]>\*\/)?\s*<\/style>)/m
Instance Method Summary collapse
-
#call(env) ⇒ Array
Rack interface.
-
#initialize(app, options = {}) ⇒ Rack
constructor
Init.
Constructor Details
#initialize(app, options = {}) ⇒ Rack
Init
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/middleman-autoprefixer/extension.rb', line 34 def initialize(app, = {}) @app = app @middleman_app = .fetch(:middleman_app) @config = .fetch(:config) @inline = @config[:inline] @ignore = @config[:ignore] @processor = ::AutoprefixerRails::Processor.new({ browsers: @config[:browsers] && Array(@config[:browsers]), add: @config[:add], remove: @config[:remove], grid: @config[:grid], supports: @config[:supports], flexbox: @config[:flexbox] }) end |
Instance Method Details
#call(env) ⇒ Array
Rack interface
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/middleman-autoprefixer/extension.rb', line 54 def call(env) status, headers, response = @app.call(env) type = headers.fetch('Content-Type', 'application/octet-stream').split(';').first path = env['PATH_INFO'] prefixed = process(response, type, path) if prefixed.is_a?(String) headers['Content-Length'] = prefixed.bytesize.to_s response = [prefixed] end [status, headers, response] end |