class Middleman::HtmlBeautify::Extension::Rack
Constants
- DEFAULT_OPTIONS
Public Class Methods
new(app, options = {})
click to toggle source
# File lib/middleman-html-beautify/extension.rb, line 26 def initialize app, options = {} require 'htmlbeautifier' @app = app @options = DEFAULT_OPTIONS.merge(options) end
Public Instance Methods
call(env)
click to toggle source
# 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