jekyll-srcset-tag 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 876700adecc1986ddfeeabf56466422a3c5a5a7f
4
- data.tar.gz: 57828f6f5c9f9a17fa257a547aa2699a1a4cab6f
3
+ metadata.gz: 4731a5625c94f4612a08a86acb434690e8c2a014
4
+ data.tar.gz: 01ba9cd52d94b7b1b1aa06e67bd0a8f98b880c6a
5
5
  SHA512:
6
- metadata.gz: be076b1d033beb25700ef300aa4601d8c8564b65fa0ac5b88d45874bbed9f28d760d19e97de73aa32fa01d4ae871cba2e2ccd3b9320004969be714f4444bb256
7
- data.tar.gz: df4c246c0057c60e78314a85f9795d47eef42f0260e85fe6a386f3b9a47e707df2381238963dc01af4e69d867d0920caf9544b978b2a64e903140e92207d01d0
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
- unless images_exist?
24
- original = MiniMagick::Image.open File.join(source_path, image_path)
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, original)
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(original, output_dir, instance.filename, instance.output_width, instance.output_height)
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
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module SrcsetTag
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-srcset-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Dew