Class: SvgConform::Requirements::NoExternalCssRequirement

Inherits:
BaseRequirement
  • Object
show all
Defined in:
lib/svg_conform/requirements/no_external_css_requirement.rb

Overview

Validates that no external CSS references are present

Instance Method Summary collapse

Methods inherited from BaseRequirement

#element?, #get_attribute, #get_attributes, #has_attribute?, #remove_attribute, #set_attribute, #text?, #to_s, #validate_document

Constructor Details

#initialize(*args) ⇒ NoExternalCssRequirement



25
26
27
28
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 25

def initialize(*args)
  super
  @collected_style_elements = []
end

Instance Method Details

#check(node, context) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 30

def check(node, context)
  return unless element?(node)

  case node.name
  when "style"
    check_style_element(node, context) if check_style_elements
  when "link"
    check_link_element(node, context) if check_link_elements
  else
    check_style_attribute(node, context) if check_style_attributes
  end
end

#collect_sax_data(element, _context) ⇒ Object



47
48
49
50
51
52
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 47

def collect_sax_data(element, _context)
  # Collect style elements for deferred validation (text content needs to be complete)
  if check_style_elements && element.name == "style"
    @collected_style_elements << element
  end
end

#needs_deferred_validation?Boolean



43
44
45
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 43

def needs_deferred_validation?
  check_style_elements # Only deferred if checking style elements
end

#should_check_node?(node, context = nil) ⇒ Boolean



67
68
69
70
71
72
73
74
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 67

def should_check_node?(node, context = nil)
  return false unless element?(node)
  return false if context&.node_structurally_invalid?(node)

  node.name == "style" ||
    node.name == "link" ||
    has_style_attribute?(node)
end

#validate_sax_complete(context) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 54

def validate_sax_complete(context)
  # Guard against nil collection
  return unless @collected_style_elements

  # Validate collected style elements
  @collected_style_elements.each do |element|
    check_style_element_sax(element, context)
  end

  # Reset for next validation
  @collected_style_elements = []
end

#validate_sax_element(element, context) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 76

def validate_sax_element(element, context)
  case element.name
  when "style"
    # Style elements handled in deferred validation (need text content)
    # Already collected in collect_sax_data
  when "link"
    check_link_element_sax(element, context) if check_link_elements
  else
    check_style_attribute_sax(element, context) if check_style_attributes
  end
end