Module: SrcsetImages::ViewHelpers
- Defined in:
- lib/middleman-srcset_images/view_helpers.rb
Instance Method Summary collapse
-
#image_tag(path, options = {}) ⇒ Object
options can be:.
Instance Method Details
#image_tag(path, options = {}) ⇒ Object
options can be:
size: pick an image version link: Set to an url to link to
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/middleman-srcset_images/view_helpers.rb', line 11 def image_tag(path, = {}) # allow for images in article directories to be referenced just by file name unless path[?/] page_path = current_page.path dir = File.dirname page_path path = File.join dir, File.basename(page_path, '.html'), path end # collect srcset info = .dup ext = app.extensions[:srcset_images] rel_path = path.sub(/\A\/?/, "") versions = nil if size = .delete(:size) [:sizes] = ext.sizes[size] scaled_images = ext.scaled_images[rel_path] versions = scaled_images.select{|v| v.name == size.to_s} unless versions.any? versions = scaled_images.select{|v| v.default_for_orientation?} end if versions.any? path = (versions.detect{|v|v.default?} || versions.first).resized_img_path [:srcset] = versions.map { |v| "#{v.resized_img_path} #{v.width}w" }.join ", " end end link = .delete(:link) img = super path, if link link_to img, link else img end end |