Class: Uniword::Validation::Rules::ImagesRule
- Inherits:
-
Base
- Object
- Base
- Uniword::Validation::Rules::ImagesRule
show all
- Defined in:
- lib/uniword/validation/rules/images_rule.rb
Overview
Validates image/media references.
DOC-050: Image relationship targets exist in word/media/ DOC-051: Image content types match file extensions DOC-052: blip embed references resolve to image parts
Constant Summary
collapse
- R_NS =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"
- A_NS =
"http://schemas.openxmlformats.org/drawingml/2006/main"
- IMAGE_TYPES =
%w[
image/png image/jpeg image/gif image/tiff
image/bmp image/svg+xml image/emf image/wmf
].freeze
Instance Method Summary
collapse
Methods inherited from Base
#description, #validity_rule
Instance Method Details
#applicable?(context) ⇒ Boolean
26
27
28
|
# File 'lib/uniword/validation/rules/images_rule.rb', line 26
def applicable?(context)
context.part_exists?("word/document.xml")
end
|
#category ⇒ Object
23
|
# File 'lib/uniword/validation/rules/images_rule.rb', line 23
def category = :images
|
#check(context) ⇒ Object
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
57
58
59
60
|
# File 'lib/uniword/validation/rules/images_rule.rb', line 30
def check(context)
issues = []
rels = context.relationships
rels_by_id = rels.to_h { |r| [r[:id], r] }
image_rels = rels.select { |r| r[:type]&.include?("image") }
image_rels.each do |rel|
target = rel[:target]
next unless target
target_path = target.start_with?("/") ? target[1..] : "word/#{target}"
next if context.part_exists?(target_path)
issues << issue(
"Image target '#{target_path}' not found in package",
part: "word/_rels/document.xml.rels",
suggestion: "Add the image file '#{target_path}' to the " \
"package, or remove the relationship.",
)
end
check_image_content_types(context, image_rels, issues)
check_blip_refs(context, rels_by_id, issues)
issues
end
|
#code ⇒ Object
22
|
# File 'lib/uniword/validation/rules/images_rule.rb', line 22
def code = "DOC-050"
|
#severity ⇒ Object
24
|
# File 'lib/uniword/validation/rules/images_rule.rb', line 24
def severity = "error"
|