class Checker::CSS
Constants
- COMMA_SEPARATED_INSPECTION_REGEX
- CSS_VALID_VALUE
Public Class Methods
comma_separated_values_match?(inspection_value, actual_value)
click to toggle source
# File lib/checker/css.rb, line 88 def self.comma_separated_values_match?(inspection_value, actual_value) inspection_value.comma_separated_words == actual_value.comma_separated_words end
inspect(parser, inspection, binding)
click to toggle source
# File lib/checker/css.rb, line 52 def self.inspect(parser, inspection, binding) case inspection.target.to_s.split(':').size when 0 then inspect_selector(parser, inspection, binding) when 1 then inspect_property(parser, inspection, binding) when 2 then inspect_property_and_value(parser, inspection, binding) else raise "Malformed target value." end end
inspect_property(parser, inspection, binding)
click to toggle source
# File lib/checker/css.rb, line 65 def self.inspect_property(parser, inspection, binding) property, _ = parse_target(inspection.target) parser.dig(binding, property).present? end
inspect_property_and_value(parser, inspection, binding)
click to toggle source
# File lib/checker/css.rb, line 70 def self.inspect_property_and_value(parser, inspection, binding) property, value = parse_target(inspection.target) actual_value = parser.dig(binding, property) || '' values_match? value, actual_value end
inspect_selector(parser, inspection, binding)
click to toggle source
# File lib/checker/css.rb, line 61 def self.inspect_selector(parser, inspection, binding) parser.dig(binding).present? end
parse_target(target)
click to toggle source
# File lib/checker/css.rb, line 84 def self.parse_target(target) target.to_s.split(':') end
run(document, expectation, binding)
click to toggle source
# File lib/checker/css.rb, line 43 def self.run(document, expectation, binding) content = document.xpath('//style').text.presence || document.text inspection = expectation.inspection parser = CssParser::Parser.new parser.load_string! content raise "Unsupported inspection #{inspection.type}" unless ['DeclaresStyle', 'DeclaresStyle:'].include? inspection.type inspect parser, inspection, binding end
values_match?(inspection_value, actual_value)
click to toggle source
# File lib/checker/css.rb, line 76 def self.values_match?(inspection_value, actual_value) if inspection_value =~ COMMA_SEPARATED_INSPECTION_REGEX comma_separated_values_match? inspection_value, actual_value else actual_value.css_values.include? inspection_value end end