Sha256: 24373c5732fa0f882852eb350f39d4a5d63d86dc2c5a7e2464dc7709bdb52b2c

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

module Spina
  module ImagesHelper
  
    def original_url(image)
      return "" if image.nil?
      main_app.url_for(image.file)
    end

    def thumbnail_url(image)
      return "" if image.nil?
      main_app.url_for(image.variant(resize_to_fill: [400, 300]))
    end
    
    def large_thumbnail_url(image)
      return "" if image.nil?
      main_app.url_for(image.variant(resize_to_fit: [800, 600]))
    end
    
    def preview_url(image)
      return "" if image.nil?
      main_app.url_for(image.variant(resize_to_limit: [1600, 1200]))
    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 || I18n.t("spina.images.missing_image")
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spina-2.12.0 app/helpers/spina/images_helper.rb
spina-2.11.0 app/helpers/spina/images_helper.rb
spina-2.10.0 app/helpers/spina/images_helper.rb
spina-2.9.1 app/helpers/spina/images_helper.rb
spina-2.9.0 app/helpers/spina/images_helper.rb