Class: Rack::Escapee
- Inherits:
-
Object
- Object
- Rack::Escapee
- Defined in:
- lib/rack/escapee.rb
Constant Summary collapse
- ESCAPED_TAG =
/(<\w+>)/
- ESCAPED_ENTITY =
/(&\w+;)/
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Escapee
constructor
A new instance of Escapee.
Constructor Details
#initialize(app, options = {}) ⇒ Escapee
Returns a new instance of Escapee.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rack/escapee.rb', line 9 def initialize(app, = {}) @app = app @options = { :logfile => false, :entities => false }.merge() if @options[:logfile] @logger = ::Logger.new(@options[:logfile]) else @logger = ::Logger.new(STDOUT) end @logger.datetime_format = "%Y-%m-%d %H:%M:%S" end |
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rack/escapee.rb', line 24 def call(env) req = Request.new(env) path = req.path_info status, headers, response = @app.call(env) response_body = [] response.each do |part| if part =~ ESCAPED_TAG @logger.warn("rendering escaped tag: #{$1}") elsif part =~ ESCAPED_ENTITY && @options[:entities] @logger.warn("rendering escaped entity: #{$1}") end response_body << part end [status, headers, response_body] end |