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

Defined Under Namespace

Classes: State

Instance Method Summary collapse

Methods inherited from BaseRequirement

#get_attributes, #skip_attribute_validation?, #to_s, #validate_document

Methods included from Interfaces::RequirementInterface

#reset_state, #to_s, #validate_document

Methods included from NodeHelpers

#element?, #get_attribute, #has_attribute?, #remove_attribute, #set_attribute, #text?

Constructor Details

#initialize(*args) ⇒ NoExternalCssRequirement

Returns a new instance of NoExternalCssRequirement.



33
34
35
36
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 33

def initialize(*args)
  super
  # No instance state - validation state stored in context
end

Instance Method Details

#check(node, context) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 38

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



55
56
57
58
59
60
61
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 55

def collect_sax_data(element, context)
  state = context.state_for(self)
  # Collect style elements for deferred validation (text content needs to be complete)
  if check_style_elements && element.name == "style"
    state.collected_styles << element
  end
end

#needs_deferred_validation?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 51

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

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

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 74

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



63
64
65
66
67
68
69
70
71
72
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 63

def validate_sax_complete(context)
  state = context.state_for(self)
  collected_style_elements = state.collected_styles
  return unless collected_style_elements

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

#validate_sax_element(element, context) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/svg_conform/requirements/no_external_css_requirement.rb', line 83

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(element, context) if check_link_elements
  else
    check_style_attribute(element, context) if check_style_attributes
  end
end