From 42642151c55017c8b7850aef16c649c56d5a059c Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 15 Jun 2020 15:25:04 +0200 Subject: [PATCH] Extract picture thumbnail sizes in a constant We want to read those value from other classes and it makes sense to have them formalized in a constant anyway. --- app/helpers/alchemy/admin/pictures_helper.rb | 10 ++++------ app/models/alchemy/picture.rb | 6 ++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/helpers/alchemy/admin/pictures_helper.rb b/app/helpers/alchemy/admin/pictures_helper.rb index a920f17ecc..d2c5f47cc4 100644 --- a/app/helpers/alchemy/admin/pictures_helper.rb +++ b/app/helpers/alchemy/admin/pictures_helper.rb @@ -4,12 +4,10 @@ module Alchemy module Admin module PicturesHelper def preview_size(size) - case size - when "small" then "80x60" - when "large" then "240x180" - else - "160x120" - end + Alchemy::Picture::THUMBNAIL_SIZES.fetch( + size, + Alchemy::Picture::THUMBNAIL_SIZES[:medium] + ) end end end diff --git a/app/models/alchemy/picture.rb b/app/models/alchemy/picture.rb index c9d5b26d8d..961f14805f 100644 --- a/app/models/alchemy/picture.rb +++ b/app/models/alchemy/picture.rb @@ -22,6 +22,12 @@ module Alchemy class Picture < BaseRecord + THUMBNAIL_SIZES = { + small: "80x60", + medium: "160x120", + large: "240x180", + }.with_indifferent_access.freeze + CONVERTIBLE_FILE_FORMATS = %w(gif jpg jpeg png).freeze include Alchemy::NameConversions