Skip to content
Snippets Groups Projects
gallery.rb 542 B
Newer Older
Arnaud Levy's avatar
Arnaud Levy committed
class Communication::Block::Template::Gallery < Communication::Block::Template
  def build_git_dependencies
    add_dependency images
  end

  def images_with_alt
Arnaud Levy's avatar
Arnaud Levy committed
    @images_with_alt ||= elements.map { |element| image_with_alt(element) }
                                 .compact
Arnaud Levy's avatar
Arnaud Levy committed
  end

Arnaud Levy's avatar
Arnaud Levy committed
  def image_with_alt(element)
    blob = find_blob element, 'file'
    return if blob.nil?
    {
      blob: blob,
      alt: element['alt']
    }.to_dot
  end

Arnaud Levy's avatar
Arnaud Levy committed
  def images
    @images ||= images_with_alt.map { |hash| hash.blob }
Arnaud Levy's avatar
Arnaud Levy committed
  end
end