Class: Markitup::Middleware
- Inherits:
-
Struct
- Object
- Struct
- Markitup::Middleware
- Defined in:
- lib/markitup/middleware.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app
4 5 6 |
# File 'lib/markitup/middleware.rb', line 4 def app @app end |
#options ⇒ Object
Returns the value of attribute options
4 5 6 |
# File 'lib/markitup/middleware.rb', line 4 def end |
Instance Method Details
#call(env) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/markitup/middleware.rb', line 6 def call(env) return app.call(env) unless config['enabled'] # if env["REQUEST_METHOD"] == "POST" # return render(:markdown, env) if env["PATH_INFO"] =~ /^\/markitup\/markdown/ # end status, headers, response = app.call(env) return [ status, headers, response ] unless headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/ body = "" response.each { |part| body << part } return [ status, headers, response ] unless body =~ /#{config['keyword']}/ index = body.rindex "</head>" if index body.insert index, styles + scripts headers["Content-Length"] = body.length.to_s response = [ body ] end [ status, headers, response ] end |