Class: Middleman::HtmlBeautify::Extension::Rack
- Inherits:
-
Object
- Object
- Middleman::HtmlBeautify::Extension::Rack
- Defined in:
- lib/middleman-html-beautify/extension.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ keep_blank_lines: 0, indent: ' ', initial_level: 0, stop_on_errors: false }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app, options = {}) ⇒ Rack
Returns a new instance of Rack.
26 27 28 29 30 31 32 |
# File 'lib/middleman-html-beautify/extension.rb', line 26 def initialize app, = {} require 'htmlbeautifier' @app = app @options = DEFAULT_OPTIONS.merge() end |
Instance Method Details
#call(env) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/middleman-html-beautify/extension.rb', line 34 def call env status, headers, body = @app.call(env) if headers.key? 'Content-Type' and headers['Content-Type'] =~ /html/ content = '' body.each do |part| content << part end content = HtmlBeautifier.beautify(content, @options) headers['Content-Length'] = content.bytesize.to_s if headers['Content-Length'] [status, headers, [content]] else [status, headers, body] end ensure body.close if body.respond_to?(:close) end |