Class: Rack::RackDiscount
- Inherits:
-
Object
- Object
- Rack::RackDiscount
- Defined in:
- lib/rack/rdiscount.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ RackDiscount
constructor
A new instance of RackDiscount.
Constructor Details
#initialize(app, options) ⇒ RackDiscount
Returns a new instance of RackDiscount.
8 9 10 11 |
# File 'lib/rack/rdiscount.rb', line 8 def initialize(app, ) @my_path_info = String.new @app = app end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/rdiscount.rb', line 13 def call(env) status, headers, body = @app.call(env) original_response = Array[status, headers, body] excluded_status = Array[204, 301, 302, 304] return original_response if excluded_status.include?(status) || body.nil? return original_response unless headers["Content-Type"].to_s == 'text/plain' mdwn = getResponse(body) body.close if body.respond_to?(:close) newbody = '<div id="page-content">' + RDiscount.new(mdwn).to_html + '</div>' # If we've made it this far, we can alter the headers headers.delete('Content-Length') headers['Content-Length'] = newbody.length.to_s headers.delete('Content-Type') headers['Content-Type'] = 'text/html' [status, headers, newbody] end |