Class: NakedRack

Inherits:
Object
  • Object
show all
Defined in:
lib/naked_rack.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{ :display_banner => true, :remove_js => false, :permanent => false }

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ NakedRack



7
8
9
10
# File 'lib/naked_rack.rb', line 7

def initialize(app, options={})
  @app = app
  @options = options.reverse_merge(DEFAULT_OPTIONS)
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/naked_rack.rb', line 12

def call(env)
  return @app.call(env) unless today_is_naked_css_day? or @options[:permanent]
  status, headers, response = @app.call(env)
  body = ''
  response.each do |str|
    body = remove_link_tags(str).to_html
    body = remove_style_tags(body).to_html
    body = remove_js_tags(body).to_html if @options[:remove_js]
  end
  headers['Content-Length'] = body.length.to_s
  [status, headers, body]
end