lato_cms 3.0.3 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/lato_cms/page_field.rb +39 -4
- data/lib/lato_cms/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 319316314172ac5393d5d560741b331e00a8570fe476090f607cf3c583addce4
|
|
4
|
+
data.tar.gz: c8566ef62e7af5280fd4627a376d79b1dabbef383eeb365d7f3720ad9b3d5dba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6be7fac9bc254c30c2302b9bdd8351c7e20809b0a1f39cfaad773c74d82ead10bd7db204816f02ca86809eb46f03afb98ecbe516e474ad93a7a7cc2e01b7c9c8
|
|
7
|
+
data.tar.gz: 139e9d97bacf5cb8eb36542674c84483c4296964359799440689fc604a0705449c0e48531ad286d961569a115cef5b5fbdb2d2fd0ca08441a5e33f01ea939f43
|
|
@@ -92,12 +92,12 @@ module LatoCms
|
|
|
92
92
|
result[:attachments] = files.map { |f| attachment_as_json(f) }
|
|
93
93
|
when 'image'
|
|
94
94
|
attached = files.first
|
|
95
|
-
result[:attachments] = attached ? [attachment_as_json(attached)] : []
|
|
95
|
+
result[:attachments] = attached ? [attachment_as_json(attached, with_variants: true)] : []
|
|
96
96
|
when 'gallery'
|
|
97
97
|
order = value ? (JSON.parse(value) rescue []) : []
|
|
98
98
|
all_files = files.to_a
|
|
99
99
|
ordered = order.any? ? all_files.sort_by { |f| order.index(f.id.to_s) || Float::INFINITY } : all_files
|
|
100
|
-
result[:attachments] = ordered.map { |f| attachment_as_json(f) }
|
|
100
|
+
result[:attachments] = ordered.map { |f| attachment_as_json(f, with_variants: true) }
|
|
101
101
|
else
|
|
102
102
|
result[:value] = parsed_value
|
|
103
103
|
end
|
|
@@ -107,14 +107,49 @@ module LatoCms
|
|
|
107
107
|
|
|
108
108
|
private
|
|
109
109
|
|
|
110
|
-
def attachment_as_json(attachment)
|
|
111
|
-
{
|
|
110
|
+
def attachment_as_json(attachment, with_variants: false)
|
|
111
|
+
json = {
|
|
112
112
|
id: attachment.id,
|
|
113
113
|
filename: attachment.filename.to_s,
|
|
114
114
|
content_type: attachment.content_type,
|
|
115
115
|
byte_size: attachment.byte_size,
|
|
116
116
|
url: Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)
|
|
117
117
|
}
|
|
118
|
+
json[:sizes] = attachment_variant_urls(attachment) if with_variants
|
|
119
|
+
json
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Builds a map of { size_name => variant_url } from the field's `settings.sizes`.
|
|
123
|
+
# Variants are processed lazily by Active Storage on first request to their URL.
|
|
124
|
+
def attachment_variant_urls(attachment)
|
|
125
|
+
sizes = field_settings['sizes']
|
|
126
|
+
return {} if sizes.blank? || !sizes.respond_to?(:each_pair) || !attachment.variable?
|
|
127
|
+
|
|
128
|
+
url_helpers = Rails.application.routes.url_helpers
|
|
129
|
+
sizes.each_with_object({}) do |(name, opts), acc|
|
|
130
|
+
transformation = variant_transformation(opts)
|
|
131
|
+
next if transformation.blank?
|
|
132
|
+
|
|
133
|
+
variant = attachment.variant(transformation)
|
|
134
|
+
acc[name] = url_helpers.rails_representation_path(variant, only_path: true)
|
|
135
|
+
end
|
|
136
|
+
rescue StandardError => e
|
|
137
|
+
Rails.logger.error("LatoCms: Failed to build image variants for attachment #{attachment.id}: #{e.message}")
|
|
138
|
+
{}
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Maps a size config (width/height/resize) to an Active Storage variant transformation.
|
|
142
|
+
# resize modes: "limit" (default, scale down only), "fit" (scale to fit), "fill" (crop to exact size).
|
|
143
|
+
def variant_transformation(opts)
|
|
144
|
+
opts = {} unless opts.respond_to?(:[])
|
|
145
|
+
dimensions = [opts['width'] || opts[:width], opts['height'] || opts[:height]]
|
|
146
|
+
return nil if dimensions.compact.empty?
|
|
147
|
+
|
|
148
|
+
case (opts['resize'] || opts[:resize] || 'limit').to_s
|
|
149
|
+
when 'fill' then { resize_to_fill: dimensions }
|
|
150
|
+
when 'fit' then { resize_to_fit: dimensions }
|
|
151
|
+
else { resize_to_limit: dimensions }
|
|
152
|
+
end
|
|
118
153
|
end
|
|
119
154
|
|
|
120
155
|
def parse_value
|
data/lib/lato_cms/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lato_cms
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gregorio Galante
|
|
@@ -65,6 +65,20 @@ dependencies:
|
|
|
65
65
|
- - ">="
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: image_processing
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '1.2'
|
|
75
|
+
type: :runtime
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '1.2'
|
|
68
82
|
description: A Rails engine to manage application users on Lato projects!
|
|
69
83
|
email:
|
|
70
84
|
- me@gregoriogalante.com
|