-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheckImages.rb
30 lines (28 loc) · 989 Bytes
/
checkImages.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
re = Regexp.new("\.adoc$") # asciidoc source file
dir = Dir.new('.')
dir.each {|fn|
if ( fn =~ re ) then
print "----------------------------------\n"
print "asciidoc source : " + fn + "\n"
paths = []
imagesDirs = [] # can be many by error => we take the last only
imagesDir = ""
# find all image: or image:: asciidoc macros
File.open(fn) { |f|
content = f.read
imagesDirs = content.scan(/:images: (.*)/)
paths = content.scan(/image::?([^\[ ]+)\[/)
}
imagesDir="images"
# test that path is a file
paths.flatten.each {|path|
if (data = /({images}).*/.match(path))
oldpath=path
path=path.gsub("{images}",imagesDir)
print (File.file?("images/"+path) ? " OK " : " NOK ") + oldpath + "\n"
else
print (File.file?("images/"+path) ? " OK " : " NOK ") + path + "\n"
end
}
end
}