Class: SvgConform::Remediations::StylePromotionRemediation

Inherits:
BaseRemediation
  • Object
show all
Defined in:
lib/svg_conform/remediations/style_promotion_remediation.rb

Overview

Promotes CSS style properties to individual attributes

Constant Summary collapse

PROMOTABLE_PROPERTIES =

CSS properties that can be promoted to SVG attributes

%w[
  fill stroke stroke-width stroke-opacity stroke-linecap stroke-linejoin
  fill-opacity fill-rule text-anchor font-family font-size font-weight
  font-style opacity visibility display
].freeze

Instance Method Summary collapse

Methods inherited from BaseRemediation

#execute, #should_execute?, #to_s

Instance Method Details

#apply(document, _context) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/svg_conform/remediations/style_promotion_remediation.rb', line 16

def apply(document, _context)
  results = []

  document.xpath("//*[@style]").each do |element|
    style_attr = element["style"]
    next if style_attr.nil? || style_attr.strip.empty?

    promoted_properties = promote_style_properties(element, style_attr)
    promoted_properties.each do |property, value|
      results << create_promotion_result(element, property, value)
    end
  end

  results
end