Friday, 23 August 2013

Rack middleware to join HTML output

Rack middleware to join HTML output

How do I join my HTML output using a Rack middleware?
I can't make the below work:
class JoinHtmlOutput
def initialize(app)
@app = app
end
def call(env)
# Call the underlying application, return a standard Rack response
status, headers, response = @app.call(env)
# Join the HTML
if headers['Content-Type'] =~ /text\/html/
response.each do |chunk|
chunk.gsub(/[\r\n]+/, '').gsub(/>\s+/, '>').gsub(/>\s+</,
'><').gsub(/; \s+/, '; ').gsub(/{ \s+/, '{ ')
end
end
# Return the new Rack response
[status, headers, response]
end
end

No comments:

Post a Comment