Module: Middleman::Presentation::Helpers::Images

Defined in:
lib/middleman/presentation/helpers/images.rb

Overview

Images helpers

Instance Method Summary collapse

Instance Method Details

#find_asset(substring) ⇒ Object

Find asset for substring



28
29
30
31
32
33
34
35
36
37
# File 'lib/middleman/presentation/helpers/images.rb', line 28

def find_asset(substring)
  # sprockets.each_logical_path.find { |f| f.to_s.include? substring }
  result = sprockets.each_file.find { |f| f.to_s.include? substring }

  if result.blank?
    Middleman::Presentation.t('errors.asset_not_found', asset: substring)
  else
    result.relative_path_from(Pathname.new(source_dir)).to_s
  end
end

#image(image) ⇒ Object

Create entry for single image



23
24
25
# File 'lib/middleman/presentation/helpers/images.rb', line 23

def image(image)
  image_gallery Array(image), image_gallery_id: SecureRandom.hex
end

Create image gallery



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/middleman/presentation/helpers/images.rb', line 9

def image_gallery(images, image_gallery_id:)
  template = " <a href=\"<%= image_path %>\" data-lightbox=\"<%= image_gallery_id %>\">\n   <img src=\"<%= image_path %>\"<% if title %> alt=\"<%= title %>\"<% end %> class=\"mp-preview-image\">\n </a>\n  EOS\n\n  images.each_with_object([]) do |(image, title), memo|\n    engine = Erubis::Eruby.new(template)\n    memo << engine.result(image_path: image, image_gallery_id: image_gallery_id, title: title)\n  end.join(\"\\n\")\nend\n".strip_heredoc.chomp