Class: Polites::Nanoc::EmbeddedImagesFilter

Inherits:
Nanoc::Filter
  • Object
show all
Defined in:
lib/polites/nanoc/embedded_images_filter.rb

Overview

Nanoc filter for replacing the Polites-generated filename to images with actual output filenames as generated by Nanoc.

Instance Method Summary collapse

Instance Method Details

#run(content, _params = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/polites/nanoc/embedded_images_filter.rb', line 10

def run(content, _params = {})
  return content unless @item[:inline_file_items]&.any?

  @item[:inline_file_items].inject(content) do |acc, inline_file_item|
    actual_item = @items.find do |item|
      item.attributes[:id] == inline_file_item.attributes[:id]
    end
    acc.gsub(/(?<=src=")(#{actual_item.attributes[:explicit_filename]}|#{actual_item.attributes[:id]})(?=")/, actual_item.path)
  end
end