alchemy_cms 8.4.3 → 8.4.5

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/builds/alchemy/admin/page-select.css +1 -1
  3. data/app/assets/builds/alchemy/admin/tags-autocomplete.css +1 -1
  4. data/app/assets/builds/alchemy/admin.css +1 -1
  5. data/app/assets/builds/alchemy/preview.min.js +1 -1
  6. data/app/components/alchemy/admin/dashboard/widgets/attachment_counts.rb +1 -1
  7. data/app/components/alchemy/admin/dashboard/widgets/picture_counts.rb +1 -1
  8. data/app/components/alchemy/admin/uploader_button.rb +22 -13
  9. data/app/components/alchemy/ingredients/picture_view.rb +4 -2
  10. data/app/javascript/preview.js +6 -1
  11. data/app/jobs/alchemy/invalidate_elements_cache_job.rb +1 -0
  12. data/app/models/alchemy/ingredient_definition.rb +3 -4
  13. data/app/models/alchemy/page.rb +7 -4
  14. data/app/models/alchemy/storage_adapter/active_storage.rb +16 -0
  15. data/app/models/alchemy/storage_adapter/dragonfly.rb +37 -0
  16. data/app/models/alchemy/storage_adapter.rb +3 -0
  17. data/app/models/concerns/alchemy/picture_thumbnails.rb +7 -4
  18. data/app/stylesheets/alchemy/admin/_tom-select.scss +11 -0
  19. data/app/stylesheets/alchemy/admin/forms.scss +1 -1
  20. data/app/stylesheets/alchemy/admin/upload.scss +11 -0
  21. data/app/views/alchemy/admin/attachments/_replace_button.html.erb +4 -4
  22. data/app/views/alchemy/admin/tinymce/_setup.html.erb +5 -3
  23. data/lib/alchemy/config_missing.rb +2 -0
  24. data/lib/alchemy/engine.rb +12 -4
  25. data/lib/alchemy/test_support/having_picture_thumbnails_examples.rb +14 -2
  26. data/lib/alchemy/tinymce.rb +25 -0
  27. data/lib/alchemy/version.rb +1 -1
  28. data/lib/alchemy_cms.rb +55 -3
  29. data/vendor/javascript/shoelace.min.js +6 -6
  30. metadata +1 -2
  31. data/lib/alchemy.rb +0 -56
