Sha256: c2972325acc4612586a080bb4fd3d2d58e63947f8135d3a0ac4685a3b4bda3a2

Contents?: true

Size: 952 Bytes

Versions: 6

Compression:

Stored size: 952 Bytes

Contents

module Spina
  module ImagesHelper

    def thumbnail_url(image)
      return "" if image.nil?
      main_app.url_for(image.variant(resize_to_fill: [400, 300]))
    end

    def embedded_image_url(image)
      return "" if image.nil?

      # support both ImageProcessing gem macro :resize_to_limit and ImageMagick-specific :resize
      resize_key = Spina.config.embedded_image_size.is_a?(Array) ? :resize_to_limit : :resize
      main_app.url_for(image.variant(Hash[resize_key, Spina.config.embedded_image_size]))
    end
    
    def content_type_color(image)
      case content_type(image)
      when "png"
        "bg-green-300"
      when "heic"
        "bg-blue-200"
      when "jpg", "jpeg"
        "bg-blue-400"
      when "gif"
        "bg-indigo-300"
      when "svg"
        "bg-yellow-400"
      else
        "bg-gray-400"
      end
    end
    
    def content_type(image)
      image.file.content_type.split("/").last
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spina-2.3.5 app/helpers/spina/images_helper.rb
spina-2.3.4 app/helpers/spina/images_helper.rb
spina-2.3.3 app/helpers/spina/images_helper.rb
spina-2.3.2 app/helpers/spina/images_helper.rb
spina-2.3.1 app/helpers/spina/images_helper.rb
spina-2.3.0 app/helpers/spina/images_helper.rb