Class: MiddlemanInlineStyle::Rack::Middleware
- Inherits:
-
Object
- Object
- MiddlemanInlineStyle::Rack::Middleware
- Defined in:
- lib/middleman-inline-style/rack-middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, opts = {}) ⇒ Middleware
Returns a new instance of Middleware.
18 19 20 21 22 |
# File 'lib/middleman-inline-style/rack-middleware.rb', line 18 def initialize app, opts = {} @app = app @opts = opts @paths = /^(?:#{ [*opts[:paths]].join('|') })/ end |
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/middleman-inline-style/rack-middleware.rb', line 24 def call env response = @app.call env return response unless @paths === env['PATH_INFO'] status, headers, body = response return response unless headers['Content-Type'] == nil or headers['Content-Type'].start_with?('text/html') newbody = [] body.each { |str| newbody << str } newbody = newbody.join('') newbody = InlineStyle.process(newbody, {:stylesheets_path => "./build/"}.merge(@opts)) headers['Content-Length'] = Rack::Utils.bytesize(newbody).to_s [status, headers, [newbody]] end |