* Initial basic work * Bulk of related work, including find/replace on the inputs * Adjust some tests * Adjust some specs * Fix a few more tests * Clean up tests * Adjust tests * Test fiddle * Adjust crop back to be a param * Update tests * Set proper defaults * Fix some styling * Adjust enrichment logic and tests * Adjust form JS * Update test snapshot * Clean up formatting * Fix spec name * Adjust some css and defaults * Adjust translation for image provider options * Switch from fill to fill-down * Proper fallback image * Fix tests * Update app/services/images/optimizer.rb Co-authored-by: Mac Siri <mac@forem.com> --------- Co-authored-by: Mac Siri <mac@forem.com>
30 lines
721 B
Ruby
30 lines
721 B
Ruby
class CloudCoverUrl
|
|
include ActionView::Helpers::AssetUrlHelper
|
|
|
|
def initialize(url)
|
|
@url = url
|
|
end
|
|
|
|
def call
|
|
return if url.blank?
|
|
return url if Rails.env.development?
|
|
|
|
width = 1000
|
|
height = Settings::UserExperience.cover_image_height
|
|
crop = Settings::UserExperience.cover_image_fit
|
|
img_src = url_without_prefix_nesting(url, width)
|
|
|
|
Images::Optimizer.call(img_src, width: width, height: height, crop: crop)
|
|
end
|
|
|
|
private
|
|
|
|
def url_without_prefix_nesting(url, width)
|
|
return url if url.blank?
|
|
return url unless url.start_with?("https://res.cloudinary.com/") && url.include?("w_#{width}/https://")
|
|
|
|
url.split("w_#{width}/").last
|
|
end
|
|
|
|
attr_reader :url, :height
|
|
end
|