Class: Rack::TidyResponse

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

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ TidyResponse

Returns a new instance of TidyResponse.



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

def initialize(body)
  @body = body
  ::Tidy.path = '/usr/lib/libtidy.A.dylib'
end

Instance Method Details

#to_sObject



11
12
13
14
15
16
17
# File 'lib/rack/tidy_response.rb', line 11

def to_s
  tidy = Tidy.open

  tidy.clean(@body)

  tidy.errors.join("<br />") + @body
end

#w3c_errorsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rack/tidy_response.rb', line 19

def w3c_errors
  response = Net::HTTP.post_form(
    URI.parse("http://validator.w3.org/check"),
    {
      'ss'=>0,
      'fragment'=>@body
    }
  )
  status = response['x-w3c-validator-status']
  if status != 'Valid'
    response.body
  else
    nil
  end
end