Sha256: 8b64a07c18cd3e910f1100f3210d9dc05124adce438b63793e8b02c77bcf1114

Contents?: true

Size: 1005 Bytes

Versions: 1

Compression:

Stored size: 1005 Bytes

Contents

require 'fastimage'

module RetinaImageTag
  module ViewHelpers
    
    def retina_image( pixel_ratio )
      insert_on = -File.extname(@image).size-1
      image_tag(@image.insert(insert_on, "@#{pixel_ratio}x"), @options)
    end
    
    
    def full_image_path
      if Rails.env == 'development'
        Rails.root.to_s+'/app/assets/images/'+@image
      else
        request.protocol + request.host_with_port + image_path(@image)
      end
    end
    
    
    def retina_image_tag(image, options = {})
      @devicePixelRatio = cookies[:devicePixelRatio]
      @options          = options
      @image            = image             # foo.jpg, subdir/foo.png

      
      if @options[:size] == nil
        @options[:size] = FastImage.size(full_image_path.delete '@2x').join("x")
      end
      
      case @devicePixelRatio
        when '2'
          retina_image 2
        when '1.5'
          retina_image 2
        else
        image_tag(@image, @options)
       end
     end
     
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
retina_image_tag-0.0.11 lib/retina_image_tag/view_helpers.rb