Sha256: 879bf8d21c120d52bfc509e871133ff2dc73bce47c20a6a885b8d98018d5895e
Contents?: true
Size: 1.7 KB
Versions: 2
Compression:
Stored size: 1.7 KB
Contents
module Storefront module ImageHelper def image_tag(source, options = {}) options.symbolize_keys! src = options[:src] = path_to_image(source) unless src =~ /^cid:/ options[:alt] = options.fetch(:alt) { File.basename(src, '.*').gsub(/-\d+$/, "").gsub("-", " ").humanize } end if size = options.delete(:size) options[:width], options[:height] = size.split("x") if size =~ %{^\d+x\d+$} end if mouseover = options.delete(:mouseover) options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'" options[:onmouseout] = "this.src='#{src}'" end tag("img", options) end def load_logo(parent, size = "small", link = nil, lightbox = true) if parent && parent.logo_id.present? path = parent.logo.url(size.to_s) rescue nil end if path.blank? path = "/images/vendors/no-logo.png" alt = "No logo" else alt = "Logo for #{parent.is_a?(::Group) ? parent.name : parent.vendor_name}" end if parent && parent.logo path << "?#{parent.logo.updated_at.to_i}" end if link # , :width => 74, :height => 74 clazz = lightbox == true ? 'fancy-ajax logo' : 'logo' link_to [content_tag(:span), image_tag(path, :class => "photo", :alt => alt, :title => alt)].join("").html_safe, link, :class => clazz, :"data-deal-id" => parent.id, :"data-ajax" => "false" else image_tag(path) end end # http://snippets.dzone.com/posts/show/805 def read_image_size(path) width, height = IO.read("#{Rails.root}/public/images/#{path}")[0x10..0x18].unpack('NN') {:width => width, :height => height} end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
storefront-0.2.1 | lib/storefront/helpers/image_helper.rb |
storefront-0.2.0 | lib/storefront/helpers/image_helper.rb |