Class: Uniword::Validation::Rules::ThemeRule

Inherits:
Base
  • Object
show all
Defined in:
lib/uniword/validation/rules/theme_rule.rb

Overview

Validates theme references.

DOC-080: Theme relationship exists if theme colors/fonts referenced DOC-081: Theme part is well-formed DrawingML

Constant Summary collapse

W_NS =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main"
A_NS =
"http://schemas.openxmlformats.org/drawingml/2006/main"

Instance Method Summary collapse

Methods inherited from Base

#description, #validity_rule

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/uniword/validation/rules/theme_rule.rb', line 20

def applicable?(context)
  context.part_exists?("word/document.xml")
end

#categoryObject



17
# File 'lib/uniword/validation/rules/theme_rule.rb', line 17

def category = :theme

#check(context) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/uniword/validation/rules/theme_rule.rb', line 24

def check(context)
  issues = []
  doc = context.document_xml
  return issues unless doc

  # Check if theme attributes are used
  uses_theme = doc.root.xpath(".//@w:val",
                              "w" => W_NS).any? do |attr|
    attr.value&.start_with?("theme")
  end

  has_theme_rels = context.relationships.any? do |r|
    r[:type]&.include?("theme")
  end

  # DOC-080: Theme referenced but not available
  if uses_theme && !has_theme_rels && !context.part_exists?("word/theme/theme1.xml")
    issues << issue(
      "Document uses theme colors/fonts but no theme relationship exists",
      part: "word/document.xml",
      suggestion: "Add a theme relationship in document.xml.rels " \
                  "pointing to word/theme/theme1.xml.",
    )
  end

  # DOC-081: Theme part well-formed
  if context.part_exists?("word/theme/theme1.xml")
    check_theme_well_formed(context,
                            issues)
  end

  issues
end

#codeObject



16
# File 'lib/uniword/validation/rules/theme_rule.rb', line 16

def code = "DOC-080"

#severityObject



18
# File 'lib/uniword/validation/rules/theme_rule.rb', line 18

def severity = "warning"