@@ -1 +1 @@
1
- !function(){"use strict";const e={outline:"","outline-offset":"",cursor:""},t={outline:"2px dashed #f0b437","outline-offset":"4px",cursor:"pointer"},n={outline:"2px dashed #90b9d0","outline-offset":"4px"};let o=[],s=null;function a(e){i(e),s=e,Object.assign(e.style,n),e.scrollIntoView({behavior:"smooth",block:"start"})}function i(t){o.forEach(n=>{n!==t&&Object.assign(n.style,e)}),s=null}function c(e){const t=(n=e.element_id,o.find(e=>e.dataset.alchemyElement===n.toString()));var n;t?a(t):console.warn("Could not focus element with id",e.element_id)}function l(n){n.addEventListener("mouseover",()=>{n!==s&&Object.assign(n.style,t)}),n.addEventListener("mouseout",()=>{n!==s&&Object.assign(n.style,e)})}function d(e){const t=e.target.closest("[data-alchemy-element]");return t&&(a(t),function(e){window.parent.postMessage({message:"Alchemy.focusElementEditor",element_id:e.dataset.alchemyElement},window.location.origin)}(t)),t}function r(e){(function(e){if(e.closest("a"))return!0;const t=e.closest("button, input");return Boolean(t?.form)&&["submit","image"].includes(t.type)})(e.target)&&d(e)&&(e.stopPropagation(),e.preventDefault())}function u(){window.addEventListener("message",e=>{switch(e.data.message){case"Alchemy.blurElements":i();break;case"Alchemy.focusElement":c(e.data);break;default:console.info("Received unknown message!",e.data)}}),window.addEventListener("click",r,{capture:!0}),window.addEventListener("click",d),o=Array.from(document.querySelectorAll("[data-alchemy-element]")),o.forEach(l),window.parent.postMessage({message:"Alchemy.previewReady"},window.location.origin)}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",u,{once:!0}):u()}();
1
+ !function(){"use strict";const e={outline:"","outline-offset":"",cursor:""},t={outline:"2px dashed #f0b437","outline-offset":"4px",cursor:"pointer"},n={outline:"2px dashed #90b9d0","outline-offset":"4px"};let o=[],s=null;function a(e){i(e),s=e,Object.assign(e.style,n),e.scrollIntoView({behavior:"smooth",block:"start"})}function i(t){o.forEach(n=>{n!==t&&Object.assign(n.style,e)}),s=null}function c(e){const t=(n=e.element_id,o.find(e=>e.dataset.alchemyElement===n.toString()));var n;t?a(t):console.warn("Could not focus element with id",e.element_id)}function l(n){n.addEventListener("mouseover",()=>{n!==s&&Object.assign(n.style,t)}),n.addEventListener("mouseout",()=>{n!==s&&Object.assign(n.style,e)})}function d(e){const t=e.target.closest("[data-alchemy-element]");return t&&(a(t),function(e){window.parent.postMessage({message:"Alchemy.focusElementEditor",element_id:e.dataset.alchemyElement},window.location.origin)}(t)),t}function r(e){(function(e){if(e.closest("a"))return!0;const t=e.closest("button, input");return Boolean(t?.form)&&["submit","image"].includes(t.type)})(e.target)&&(d(e),e.stopPropagation(),e.preventDefault())}function u(){window.addEventListener("message",e=>{switch(e.data.message){case"Alchemy.blurElements":i();break;case"Alchemy.focusElement":c(e.data);break;default:console.info("Received unknown message!",e.data)}}),window.addEventListener("click",r,{capture:!0}),window.addEventListener("click",d),window.addEventListener("turbo:before-visit",e=>e.preventDefault()),o=Array.from(document.querySelectorAll("[data-alchemy-element]")),o.forEach(l),window.parent.postMessage({message:"Alchemy.previewReady"},window.location.origin)}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",u,{once:!0}):u()}();
@@ -9,7 +9,7 @@ module Alchemy
9
9
  def link = alchemy.admin_attachments_path
10
10
  def icon = "file-copy-2"
11
11
  def count = Alchemy::Attachment.count
12
- def infos = number_to_human_size(Alchemy::Attachment.sum(&:file_size))
12
+ def infos = number_to_human_size(Alchemy.storage_adapter.total_file_size)
13
13
  end
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ module Alchemy
9
9
  def link = alchemy.admin_pictures_path
10
10
  def icon = "multi-image"
11
11
  def count = Alchemy::Picture.count
12
- def infos = number_to_human_size(Alchemy::Picture.sum(&:image_file_size))
12
+ def infos = number_to_human_size(Alchemy.storage_adapter.total_image_file_size)
13
13
  end
14
14
  end
15
15
  end
@@ -19,7 +19,7 @@ module Alchemy
19
19
  def call
20
20
  content_tag "alchemy-uploader", "redirect-url": redirect_url, dropzone:, layout: do
21
21
  form_for [alchemy, :admin, object], html: {multipart: true, class: "upload-button"} do |f|
22
- safe_join([upload_hash_field(f), file_input(f), upload_label(f)].compact)
22
+ safe_join([upload_hash_field(f), upload_label(f)].compact)
23
23
  end
24
24
  end
25
25
  end
@@ -35,21 +35,30 @@ module Alchemy
35
35
  def file_input(f)
36
36
  f.file_field file_attribute,
37
37
  class: "fileupload fileupload--field", multiple: true, accept: accept,
38
- name: "#{f.object_name}[#{file_attribute}]", tabindex: "-1"
38
+ name: "#{f.object_name}[#{file_attribute}]"
39
39
  end
40
40
 
41
+ # The visually hidden file input is what the button is operated with, so it
42
+ # has to sit inside the label and the label inside the tooltip: the tooltip
43
+ # only opens for focus moving into itself.
41
44
  def upload_label(f)
42
- f.label file_attribute, data: {alchemy_hotkey: "alt+n"} do
43
- if inline_label
44
- tag.span class: "button with_icon", tabindex: "0" do
45
- render(Alchemy::Admin::Icon.new("upload-2")) + tooltip
46
- end
47
- else
48
- content_tag "sl-tooltip", content: tooltip, placement: "top-start" do
49
- tag.span class: "icon_button", tabindex: "0" do
50
- render Alchemy::Admin::Icon.new("upload-2")
51
- end
52
- end
45
+ label = f.label file_attribute, data: {alchemy_hotkey: "alt+n"} do
46
+ safe_join([button_content, file_input(f)])
47
+ end
48
+
49
+ return label if inline_label
50
+
51
+ content_tag "sl-tooltip", label, content: tooltip, placement: "top-start"
52
+ end
53
+
54
+ def button_content
55
+ if inline_label
56
+ tag.span class: "button with_icon" do
57
+ render(Alchemy::Admin::Icon.new("upload-2")) + tooltip
58
+ end
59
+ else
60
+ tag.span class: "icon_button" do
61
+ render Alchemy::Admin::Icon.new("upload-2")
53
62
  end
54
63
  end
55
64
  end
@@ -43,7 +43,7 @@ module Alchemy
43
43
  end
44
44
 
45
45
  def call
46
- return if picture.blank?
46
+ return if picture.blank? || src.nil?
47
47
 
48
48
  output = caption ? img_tag + caption : img_tag
49
49
 
@@ -72,7 +72,9 @@ module Alchemy
72
72
  end
73
73
 
74
74
  def src
75
- ingredient.picture_url(picture_options)
75
+ return @_src if defined?(@_src)
76
+
77
+ @_src = ingredient.picture_url(picture_options)
76
78
  end
77
79
 
78
80
  def img_tag
@@ -101,7 +101,8 @@ function navigates(target) {
101
101
  // Client side routers navigate from click handlers on the link itself, so
102
102
  // navigating clicks have to be taken before the event reaches the page.
103
103
  function onNavigatingClick(event) {
104
- if (navigates(event.target) && selectClickedElement(event)) {
104
+ if (navigates(event.target)) {
105
+ selectClickedElement(event)
105
106
  event.stopPropagation()
106
107
  event.preventDefault()
107
108
  }
@@ -123,6 +124,10 @@ function init() {
123
124
 
124
125
  window.addEventListener("click", onNavigatingClick, { capture: true })
125
126
  window.addEventListener("click", selectClickedElement)
127
+ // Turbo.visit can be called from any click handler, not only from links.
128
+ window.addEventListener("turbo:before-visit", (event) =>
129
+ event.preventDefault()
130
+ )
126
131
 
127
132
  elements = Array.from(document.querySelectorAll("[data-alchemy-element]"))
128
133
  elements.forEach(observeElement)
@@ -11,6 +11,7 @@ module Alchemy
11
11
 
12
12
  all_element_ids = get_all_element_ids(elements, element_ids)
13
13
  Element.where(id: all_element_ids).touch_all
14
+ PageVersion.scheduled.where(id: elements.select(:page_version_id)).touch_all
14
15
 
15
16
  page_ids = elements.joins(page_version: :page).distinct.pluck("alchemy_pages.id")
16
17
  Page.where(id: page_ids).touch_all
@@ -61,11 +61,10 @@ module Alchemy
61
61
  # If the value is a symbol it gets passed through i18n
62
62
  # inside the +alchemy.default_ingredient_texts+ scope
63
63
  def default_value
64
- case default
65
- when Symbol
64
+ if default.is_a?(Symbol)
66
65
  Alchemy.t(default, scope: :default_ingredient_texts)
67
- when String
68
- default
66
+ else
67
+ default&.to_s
69
68
  end
70
69
  end
71
70
 
@@ -165,7 +165,7 @@ module Alchemy
165
165
  validates_format_of :page_layout, with: /\A[a-z0-9_-]+\z/, unless: -> { page_layout.blank? }
166
166
  validates_presence_of :parent, unless: -> { layoutpage? || language_root? }
167
167
  validates_presence_of :permitted_roles, if: :restricted?
168
- validate :permitted_roles_are_configured
168
+ validate :permitted_roles_are_configured, if: :restricted?
169
169
 
170
170
  after_initialize :ensure_draft_version, if: :new_record?
171
171
 
@@ -453,14 +453,17 @@ module Alchemy
453
453
  # Returns true if the draft version has changes not yet published.
454
454
  #
455
455
  # Compares the updated_at timestamp of the draft_version against the
456
- # updated_at timestamp of the public_version. If there's no public_version,
457
- # the page has never been published and always has unpublished changes.
456
+ # page's published_at timestamp. The public_version's updated_at is not
457
+ # used, because it gets touched to invalidate caches. It only serves as
458
+ # fallback for public versions created without publishing (via +public_on=+).
459
+ # If there's no public_version, the page has never been published and
460
+ # always has unpublished changes.
458
461
  #
459
462
  # @return [Boolean]
460
463
  def has_unpublished_changes?
461
464
  return true unless public_version
462
465
 
463
- draft_version.updated_at > public_version.updated_at
466
+ draft_version.updated_at > (published_at || public_version.updated_at)
464
467
  end
465
468
 
466
469
  # Sets the public_on date on the published version
@@ -140,6 +140,11 @@ module Alchemy
140
140
  attachment.file&.byte_size
141
141
  end
142
142
 
143
+ # @return [Integer]
144
+ def total_file_size
145
+ Attachment.joins(:file_blob).sum("active_storage_blobs.byte_size")
146
+ end
147
+
143
148
  # @param [Alchemy::Attachment]
144
149
  # @return [String]
145
150
  def file_mime_type(attachment)
@@ -158,6 +163,12 @@ module Alchemy
158
163
  picture.image_file&.variable?
159
164
  end
160
165
 
166
+ # @param [String, Symbol] format file extension
167
+ # @return [TrueClass, FalseClass]
168
+ def can_convert_to?(format)
169
+ Marcel::MimeType.for(extension: format.to_s).in?(::ActiveStorage.variable_content_types)
170
+ end
171
+
161
172
  # @param [Alchemy::Picture]
162
173
  # @return [String]
163
174
  def image_file_basename(picture)
@@ -183,6 +194,11 @@ module Alchemy
183
194
  picture.image_file&.byte_size
184
195
  end
185
196
 
197
+ # @return [Integer]
198
+ def total_image_file_size
199
+ Picture.joins(:image_file_blob).sum("active_storage_blobs.byte_size")
200
+ end
201
+
186
202
  # @param [Alchemy::Picture]
187
203
  # @return [Integer]
188
204
  def image_file_width(picture)
@@ -7,6 +7,10 @@ module Alchemy
7
7
  dragonfly_accessor :image_file, app: :alchemy_pictures do
8
8
  # Preprocess after uploading the picture
9
9
  after_assign do |image|
10
+ if Alchemy::StorageAdapter::Dragonfly.svg?(image)
11
+ write_attribute(:image_file_format, "svg")
12
+ end
13
+
10
14
  if has_convertible_format?
11
15
  Alchemy.storage_adapter.preprocessor_class.new(image).call
12
16
  end
@@ -46,6 +50,23 @@ module Alchemy
46
50
 
47
51
  CONVERTIBLE_FILE_FORMATS = %w[gif jpg jpeg png webp].freeze
48
52
 
53
+ SVG_MIME_TYPE = "image/svg+xml"
54
+
55
+ # Whether the attached file is an SVG
56
+ #
57
+ # ImageMagick renders SVGs through the rsvg delegate before reading them,
58
+ # so +identify+ reports the format of the rendered raster instead of the
59
+ # source file. The file itself has to be inspected to detect SVGs.
60
+ #
61
+ # @param [Dragonfly::Model::Attachment]
62
+ # @return [TrueClass, FalseClass]
63
+ def svg?(image_file)
64
+ mime_type = image_file.file do |file|
65
+ Marcel::MimeType.for(file, name: image_file.name)
66
+ end
67
+ mime_type == SVG_MIME_TYPE
68
+ end
69
+
49
70
  # Allows to set a custom Attachment Url class
50
71
  def attachment_url_class=(klass)
51
72
  @_attachment_url_class = klass
@@ -139,6 +160,11 @@ module Alchemy
139
160
  attachment.read_attribute(:file_size)
140
161
  end
141
162
 
163
+ # @return [Integer]
164
+ def total_file_size
165
+ Attachment.sum(:file_size)
166
+ end
167
+
142
168
  # @param [Alchemy::Attachment]
143
169
  # @return [String]
144
170
  def file_mime_type(attachment)
@@ -164,6 +190,12 @@ module Alchemy
164
190
  image_file_extension(picture).in?(CONVERTIBLE_FILE_FORMATS)
165
191
  end
166
192
 
193
+ # @param [String, Symbol] format file extension
194
+ # @return [TrueClass, FalseClass]
195
+ def can_convert_to?(format)
196
+ format.to_s.in?(CONVERTIBLE_FILE_FORMATS)
197
+ end
198
+
167
199
  # @param [Alchemy::Picture]
168
200
  # @return [String]
169
201
  def image_file_basename(picture)
@@ -189,6 +221,11 @@ module Alchemy
189
221
  picture.read_attribute(:image_file_size)
190
222
  end
191
223
 
224
+ # @return [Integer]
225
+ def total_image_file_size
226
+ Picture.sum(:image_file_size)
227
+ end
228
+
192
229
  # @param [Alchemy::Picture]
193
230
  # @return [Integer]
194
231
  def image_file_width(picture)
@@ -15,6 +15,7 @@ module Alchemy
15
15
  :file_mime_type,
16
16
  :file_name,
17
17
  :file_size,
18
+ :can_convert_to?,
18
19
  :has_convertible_format?,
19
20
  :image_file_basename,
20
21
  :image_file_extension,
@@ -33,6 +34,8 @@ module Alchemy
33
34
  :rescuable_errors,
34
35
  :searchable_alchemy_resource_attributes,
35
36
  :set_attachment_name?,
37
+ :total_file_size,
38
+ :total_image_file_size,
36
39
  to: :adapter
37
40
  )
38
41
 
@@ -33,11 +33,13 @@ module Alchemy
33
33
  # @option options crop [Boolean]
34
34
  # If set to true the picture will be cropped to fit the size value.
35
35
  #
36
- # @return [String]
36
+ # @return [String, nil] +nil+ if no picture is assigned or the url could not be generated
37
37
  def picture_url(options = {})
38
38
  return if picture.nil?
39
39
 
40
- picture.url(picture_url_options(options)) || "missing-image.png"
40
+ url = picture.url(picture_url_options(options))
41
+ Logger.warn("Could not generate url for picture #{picture.id}") if url.nil?
42
+ url
41
43
  end
42
44
 
43
45
  # Picture rendering options
@@ -47,7 +49,7 @@ module Alchemy
47
49
  #
48
50
  # The render format is taken from the +format+ option, the +format+ setting
49
51
  # of the ingredient definition or the +default_render_format+ of the picture.
50
- # A format is only applied if the picture can be converted.
52
+ # A format is only applied if the picture can be converted into it.
51
53
  #
52
54
  # @param options [Hash] Options that override the defaults (i.e. +size+ or +format+ of a srcset entry)
53
55
  #
@@ -157,7 +159,8 @@ module Alchemy
157
159
  private
158
160
 
159
161
  def picture_render_format(format)
160
- if format.present? && picture.has_convertible_format?
162
+ if format.present? && picture.has_convertible_format? &&
163
+ Alchemy.storage_adapter.can_convert_to?(format)
161
164
  format.to_s
162
165
  else
163
166
  picture.default_render_format
@@ -1,4 +1,5 @@
1
1
  // Theme for the Tom Select powered `<select is="alchemy-select">`.
2
+ @use "../extends";
2
3
  @use "../mixins";
3
4
  @use "icons";
4
5
 
@@ -167,6 +168,16 @@
167
168
  );
168
169
  }
169
170
 
171
+ // Not `&.invalid`: Tom Select sets that on first render, before any user
172
+ // interaction.
173
+ select:user-invalid + & .ts-control {
174
+ @extend %field-with-error;
175
+
176
+ > input {
177
+ background-color: transparent;
178
+ }
179
+ }
180
+
170
181
  &.disabled .ts-control {
171
182
  background-color: var(--select-disabled-background-color);
172
183
  border-color: var(--select-disabled-border-color);
@@ -138,7 +138,7 @@ form {
138
138
  }
139
139
  }
140
140
 
141
- input:invalid:focus {
141
+ input:user-invalid:focus {
142
142
  @extend %field-with-error;
143
143
  }
144
144
 
@@ -1,4 +1,5 @@
1
1
  @use "../extends";
2
+ @use "../mixins";
2
3
 
3
4
  .upload-button {
4
5
  display: inline-block;
@@ -6,6 +7,16 @@
6
7
  label {
7
8
  cursor: pointer;
8
9
  }
10
+
11
+ // The focus rests on the visually hidden file input, so the button standing in
12
+ // for it has to draw the focus ring.
13
+ label:focus-within {
14
+ &.icon_button,
15
+ .button,
16
+ .icon_button {
17
+ @include mixins.default-focus-style;
18
+ }
19
+ }
9
20
  }
10
21
 
11
22
  .fileupload--field {
@@ -3,12 +3,12 @@
3
3
 
4
4
  <alchemy-uploader redirect-url="<%= redirect_url %>">
5
5
  <%= form_for [:admin, object], html: {multipart: true, class: 'upload-button'} do |f| %>
6
- <%= f.file_field file_attribute,
7
- class: 'fileupload--field', accept: accept,
8
- name: "#{f.object_name}[#{file_attribute}]",
9
- id: "replace_#{dom_id(object)}" %>
10
6
  <%= label_tag "replace_#{dom_id(object)}", class: "icon_button" do %>
11
7
  <%= render_icon "file-upload" %>
8
+ <%= f.file_field file_attribute,
9
+ class: 'fileupload--field', accept: accept,
10
+ name: "#{f.object_name}[#{file_attribute}]",
11
+ id: "replace_#{dom_id(object)}" %>
12
12
  <% end %>
13
13
  <% end %>
14
14
  </alchemy-uploader>
@@ -1,11 +1,12 @@
1
1
  <% tinymce_base_path = "#{Rails.application.config.assets.prefix}/tinymce" %>
2
+ <% cache_suffix = Alchemy::Tinymce.cache_suffix(self) %>
2
3
 
3
- <link rel="preload" href="<%= asset_path("#{tinymce_base_path}/skins/ui/alchemy/skin.min.css") %>" as="style">
4
+ <link rel="preload" href="<%= asset_path("#{tinymce_base_path}/skins/ui/alchemy/skin.min.css") %>?<%= cache_suffix %>" as="style">
4
5
  <% if Alchemy::Tinymce.init[:content_css] %>
5
- <link rel="preload" href="<%= asset_path(Alchemy::Tinymce.init[:content_css]) %>" as="style">
6
+ <link rel="preload" href="<%= asset_path(Alchemy::Tinymce.init[:content_css]) %>?<%= cache_suffix %>" as="style">
6
7
  <% end %>
7
8
  <% Alchemy::Tinymce.preloadable_plugins.each do |plugin| %>
8
- <link rel="preload" href="<%= asset_path("#{tinymce_base_path}/plugins/#{plugin}/plugin.min.js") %>" as="script">
9
+ <link rel="preload" href="<%= asset_path("#{tinymce_base_path}/plugins/#{plugin}/plugin.min.js") %>?<%= cache_suffix %>" as="script">
9
10
  <% end %>
10
11
 
11
12
  <%= tag.script(type: "application/json", id: "alchemy_tinymce_defaults") do %>
@@ -14,6 +15,7 @@
14
15
  asset_url(tinymce_base_path, host: ActionController::Base.config.asset_host) :
15
16
  tinymce_base_path,
16
17
  suffix: ".min",
18
+ cache_suffix: cache_suffix,
17
19
  plugins: Alchemy::Tinymce.plugins.join(",")
18
20
  ).to_json %>
19
21
  <% end %>
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "alchemy/deprecation"
4
+
3
5
  module Alchemy
4
6
  module ConfigMissing
5
7
  def const_missing(missing_const_name)
@@ -54,8 +54,12 @@ module Alchemy
54
54
  )
55
55
  end
56
56
 
57
+ # Runs after initialization, so that importmaps added from an application
58
+ # initializer (those run after the engine's initializers) are picked up.
59
+ # It must not run again on reload: every entry it adds below lands in a
60
+ # registry that is never pruned.
57
61
  initializer "alchemy.importmap" do |app|
58
- app.config.to_prepare do
62
+ app.config.after_initialize do
59
63
  watch_paths = []
60
64
 
61
65
  Alchemy.config.admin_importmaps.each do |admin_import|
@@ -81,9 +85,10 @@ module Alchemy
81
85
  end
82
86
  end
83
87
 
84
- # All the initialization that needs to be re-triggered during reloads
85
- config.to_prepare do
86
- # Definition files
88
+ # Registered from a `to_prepare` block these watchers would pile up in the
89
+ # never pruned reloader registries on every reload, and with them the file
90
+ # system handles they hold open.
91
+ config.after_initialize do
87
92
  elements_reloader = Rails.application.config.file_watcher.new([ElementDefinition.definitions_file_path]) do
88
93
  Logger.info "Reloading Element Definitions."
89
94
  ElementDefinition.reset!
@@ -98,7 +103,10 @@ module Alchemy
98
103
  reloader.execute_if_updated
99
104
  end
100
105
  end
106
+ end
101
107
 
108
+ # All the initialization that needs to be re-triggered during reloads
109
+ config.to_prepare do
102
110
  # The storage adapter for Pictures and Attachments
103
111
  #
104
112
  # Chose between 'active_storage' (default) or 'dragonfly' (legacy)
@@ -103,8 +103,9 @@ RSpec.shared_examples_for "having picture thumbnails" do
103
103
  expect(picture).to receive(:url) { nil }
104
104
  end
105
105
 
106
- it "returns missing image url" do
107
- is_expected.to eq "missing-image.png"
106
+ it "returns nil and logs a warning" do
107
+ expect(Alchemy::Logger).to receive(:warn).with(/Could not generate url for picture/)
108
+ is_expected.to be_nil
108
109
  end
109
110
  end
110
111
  end
@@ -204,6 +205,17 @@ RSpec.shared_examples_for "having picture thumbnails" do
204
205
  expect(picture_url_options[:format]).to eq "png"
205
206
  end
206
207
  end
208
+
209
+ context "with format the picture can not be converted to" do
210
+ before do
211
+ allow(record).to receive(:settings) { {format: "svg"} }
212
+ allow(picture).to receive(:default_render_format) { "webp" }
213
+ end
214
+
215
+ it "includes the pictures default render format" do
216
+ expect(picture_url_options[:format]).to eq "webp"
217
+ end
218
+ end
207
219
  end
208
220
 
209
221
  context "with picture not having a convertible format" do
@@ -15,6 +15,8 @@ module Alchemy
15
15
  alchemy_link
16
16
  ]
17
17
 
18
+ SKINS = %w[alchemy alchemy-dark]
19
+
18
20
  @@plugins = DEFAULT_PLUGINS
19
21
  @@init = {
20
22
  skin: "alchemy",
@@ -49,6 +51,29 @@ module Alchemy
49
51
  def preloadable_plugins
50
52
  @@plugins - DEFAULT_PLUGINS
51
53
  end
54
+
55
+ # Query string TinyMCE appends to every asset it loads at runtime.
56
+ #
57
+ # TinyMCE loads these from undigested asset paths that are served with a
58
+ # one year immutable cache, so they need a content dependent query string
59
+ # to ever be fetched again. The asset pipeline digests all of them
60
+ # individually, but TinyMCE only takes a single suffix for all of them.
61
+ def cache_suffix(view_context)
62
+ digested_paths = undigested_assets.map { |path| view_context.asset_path(path) }
63
+ ActiveSupport::Digest.hexdigest(digested_paths.join).first(8)
64
+ end
65
+
66
+ private
67
+
68
+ def undigested_assets
69
+ SKINS.flat_map do |skin|
70
+ [
71
+ "tinymce/skins/ui/#{skin}/skin.min.css",
72
+ "tinymce/skins/ui/#{skin}/content.min.css",
73
+ "tinymce/skins/content/#{skin}/content.min.css"
74
+ ]
75
+ end + preloadable_plugins.map { |plugin| "tinymce/plugins/#{plugin}/plugin.min.js" }
76
+ end
52
77
  end
53
78
  end
54
79
  end
@@ -3,7 +3,7 @@
3
3
  module Alchemy
4
4
  extend self
5
5
 
6
- VERSION = "8.4.3"
6
+ VERSION = "8.4.5"
7
7
 
8
8
  def version
9
9
  VERSION
data/lib/alchemy_cms.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Instantiate the global Alchemy namespace
4
- require "alchemy"
5
-
6
3
  # Require globally used external libraries
7
4
  require "acts_as_list"
8
5
  require "action_view/dependency_tracker"
@@ -19,6 +16,61 @@ require "turbo-rails"
19
16
  require "userstamp"
20
17
  require "view_component"
21
18
 
19
+ # Instantiate the global Alchemy namespace
20
+ module Alchemy
21
+ require "alchemy/config_missing"
22
+
23
+ include Alchemy::ConfigMissing
24
+ extend Alchemy::ConfigMissing
25
+
26
+ YAML_PERMITTED_CLASSES = %w[Symbol Date Regexp]
27
+
28
+ # JS Importmap instance
29
+ singleton_class.attr_accessor :importmap
30
+ self.importmap = Importmap::Map.new
31
+
32
+ mattr_accessor :storage_adapter
33
+
34
+ class << self
35
+ def config
36
+ require "alchemy/configurations/main"
37
+ @_config ||= Alchemy::Configurations::Main.new
38
+ end
39
+ delegate :configure, to: :config
40
+
41
+ enable_searchable_deprecation_msg = "Use `Alchemy.config.show_page_searchable_checkbox` instead."
42
+ def enable_searchable = config.show_page_searchable_checkbox
43
+ deprecate :enable_searchable= => enable_searchable_deprecation_msg, :deprecator => Alchemy::Deprecation
44
+
45
+ def enable_searchable=(other)
46
+ config.show_page_searchable_checkbox = other
47
+ end
48
+ deprecate enable_searchable: enable_searchable_deprecation_msg, deprecator: Alchemy::Deprecation
49
+
50
+ delegate :preview_sources, to: :config
51
+ delegate :preview_sources=, to: :config
52
+ deprecate preview_sources: "Use `Alchemy.config.preview_sources` instead.", deprecator: Alchemy::Deprecation
53
+ deprecate :preview_sources= => "Use `Alchemy.config.preview_sources=` instead.", :deprecator => Alchemy::Deprecation
54
+
55
+ delegate :admin_js_imports, to: :config
56
+ delegate :admin_js_imports=, to: :config
57
+ deprecate admin_js_imports: "Use `Alchemy.config.admin_js_imports` instead", deprecator: Alchemy::Deprecation
58
+ deprecate :admin_js_imports= => "Use `Alchemy.config.admin_js_imports=` instead", :deprecator => Alchemy::Deprecation
59
+
60
+ delegate :admin_importmaps, to: :config
61
+ deprecate admin_importmaps: "Use Alchemy.config.admin_importmaps instead", deprecator: Alchemy::Deprecation
62
+
63
+ delegate :admin_stylesheets, to: :config
64
+ deprecate admin_stylesheets: "Use Alchemy.config.admin_stylesheets instead", deprecator: Alchemy::Deprecation
65
+
66
+ delegate :publish_targets, to: :config
67
+ deprecate publish_targets: "Use Alchemy.config.publish_targets instead", deprecator: Alchemy::Deprecation
68
+
69
+ delegate :link_dialog_tabs, to: :config
70
+ deprecate link_dialog_tabs: "Use Alchemy.config.link_dialog_tabs instead", deprecator: Alchemy::Deprecation
71
+ end
72
+ end
73
+
22
74
  # Require globally used Alchemy mixins
23
75
  require_relative "alchemy/auth_accessors"
24
76
  require_relative "alchemy/cache_digests/template_tracker"