Class: Fileboost::VariantTransformer
- Inherits:
-
Object
- Object
- Fileboost::VariantTransformer
- Defined in:
- lib/fileboost/variant_transformer.rb
Overview
Maps ActiveStorage variant transformations to Fileboost URL parameters
Constant Summary collapse
- TRANSFORMATION_MAPPING =
Maps ActiveStorage transformation operations to Fileboost parameters
{ # Resize operations resize_to_limit: { fit: "scale-down" }, resize_to_fit: { fit: "contain" }, resize_to_fill: { fit: "cover" }, resize_and_pad: { fit: "pad" }, # Quality settings quality: { param: "q" }, # Format settings format: { param: "f" }, # Rotation rotate: { param: "r" }, # Crop operations - need special handling crop: { special: :crop_handler } }.freeze
Class Method Summary collapse
-
.transform_variant_params(variant) ⇒ Object
Convert ActiveStorage variant transformations to Fileboost parameters.
Class Method Details
.transform_variant_params(variant) ⇒ Object
Convert ActiveStorage variant transformations to Fileboost parameters
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fileboost/variant_transformer.rb', line 26 def self.transform_variant_params(variant) return {} unless variant.respond_to?(:variation) transformations = variant.variation.transformations params = {} transformations.each do |operation, value| case operation when :resize_to_limit, :resize_to_fit, :resize_to_fill, :resize_and_pad resize_params = handle_resize_operation(operation, value) params.merge!(resize_params) when :quality params["q"] = normalize_quality(value) when :format params["f"] = normalize_format(value) when :rotate params["r"] = normalize_rotation(value) when :crop crop_params = handle_crop_operation(value) params.merge!(crop_params) if crop_params # Add more transformations as needed end end params end |