Module: ValidateHTML
- Defined in:
- lib/validate_html.rb,
lib/validate_html/railtie.rb,
lib/validate_html/version.rb,
lib/validate_html/configuration.rb,
lib/validate_html/mailer_observer.rb,
lib/validate_html/rack_middleware.rb,
lib/validate_html/active_support_notification_handler.rb
Overview
Validate HTML as it leaves your rails application
Defined Under Namespace
Modules: ActiveSupportNotificationHandler, MailerObserver Classes: Configuration, Error, InvalidHTMLError, NotRememberingMessagesError, RackMiddleware, Railtie
Constant Summary collapse
- VERSION =
'0.1.0'
Class Attribute Summary collapse
- .configuration ⇒ Configuration readonly
- .remembered_messages ⇒ Array<String> readonly
Class Method Summary collapse
-
.configure {|config| ... } ⇒ void
Configure ValidateHTML.
-
.forget_messages ⇒ void
Clear any remembered messages.
-
.raise_remembered_messages ⇒ void
Raise any remembered messages.
-
.validate_html(html, name: nil, content_type: nil, raise_on_invalid_html: configuration.raise_on_invalid_html?) ⇒ Boolean
Validate the HTML using by parsing it with nokogiri.
Class Attribute Details
.configuration ⇒ Configuration (readonly)
121 122 123 |
# File 'lib/validate_html.rb', line 121 def configuration @configuration ||= Configuration.new end |
.remembered_messages ⇒ Array<String> (readonly)
109 110 111 |
# File 'lib/validate_html.rb', line 109 def @remembered_messages ||= [] end |
Class Method Details
.configure {|config| ... } ⇒ void
This method returns an undefined value.
Configure ValidateHTML
134 135 136 |
# File 'lib/validate_html.rb', line 134 def configure yield configuration end |
.forget_messages ⇒ void
This method returns an undefined value.
Clear any remembered messages
115 116 117 |
# File 'lib/validate_html.rb', line 115 def @remembered_messages = [] end |
.raise_remembered_messages ⇒ void
This method returns an undefined value.
Raise any remembered messages
98 99 100 101 102 103 104 105 |
# File 'lib/validate_html.rb', line 98 def raise NotRememberingMessagesError unless configuration. return if .empty? = raise InvalidHTMLError, .uniq.join("---\n") end |
.validate_html(html, name: nil, content_type: nil, raise_on_invalid_html: configuration.raise_on_invalid_html?) ⇒ Boolean
Validate the HTML using by parsing it with nokogiri
skip any errors matching patterns in ValidateHTML::Configuration#ignored_errors
if there are any errors remaining: remember the errors if ValidateHTML::Configuration#remember_messages is true, save the invalid html into the ValidateHTML::Configuration#snapshot_path directory, and raise InvalidHTMLError with the full messages if raise_on_invalid_html is true or return false
if there are no errors, return true
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/validate_html.rb', line 79 def validate_html(html, name: nil, content_type: nil, raise_on_invalid_html: configuration.raise_on_invalid_html?) return true if html.empty? doc = parse_html(html, find_encoding(content_type)) errors = filter_errors(doc.errors) return true if errors.empty? handle_errors(name, doc, html, errors, raise_on_invalid_html) false end |