Class: HtmlMockupAutoprefixer::Middleware
- Inherits:
-
Object
- Object
- HtmlMockupAutoprefixer::Middleware
- Defined in:
- lib/html_mockup-autoprefixer/middleware.rb
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.
3 4 5 6 7 8 |
# File 'lib/html_mockup-autoprefixer/middleware.rb', line 3 def initialize(app, ={}) @app = app @options = { :skip => [] }.update() end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/html_mockup-autoprefixer/middleware.rb', line 10 def call(env) status, headers, body = @app.call(env) if status == 200 && headers["Content-Type"].to_s.include?("text/css") && !@options[:skip].detect{|r| r.match(env["PATH_INFO"]) } body_str = [] body.each{|f| body_str << f } body_str = body_str.join # This is a dirty little hack to always enforce UTF8 body_str.force_encoding("UTF-8") Rack::Response.new(AutoprefixerRails.compile(body_str), status, headers).finish else [status, headers, body] end end |