Class: Rack::Pygmentize

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

Instance Method Summary collapse

Constructor Details

#initialize(app, xpath = "//pre[@lang]") ⇒ Pygmentize

Returns a new instance of Pygmentize.



7
8
9
# File 'lib/rack/pygmentize.rb', line 7

def initialize(app, xpath="//pre[@lang]")
  @app, @xpath = app, xpath
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
# File 'lib/rack/pygmentize.rb', line 11

def call(env)
  dup.call!(env)
end

#call!(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rack/pygmentize.rb', line 15

def call!(env)
  @env = env.dup
  status, headers, body = @app.call(@env)

  if headers['Content-Type'] && headers['Content-Type'].include?('text/html')
    headers.delete('Content-Length')
    Rack::Response.new(parse(body), status, headers).finish
  else
    [status, headers, body]
  end
end