jsduck 4.6.1 → 4.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,72 +0,0 @@
1
- require "jsduck/logger"
2
- require "fileutils"
3
-
4
- module JsDuck
5
-
6
- # Looks up images from directories specified through --images option.
7
- class Images
8
- def initialize(paths)
9
- @paths = scan_for_images(paths)
10
- @images = {}
11
- end
12
-
13
- # Scans each path for image files, building a hash of paths where
14
- # each path points to a hash of image files found in that path.
15
- def scan_for_images(paths)
16
- map = {}
17
- paths.each do |path|
18
- # Scans directory for image files
19
- map[path] = {}
20
- Dir[path+"/**/*.{png,jpg,jpeg,gif}"].each do |img|
21
- map[path][img] = false
22
- end
23
- end
24
- map
25
- end
26
-
27
- # Adds relative image path of an image
28
- def add(filename)
29
- unless @images[filename]
30
- @images[filename] = true
31
- end
32
- end
33
-
34
- # Copys over images to given output dir
35
- def copy(output_dir)
36
- @images.each_key do |img|
37
- unless copy_img(img, output_dir)
38
- Logger.warn(:image, "Image not found.", img)
39
- end
40
- end
41
- report_unused
42
- end
43
-
44
- # Attempts to copy one image, returns true on success
45
- def copy_img(img, output_dir)
46
- @paths.each_pair do |path, map|
47
- filename = path + "/" + img
48
- if map.has_key?(filename)
49
- dest = output_dir + "/" + img
50
- Logger.log("Copying image", dest)
51
- FileUtils.makedirs(File.dirname(dest))
52
- FileUtils.cp(filename, dest)
53
- # mark file as used.
54
- map[filename] = true
55
- return true
56
- end
57
- end
58
- return false
59
- end
60
-
61
- # Report unused images
62
- def report_unused
63
- @paths.each_pair do |path, map|
64
- map.each_pair do |img, used|
65
- Logger.warn(:image_unused, "Image not used.", img) unless used
66
- end
67
- end
68
- end
69
-
70
- end
71
-
72
- end