jekyll-srcset-tag 0.1.1 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/jekyll/srcset_tag/image/instance.rb +2 -5
- data/lib/jekyll/srcset_tag/image.rb +7 -12
- data/lib/jekyll/srcset_tag/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4731a5625c94f4612a08a86acb434690e8c2a014
|
4
|
+
data.tar.gz: 01ba9cd52d94b7b1b1aa06e67bd0a8f98b880c6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f870f6dcff942afe51be12973e2baaa5beeb81c902c3682b990240a361c2fc476be7f8dd33739f6f245935af3fe78b8f090ad94b1303aa9700ba45c474185b51
|
7
|
+
data.tar.gz: ac551526bf8d16ca8c2bdfa23855374754ca2475d487c4b24846de803dffaf6a28c3c447b0a27a59ece949294ddab0b6ba68f39775093a36e84bbbfc8d74f576
|
@@ -5,17 +5,14 @@ module Jekyll
|
|
5
5
|
attr_reader :width, :height, :image, :extension, :image_width, :image_height, :output_width, :output_height,
|
6
6
|
:undersized
|
7
7
|
|
8
|
-
def initialize(width:, height:, extension:)
|
8
|
+
def initialize(width:, height:, extension:, image:)
|
9
9
|
@width = width
|
10
10
|
@height = height
|
11
11
|
@extension = extension
|
12
|
-
end
|
13
|
-
|
14
|
-
def for_image!(image)
|
15
12
|
@image = image
|
16
13
|
@image_width = image[:width].to_i
|
17
14
|
@image_height = image[:height].to_i
|
18
|
-
calculate_output_dimensions!
|
15
|
+
calculate_output_dimensions!
|
19
16
|
end
|
20
17
|
|
21
18
|
def filename
|
@@ -20,15 +20,8 @@ module Jekyll
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def generate_images!
|
23
|
-
|
24
|
-
|
25
|
-
instances.each { |instance| instance.for_image!(original) }
|
26
|
-
resize_images! uniq_instances, original
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def images_exist?
|
31
|
-
Dir.exist? output_dir
|
23
|
+
needed_instances = uniq_instances.select { |instance| !File.exist?(File.join(output_dir, instance.filename)) }
|
24
|
+
resize_images! needed_instances
|
32
25
|
end
|
33
26
|
|
34
27
|
def instances
|
@@ -71,10 +64,12 @@ module Jekyll
|
|
71
64
|
all_sources = sources.map do |source|
|
72
65
|
reverse_ppi.map { |ppi| [source, ppi] }
|
73
66
|
end.flatten(1)
|
67
|
+
original = MiniMagick::Image.open File.join(source_path, image_path)
|
74
68
|
all_sources.map do |(source, ppi)|
|
75
69
|
Instance.new width: (source.width ? (source.width.to_f * ppi).round : nil),
|
76
70
|
height: (source.height ? (source.height.to_f * ppi).round : nil),
|
77
|
-
extension: File.extname(image_path)
|
71
|
+
extension: File.extname(image_path),
|
72
|
+
image: original
|
78
73
|
end
|
79
74
|
end
|
80
75
|
|
@@ -88,13 +83,13 @@ module Jekyll
|
|
88
83
|
sources.map { |source| source.size_string }
|
89
84
|
end
|
90
85
|
|
91
|
-
def resize_images!(instances
|
86
|
+
def resize_images!(instances)
|
92
87
|
if instances.any? { |i| i.undersized }
|
93
88
|
warn "Warning:".yellow + " #{image_path} is smaller than the requested output file. " +
|
94
89
|
"It will be resized without upscaling."
|
95
90
|
end
|
96
91
|
instances.each do |instance|
|
97
|
-
Resizer::resize(
|
92
|
+
Resizer::resize(instance.image, output_dir, instance.filename, instance.output_width, instance.output_height)
|
98
93
|
puts "Generated #{File.join(output_dir, instance.filename)}"
|
99
94
|
end
|
100
95
|
end
|