Sha256: 3f6d41dc7151a9401e44b42f7ec3d6f2e74d89dab21e951b9b798df17170b055

Contents?: true

Size: 642 Bytes

Versions: 1

Compression:

Stored size: 642 Bytes

Contents

require 'rack/request'
require 'rack/response'
require File.dirname(__FILE__) + "/w3c_validator"

module RogerW3cvalidator
  class Middleware
    def initialize(app)
      @app = app
    end
    
    def call(env)
      resp = @app.call(env)
      if resp[1]["Content-Type"].to_s.include?("html")
        str = ""
        resp[2].each{|c| str << c}
        validator = W3CValidator.new(str)
        validator.validate!
        if !validator.valid
          env["rack.errors"].puts "Validation failed on #{env["PATH_INFO"]}: (errors: #{validator.errors}, warnings: #{validator.warnings})"
        end
      end
      resp
    end    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roger_w3cvalidator-0.1.0 lib/roger_w3cvalidator/middleware.rb