Question

The application I'm working on allows users to upload HTML templates with CSS, which the app then processes out for various tasks. The upload process works fine, but I'm trying to find a way to validate the HTML and CSS files that get uploaded. I've found several gems and plugins that are meant to be integrated into unit tests (such as https://github.com/realityforge/rails-assert-valid-asset), but I'm looking for something I can run the files against on upload (in a production environment).

Does something like this exist?

Thanks

Était-ce utile?

La solution

You should be able to use the World Wide Web Consortium’s online validation service through the w3c_validators gem: https://github.com/alexdunae/w3c_validators .

Here's an example from the Readme for CSS:

require 'w3c_validators'

include W3CValidators

@validator = CSSValidator.new

results = @validator.validate_text('body { margin: 0px; }')

if results.errors.length > 0
  results.errors.each do |err|
    puts err.to_s
  end
else
  puts 'Valid!'
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top