Module: Middleman::Thumbnailer::Helpers

Defined in:
lib/middleman-thumbnailer/extension.rb

Instance Method Summary collapse

Instance Method Details

#thumbnail(image, name, html_options = {}) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/middleman-thumbnailer/extension.rb', line 71

def thumbnail(image, name, html_options = {})
  specs_for_data_attribute = thumbnail_specs(image, name).map {|name, spec| "#{name}:#{spec[:name]}"}

  html_options.merge!({'data-thumbnails' => specs_for_data_attribute.join('|')}) if Thumbnailer.options[:include_data_thumbnails]

  image_tag(thumbnail_url(image, name), html_options)
end

#thumbnail_specs(image, name) ⇒ Object



57
58
59
60
# File 'lib/middleman-thumbnailer/extension.rb', line 57

def thumbnail_specs(image, name)
  dimensions = Thumbnailer.options[:dimensions]
  ThumbnailGenerator.specs(image, dimensions)
end

#thumbnail_url(image, name, options = {}) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/middleman-thumbnailer/extension.rb', line 62

def thumbnail_url(image, name, options = {})
  include_images_dir = options.delete :include_images_dir

  url = thumbnail_specs(image, name)[name][:name]
  url = File.join(images_dir, url) if include_images_dir

  url
end