Class: Rack::Tidy::Cleaner
- Inherits:
-
Object
- Object
- Rack::Tidy::Cleaner
- Defined in:
- lib/rack/tidy/cleaner.rb
Overview
This class is the interface between Rack and the Tidy gem
Constant Summary collapse
- DEFAULT_TIDY_OPTS =
Defaults for the Tidy gem config
{ 'char-encoding' => 'utf8', 'indent' => true, 'indent-spaces' => 2, 'tidy-mark' => false, 'wrap' => 0 }
Instance Attribute Summary collapse
-
#ignore_paths ⇒ Object
Paths to be ignored during Rack::Tidy processing.
-
#tidy_options ⇒ Object
Tidy gem options, see tidy.sourceforge.net/docs/quickref.html.
Instance Method Summary collapse
-
#call(env) ⇒ Object
method required by Rack interface.
-
#call!(env) ⇒ Object
thread safe version using shallow copy of env.
-
#initialize(app, options = {}) ⇒ Cleaner
constructor
A new instance of Cleaner.
Constructor Details
#initialize(app, options = {}) ⇒ Cleaner
Returns a new instance of Cleaner.
21 22 23 24 25 26 |
# File 'lib/rack/tidy/cleaner.rb', line 21 def initialize(app, = {}) ::Tidy.path = TIDY_LIB @app = app self.ignore_paths = [:ignore_paths] || [] self. = DEFAULT_TIDY_OPTS.merge() end |
Instance Attribute Details
#ignore_paths ⇒ Object
Paths to be ignored during Rack::Tidy processing
19 20 21 |
# File 'lib/rack/tidy/cleaner.rb', line 19 def ignore_paths @ignore_paths end |
#tidy_options ⇒ Object
Tidy gem options, see tidy.sourceforge.net/docs/quickref.html
16 17 18 |
# File 'lib/rack/tidy/cleaner.rb', line 16 def @tidy_options end |
Instance Method Details
#call(env) ⇒ Object
method required by Rack interface
29 30 31 |
# File 'lib/rack/tidy/cleaner.rb', line 29 def call(env) call! env end |
#call!(env) ⇒ Object
thread safe version using shallow copy of env
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rack/tidy/cleaner.rb', line 34 def call!(env) @env = env.dup status, @headers, response = @app.call(@env) if should_clean? @headers.delete('Content-Length') response = Rack::Response.new( tidy_markup(response.respond_to?(:body) ? response.body : response), status, @headers ) response.finish response.to_a else [status, @headers, response] end end |