Module: Kitchen::Directions::BakeImages

Defined in:
lib/kitchen/directions/bake_images.rb

Class Method Summary collapse

Class Method Details

.v1(book:, resources:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kitchen/directions/bake_images.rb', line 6

def self.v1(book:, resources:)
  # Add image dimensions to <img>s
  book.images.each do |image|
    img_src = image.resource_key
    img_json = resources&.[](img_src)
    if img_json
      scale = \
        if image[:width]
          image[:width].to_f / img_json[:width].to_i
        elsif image[:height]
          image[:height].to_f / img_json[:height].to_i
        else
          1
        end
      image[:width] = (img_json[:width].to_i * scale).floor
      image[:height] = (img_json[:height].to_i * scale).floor
    else
      warn("Could not find resource for image with src #{image.src}")
    end
  end
end