Sha256: 14782030f091fb7789a217902c8051e80e4b2b5486c9d10216ed3b8c048af99a

Contents?: true

Size: 1001 Bytes

Versions: 3

Compression:

Stored size: 1001 Bytes

Contents

module RetinaImageTag
  module ViewHelpers


    def retina_image( pixel_ratio )
      if @image.class.superclass.superclass.to_s == "CarrierWave::Uploader::Base"
        image_tag(@image, :size => @image.class.sizes[@image.version_name].join('x'))
      else
        insert_on = -File.extname(@image).size-1
        image_tag(@image.insert(insert_on, "@#{pixel_ratio}x"), @options)
      end
    end

    def retina_image_tag(image, options = {})
      @devicePixelRatio = cookies[:devicePixelRatio].to_i
      @options          = options
      @image            = image

      case @devicePixelRatio
        when 4
          retina_image 2
        when 3
          retina_image 2
        when 2
          retina_image 2
        when 1.5
          retina_image 2
        else
          if @image.class.superclass.superclass.to_s == "CarrierWave::Uploader::Base"
            image_tag(@image.normal)
          else
            image_tag(@image, @options)
          end
       end
     end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
retina_image_tag-1.0.3 lib/retina_image_tag/view_helpers.rb
retina_image_tag-1.0.2 lib/retina_image_tag/view_helpers.rb
retina_image_tag-1.0.1 lib/retina_image_tag/view_helpers.rb