alchemy_cms 7.0.0.pre.a → 7.0.0.pre.b

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/brakeman-analysis.yml +2 -2
  3. data/.github/workflows/ci.yml +7 -7
  4. data/.github/workflows/lint.yml +17 -0
  5. data/.hound.yml +2 -3
  6. data/.rubocop.yml +4 -350
  7. data/.standard.yml +3 -0
  8. data/CHANGELOG.md +29 -0
  9. data/Gemfile +3 -1
  10. data/README.md +7 -9
  11. data/Rakefile +1 -1
  12. data/alchemy_cms.gemspec +2 -1
  13. data/app/assets/javascripts/alchemy/admin.js +0 -1
  14. data/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee +6 -1
  15. data/app/components/alchemy/ingredients/audio_view.rb +37 -0
  16. data/app/components/alchemy/ingredients/base_view.rb +38 -0
  17. data/app/components/alchemy/ingredients/boolean_view.rb +13 -0
  18. data/app/components/alchemy/ingredients/datetime_view.rb +22 -0
  19. data/app/components/alchemy/ingredients/file_view.rb +40 -0
  20. data/app/components/alchemy/ingredients/headline_view.rb +20 -0
  21. data/app/components/alchemy/ingredients/html_view.rb +9 -0
  22. data/app/components/alchemy/ingredients/link_view.rb +25 -0
  23. data/app/components/alchemy/ingredients/node_view.rb +11 -0
  24. data/app/components/alchemy/ingredients/page_view.rb +15 -0
  25. data/app/components/alchemy/ingredients/picture_view.rb +108 -0
  26. data/app/components/alchemy/ingredients/richtext_view.rb +22 -0
  27. data/app/components/alchemy/ingredients/select_view.rb +6 -0
  28. data/app/components/alchemy/ingredients/text_view.rb +41 -0
  29. data/app/components/alchemy/ingredients/video_view.rb +39 -0
  30. data/app/controllers/alchemy/admin/attachments_controller.rb +3 -3
  31. data/app/controllers/alchemy/admin/base_controller.rb +7 -7
  32. data/app/controllers/alchemy/admin/clipboard_controller.rb +2 -2
  33. data/app/controllers/alchemy/admin/elements_controller.rb +26 -11
  34. data/app/controllers/alchemy/admin/languages_controller.rb +1 -1
  35. data/app/controllers/alchemy/admin/nodes_controller.rb +2 -2
  36. data/app/controllers/alchemy/admin/pages_controller.rb +10 -10
  37. data/app/controllers/alchemy/admin/pictures_controller.rb +14 -14
  38. data/app/controllers/alchemy/admin/resources_controller.rb +27 -28
  39. data/app/controllers/alchemy/admin/styleguide_controller.rb +1 -0
  40. data/app/controllers/alchemy/admin/tags_controller.rb +11 -11
  41. data/app/controllers/alchemy/api/base_controller.rb +2 -2
  42. data/app/controllers/alchemy/api/elements_controller.rb +11 -11
  43. data/app/controllers/alchemy/api/ingredients_controller.rb +1 -1
  44. data/app/controllers/alchemy/api/nodes_controller.rb +1 -1
  45. data/app/controllers/alchemy/api/pages_controller.rb +11 -11
  46. data/app/controllers/alchemy/attachments_controller.rb +3 -3
  47. data/app/controllers/alchemy/base_controller.rb +1 -1
  48. data/app/controllers/alchemy/messages_controller.rb +9 -9
  49. data/app/controllers/alchemy/pages_controller.rb +8 -19
  50. data/app/controllers/concerns/alchemy/admin/archive_overlay.rb +1 -0
  51. data/app/controllers/concerns/alchemy/admin/uploader_responses.rb +5 -7
  52. data/app/controllers/concerns/alchemy/legacy_page_redirects.rb +5 -5
  53. data/app/decorators/alchemy/element_editor.rb +4 -4
  54. data/app/decorators/alchemy/ingredient_editor.rb +6 -6
  55. data/app/helpers/alchemy/admin/attachments_helper.rb +1 -1
  56. data/app/helpers/alchemy/admin/base_helper.rb +21 -22
  57. data/app/helpers/alchemy/admin/elements_helper.rb +1 -1
  58. data/app/helpers/alchemy/admin/form_helper.rb +1 -1
  59. data/app/helpers/alchemy/admin/navigation_helper.rb +7 -7
  60. data/app/helpers/alchemy/admin/pages_helper.rb +2 -2
  61. data/app/helpers/alchemy/admin/tags_helper.rb +3 -3
  62. data/app/helpers/alchemy/base_helper.rb +2 -2
  63. data/app/helpers/alchemy/elements_block_helper.rb +9 -7
  64. data/app/helpers/alchemy/elements_helper.rb +12 -12
  65. data/app/helpers/alchemy/pages_helper.rb +11 -11
  66. data/app/helpers/alchemy/url_helper.rb +1 -1
  67. data/app/mailers/alchemy/messages_mailer.rb +1 -1
  68. data/app/models/alchemy/attachment.rb +6 -6
  69. data/app/models/alchemy/base_record.rb +1 -0
  70. data/app/models/alchemy/eager_loading.rb +6 -6
  71. data/app/models/alchemy/element/definitions.rb +1 -1
  72. data/app/models/alchemy/element/element_ingredients.rb +3 -3
  73. data/app/models/alchemy/element.rb +2 -2
  74. data/app/models/alchemy/elements_repository.rb +1 -1
  75. data/app/models/alchemy/image_cropper_settings.rb +2 -2
  76. data/app/models/alchemy/ingredient.rb +14 -12
  77. data/app/models/alchemy/ingredient_validator.rb +1 -1
  78. data/app/models/alchemy/ingredients/datetime.rb +1 -1
  79. data/app/models/alchemy/ingredients/file.rb +5 -5
  80. data/app/models/alchemy/ingredients/headline.rb +4 -4
  81. data/app/models/alchemy/ingredients/picture.rb +27 -9
  82. data/app/models/alchemy/ingredients/richtext.rb +15 -12
  83. data/app/models/alchemy/ingredients/text.rb +6 -6
  84. data/app/models/alchemy/language/code.rb +1 -1
  85. data/app/models/alchemy/language.rb +4 -4
  86. data/app/models/alchemy/legacy_page_url.rb +1 -1
  87. data/app/models/alchemy/node.rb +2 -2
  88. data/app/models/alchemy/page/page_elements.rb +14 -14
  89. data/app/models/alchemy/page/page_naming.rb +4 -4
  90. data/app/models/alchemy/page/page_natures.rb +1 -1
  91. data/app/models/alchemy/page/page_scopes.rb +5 -5
  92. data/app/models/alchemy/page.rb +11 -11
  93. data/app/models/alchemy/picture/calculations.rb +2 -2
  94. data/app/models/alchemy/picture/transformations.rb +2 -2
  95. data/app/models/alchemy/picture/url.rb +4 -4
  96. data/app/models/alchemy/picture.rb +11 -10
  97. data/app/models/alchemy/picture_thumb/create.rb +1 -1
  98. data/app/models/alchemy/picture_thumb.rb +1 -1
  99. data/app/models/alchemy/picture_variant.rb +2 -3
  100. data/app/models/alchemy/tag.rb +8 -0
  101. data/app/models/concerns/alchemy/picture_thumbnails.rb +6 -6
  102. data/app/serializers/alchemy/base_serializer.rb +1 -1
  103. data/app/serializers/alchemy/page_tree_serializer.rb +7 -7
  104. data/app/services/alchemy/duplicate_element.rb +3 -3
  105. data/app/services/alchemy/tag_validations.rb +1 -1
  106. data/app/views/alchemy/admin/elements/_element.html.erb +3 -0
  107. data/app/views/alchemy/admin/pages/edit.html.erb +0 -3
  108. data/app/views/alchemy/admin/pages/update.js.erb +10 -4
  109. data/app/views/alchemy/admin/pictures/_infos.html.erb +1 -1
  110. data/app/views/alchemy/ingredients/_audio_view.html.erb +1 -14
  111. data/app/views/alchemy/ingredients/_boolean_view.html.erb +1 -1
  112. data/app/views/alchemy/ingredients/_datetime_view.html.erb +3 -9
  113. data/app/views/alchemy/ingredients/_file_view.html.erb +3 -16
  114. data/app/views/alchemy/ingredients/_headline_view.html.erb +4 -10
  115. data/app/views/alchemy/ingredients/_html_view.html.erb +1 -1
  116. data/app/views/alchemy/ingredients/_link_view.html.erb +4 -9
  117. data/app/views/alchemy/ingredients/_node_view.html.erb +1 -1
  118. data/app/views/alchemy/ingredients/_page_view.html.erb +1 -4
  119. data/app/views/alchemy/ingredients/_picture_view.html.erb +4 -5
  120. data/app/views/alchemy/ingredients/_richtext_editor.html.erb +11 -2
  121. data/app/views/alchemy/ingredients/_richtext_view.html.erb +3 -3
  122. data/app/views/alchemy/ingredients/_select_view.html.erb +1 -1
  123. data/app/views/alchemy/ingredients/_text_view.html.erb +3 -19
  124. data/app/views/alchemy/ingredients/_video_view.html.erb +3 -18
  125. data/app/views/alchemy/ingredients/shared/_link_tools.html.erb +1 -0
  126. data/app/views/alchemy/ingredients/shared/_picture_tools.html.erb +1 -0
  127. data/app/views/layouts/alchemy/admin.html.erb +7 -9
  128. data/bin/setup +37 -0
  129. data/bin/start +17 -0
  130. data/config/initializers/assets.rb +1 -0
  131. data/config/initializers/dragonfly.rb +1 -0
  132. data/config/initializers/mime_types.rb +1 -0
  133. data/config/initializers/mini_profiler.rb +1 -0
  134. data/config/initializers/simple_form.rb +3 -2
  135. data/config/locales/alchemy.en.yml +1 -1
  136. data/config/routes.rb +21 -20
  137. data/config/spring.rb +1 -0
  138. data/db/migrate/20230121212637_alchemy_six_point_one.rb +8 -8
  139. data/db/migrate/20230505132743_add_indexes_to_alchemy_pictures.rb +6 -0
  140. data/lib/alchemy/admin/locale.rb +3 -3
  141. data/lib/alchemy/admin/preview_url.rb +2 -2
  142. data/lib/alchemy/auth_accessors.rb +1 -1
  143. data/lib/alchemy/config.rb +1 -1
  144. data/lib/alchemy/controller_actions.rb +4 -4
  145. data/lib/alchemy/deprecation.rb +1 -0
  146. data/lib/alchemy/dragonfly/processors/thumbnail.rb +1 -1
  147. data/lib/alchemy/element_definition.rb +2 -2
  148. data/lib/alchemy/engine.rb +2 -1
  149. data/lib/alchemy/filetypes.rb +7 -7
  150. data/lib/alchemy/forms/builder.rb +4 -4
  151. data/lib/alchemy/i18n.rb +6 -4
  152. data/lib/alchemy/install/tasks.rb +2 -1
  153. data/lib/alchemy/name_conversions.rb +1 -1
  154. data/lib/alchemy/page_layout.rb +1 -1
  155. data/lib/alchemy/permissions.rb +5 -4
  156. data/lib/alchemy/resource.rb +10 -10
  157. data/lib/alchemy/resources_helper.rb +7 -7
  158. data/lib/alchemy/routing_constraints.rb +2 -2
  159. data/lib/alchemy/seeder.rb +12 -5
  160. data/lib/alchemy/shell.rb +2 -1
  161. data/lib/alchemy/taggable.rb +3 -2
  162. data/lib/alchemy/tasks/tidy.rb +1 -0
  163. data/lib/alchemy/test_support/capybara_helpers.rb +1 -1
  164. data/lib/alchemy/test_support/config_stubbing.rb +1 -0
  165. data/lib/alchemy/test_support/factories/element_factory.rb +4 -0
  166. data/lib/alchemy/test_support/factories/page_factory.rb +2 -2
  167. data/lib/alchemy/test_support/having_crop_action_examples.rb +9 -9
  168. data/lib/alchemy/test_support/having_picture_thumbnails_examples.rb +33 -33
  169. data/lib/alchemy/test_support/integration_helpers.rb +4 -3
  170. data/lib/alchemy/test_support/shared_contexts.rb +2 -1
  171. data/lib/alchemy/test_support/shared_dom_ids_examples.rb +9 -9
  172. data/lib/alchemy/test_support/shared_ingredient_examples.rb +12 -6
  173. data/lib/alchemy/test_support/shared_uploader_examples.rb +1 -0
  174. data/lib/alchemy/tinymce.rb +3 -26
  175. data/lib/alchemy/upgrader.rb +1 -0
  176. data/lib/alchemy/version.rb +1 -1
  177. data/lib/alchemy_cms.rb +1 -0
  178. data/lib/generators/alchemy/base.rb +3 -2
  179. data/lib/generators/alchemy/elements/elements_generator.rb +2 -1
  180. data/lib/generators/alchemy/ingredient/ingredient_generator.rb +1 -0
  181. data/lib/generators/alchemy/install/files/application.html.erb +1 -1
  182. data/lib/generators/alchemy/install/install_generator.rb +2 -1
  183. data/lib/generators/alchemy/module/module_generator.rb +1 -0
  184. data/lib/generators/alchemy/page_layouts/page_layouts_generator.rb +1 -0
  185. data/lib/generators/alchemy/site_layouts/site_layouts_generator.rb +1 -0
  186. data/lib/generators/alchemy/views/views_generator.rb +2 -1
  187. data/lib/tasks/alchemy/thumbnails.rake +5 -5
  188. data/lib/tasks/alchemy/tidy.rake +1 -0
  189. data/lib/tasks/alchemy/upgrade.rake +6 -5
  190. data/package/admin.js +2 -0
  191. data/package/dist/admin.js +3 -3
  192. data/package/dist/admin.js.map +4 -4
  193. data/package/src/datepicker.js +1 -0
  194. data/package/src/tinymce.js +142 -0
  195. data/package.json +2 -2
  196. metadata +39 -7
  197. data/app/assets/javascripts/alchemy/alchemy.tinymce.js.coffee +0 -93
  198. data/app/presenters/alchemy/picture_view.rb +0 -88
  199. data/app/views/alchemy/admin/pages/_tinymce_custom_config.html.erb +0 -10
@@ -25,7 +25,7 @@ module Alchemy
25
25
  THUMBNAIL_SIZES = {
26
26
  small: "80x60",
27
27
  medium: "160x120",
28
- large: "240x180",
28
+ large: "240x180"
29
29
  }.with_indifferent_access.freeze
30
30
 
31
31
  CONVERTIBLE_FILE_FORMATS = %w[gif jpg jpeg png webp].freeze
@@ -38,7 +38,7 @@ module Alchemy
38
38
  :format,
39
39
  :quality,
40
40
  :size,
41
- :upsample,
41
+ :upsample
42
42
  ]
43
43
 
44
44
  include Alchemy::Logger
@@ -64,7 +64,7 @@ module Alchemy
64
64
  # to ensure this runs before Dragonfly's before_destroy callback.
65
65
  #
66
66
  before_destroy unless: :deletable? do
67
- raise PictureInUseError, Alchemy.t(:cannot_delete_picture_notice) % { name: name }
67
+ raise PictureInUseError, Alchemy.t(:cannot_delete_picture_notice) % {name: name}
68
68
  end
69
69
 
70
70
  # Image preprocessing class
@@ -117,7 +117,7 @@ module Alchemy
117
117
  -> {
118
118
  where("#{table_name}.id NOT IN (SELECT related_object_id FROM alchemy_ingredients WHERE related_object_type = 'Alchemy::Picture')")
119
119
  }
120
- scope :without_tag, -> { left_outer_joins(:taggings).where(gutentag_taggings: { id: nil }) }
120
+ scope :without_tag, -> { left_outer_joins(:taggings).where(gutentag_taggings: {id: nil}) }
121
121
  scope :by_file_format, ->(format) { where(image_file_format: format) }
122
122
 
123
123
  # Class methods
@@ -138,20 +138,21 @@ module Alchemy
138
138
  end
139
139
 
140
140
  def alchemy_resource_filters
141
+ @_file_formats ||= distinct.pluck(:image_file_format).compact.presence || []
141
142
  [
142
143
  {
143
144
  name: :by_file_format,
144
- values: distinct.pluck(:image_file_format),
145
+ values: @_file_formats
145
146
  },
146
147
  {
147
148
  name: :misc,
148
- values: %w(recent last_upload without_tag),
149
- },
149
+ values: %w[recent last_upload without_tag deletable]
150
+ }
150
151
  ]
151
152
  end
152
153
 
153
154
  def searchable_alchemy_resource_attributes
154
- %w(name image_file_name)
155
+ %w[name image_file_name]
155
156
  end
156
157
 
157
158
  def last_upload
@@ -183,7 +184,7 @@ module Alchemy
183
184
  options.except(*TRANSFORMATION_OPTIONS).merge(
184
185
  basename: name,
185
186
  ext: variant.render_format,
186
- name: name,
187
+ name: name
187
188
  )
188
189
  )
189
190
  rescue ::Dragonfly::Job::Fetch::NotFound => e
@@ -211,7 +212,7 @@ module Alchemy
211
212
  {
212
213
  name: image_file_name,
213
214
  size: image_file_size,
214
- error: errors[:image_file].join,
215
+ error: errors[:image_file].join
215
216
  }
216
217
  end
217
218
 
@@ -27,7 +27,7 @@ module Alchemy
27
27
  end
28
28
  begin
29
29
  Alchemy::PictureThumb.storage_class.call(variant, uid)
30
- rescue StandardError => e
30
+ rescue => e
31
31
  ErrorTracking.notification_handler.call(e)
32
32
  # destroy the thumb if processing or storing fails
33
33
  @thumb&.destroy
@@ -42,7 +42,7 @@ module Alchemy
42
42
  Alchemy::Picture::THUMBNAIL_SIZES.values.each do |size|
43
43
  variant = Alchemy::PictureVariant.new(picture, {
44
44
  size: size,
45
- flatten: true,
45
+ flatten: true
46
46
  })
47
47
  signature = Alchemy::PictureThumb::Signature.call(variant)
48
48
  thumb = find_by(signature: signature)
@@ -54,8 +54,7 @@ module Alchemy
54
54
  raise MissingImageFileError, "Missing image file for #{picture.inspect}" if image.nil?
55
55
 
56
56
  image = processed_image(image, @options)
57
- image = encoded_image(image, @options)
58
- image
57
+ encoded_image(image, @options)
59
58
  rescue MissingImageFileError, WrongImageFormatError => e
60
59
  log_warning(e.message)
61
60
  nil
@@ -88,7 +87,7 @@ module Alchemy
88
87
  end
89
88
 
90
89
  options = {
91
- flatten: !render_format.in?(ANIMATED_IMAGE_FORMATS) && picture.image_file_format == "gif",
90
+ flatten: !render_format.in?(ANIMATED_IMAGE_FORMATS) && picture.image_file_format == "gif"
92
91
  }.with_indifferent_access.merge(options)
93
92
 
94
93
  encoding_options = []
@@ -13,6 +13,14 @@
13
13
  # The original Tag model is Gutentag::Tag
14
14
  module Alchemy
15
15
  class Tag < Gutentag::Tag
16
+ def self.ransackable_attributes(_auth_object = nil)
17
+ %w[created_at id name taggings_count updated_at]
18
+ end
19
+
20
+ def self.ransackable_associations(_auth_object = nil)
21
+ %w[taggings]
22
+ end
23
+
16
24
  # Replaces tag with new tag on all models tagged with tag.
17
25
  def self.replace(tag, new_tag)
18
26
  tag.taggings.collect(&:taggable).each do |taggable|
@@ -56,7 +56,7 @@ module Alchemy
56
56
  crop: crop,
57
57
  crop_from: crop && crop_from.presence || nil,
58
58
  crop_size: crop && crop_size.presence || nil,
59
- size: settings[:size],
59
+ size: settings[:size]
60
60
  }.with_indifferent_access
61
61
  end
62
62
 
@@ -84,7 +84,7 @@ module Alchemy
84
84
  crop_from: crop && crop_from.presence || default_crop_from&.join("x"),
85
85
  crop_size: crop && crop_size.presence || default_crop_size&.join("x"),
86
86
  flatten: true,
87
- format: picture&.image_file_format || "jpg",
87
+ format: picture&.image_file_format || "jpg"
88
88
  }
89
89
  end
90
90
 
@@ -96,7 +96,7 @@ module Alchemy
96
96
  default_crop_size: default_crop_size,
97
97
  fixed_ratio: settings[:fixed_ratio],
98
98
  image_width: picture&.image_file_width,
99
- image_height: picture&.image_file_height,
99
+ image_height: picture&.image_file_height
100
100
  ).to_h
101
101
  end
102
102
 
@@ -105,7 +105,7 @@ module Alchemy
105
105
  settings[:crop] && picture &&
106
106
  picture.can_be_cropped_to?(
107
107
  settings[:size],
108
- settings[:upsample],
108
+ settings[:upsample]
109
109
  ) && !!picture.image_file
110
110
  end
111
111
 
@@ -124,7 +124,7 @@ module Alchemy
124
124
  def thumbnail_zoom_factor(mask)
125
125
  [
126
126
  mask[0].to_f / (image_file_width || 1),
127
- mask[1].to_f / (image_file_height || 1),
127
+ mask[1].to_f / (image_file_height || 1)
128
128
  ].max
129
129
  end
130
130
 
@@ -134,7 +134,7 @@ module Alchemy
134
134
 
135
135
  [
136
136
  ((image_file_width || 0) - default_crop_size[0]) / 2,
137
- ((image_file_height || 0) - default_crop_size[1]) / 2,
137
+ ((image_file_height || 0) - default_crop_size[1]) / 2
138
138
  ].map(&:round)
139
139
  end
140
140
 
@@ -14,7 +14,7 @@ module Alchemy
14
14
  # The attributes to be serialized. See ActiveModel::Serialization.
15
15
  # By default, serialize all columns from the AR object.
16
16
  def attributes
17
- Hash[object.class.column_names.map { |c| [c, nil] }]
17
+ object.class.column_names.map { |c| [c, nil] }.to_h
18
18
  end
19
19
 
20
20
  private
@@ -3,13 +3,13 @@
3
3
  module Alchemy
4
4
  class PageTreeSerializer < BaseSerializer
5
5
  def attributes
6
- { "pages" => nil }
6
+ {"pages" => nil}
7
7
  end
8
8
 
9
9
  def pages
10
10
  tree = []
11
- path = [{ id: object.parent_id, children: tree }]
12
- page_list = object.self_and_descendants.includes(:public_version, { language: :site })
11
+ path = [{id: object.parent_id, children: tree}]
12
+ page_list = object.self_and_descendants.includes(:public_version, {language: :site})
13
13
  base_level = object.level - 1
14
14
  # Load folded pages in advance
15
15
  folded_user_pages = FoldedPage.folded_for_user(opts[:user]).pluck(:page_id)
@@ -61,7 +61,7 @@ module Alchemy
61
61
  level: level,
62
62
  root: page.root?,
63
63
  root_or_leaf: page.root? || page.leaf?,
64
- children: [],
64
+ children: []
65
65
  }
66
66
 
67
67
  if opts[:elements]
@@ -75,7 +75,7 @@ module Alchemy
75
75
  locked: page.locked?,
76
76
  locked_notice: page.locked? ? Alchemy.t("This page is locked", name: page.locker_name) : nil,
77
77
  permissions: page_permissions(page, opts[:ability]),
78
- status_titles: page_status_titles(page),
78
+ status_titles: page_status_titles(page)
79
79
  })
80
80
  else
81
81
  p_hash
@@ -98,14 +98,14 @@ module Alchemy
98
98
  copy: ability.can?(:copy, page),
99
99
  destroy: ability.can?(:destroy, page),
100
100
  create: ability.can?(:create, Alchemy::Page),
101
- edit_content: ability.can?(:edit_content, page),
101
+ edit_content: ability.can?(:edit_content, page)
102
102
  }
103
103
  end
104
104
 
105
105
  def page_status_titles(page)
106
106
  {
107
107
  public: page.status_title(:public),
108
- restricted: page.status_title(:restricted),
108
+ restricted: page.status_title(:restricted)
109
109
  }
110
110
  end
111
111
  end
@@ -10,7 +10,7 @@ module Alchemy
10
10
  "id",
11
11
  "folded",
12
12
  "updated_at",
13
- "updater_id",
13
+ "updater_id"
14
14
  ].freeze
15
15
 
16
16
  attr_reader :source_element, :repository
@@ -27,7 +27,7 @@ module Alchemy
27
27
  .merge(
28
28
  autogenerate_ingredients: false,
29
29
  autogenerate_nested_elements: false,
30
- tags: source_element.tags,
30
+ tags: source_element.tags
31
31
  )
32
32
 
33
33
  new_element = Element.new(attributes)
@@ -40,7 +40,7 @@ module Alchemy
40
40
  self.class.new(nested_element, repository: repository).call(
41
41
  parent_element: new_element,
42
42
  page_version: new_element.page_version,
43
- position: position,
43
+ position: position
44
44
  )
45
45
  end
46
46
  end
@@ -11,7 +11,7 @@ module Alchemy
11
11
  end
12
12
 
13
13
  def call
14
- klass.validates :name, presence: true, uniqueness: { case_sensitive: true }
14
+ klass.validates :name, presence: true, uniqueness: {case_sensitive: true}
15
15
  end
16
16
 
17
17
  private
@@ -56,6 +56,9 @@
56
56
  <% end %>
57
57
  <% end %>
58
58
 
59
+ <%# We need to render nested elements even if the element is folded,
60
+ because we need the element present in the DOM for the feature
61
+ "click element in the preview => load and expand element editor". %>
59
62
  <% if element.nestable_elements.any? %>
60
63
  <div class="nestable-elements">
61
64
  <%= content_tag :div,
@@ -138,9 +138,6 @@
138
138
  <% end %>
139
139
 
140
140
  <% content_for :javascripts do %>
141
- <% if Alchemy::Tinymce.custom_configs_present?(@page) %>
142
- <%= render 'tinymce_custom_config' %>
143
- <% end %>
144
141
 
145
142
  <% content_for :javascript_includes do %>
146
143
  <meta name="turbolinks-cache-control" content="no-cache">
@@ -18,10 +18,16 @@
18
18
  <% else -%>
19
19
 
20
20
  if (page) {
21
- var page_html = "<%= j render('page', page: @page) %>".replace(/__ID__/g, "<%= @page.id %>");;
22
- var compiler = Handlebars.compile(page_html);
23
- var tree = <%== @tree.to_json %>;
24
- page.outerHTML = compiler(tree.pages[0]);
21
+
22
+ <% if @page.layoutpage %>
23
+ page.outerHTML = "<%= j render('alchemy/admin/layoutpages/layoutpage', layoutpage: @page) %>"
24
+ <% else %>
25
+ const page_html = "<%= j render('page', page: @page) %>".replace(/__ID__/g, "<%= @page.id %>");
26
+ const compiler = Handlebars.compile(page_html);
27
+ const tree = <%== @tree.to_json %>;
28
+ page.outerHTML = compiler(tree.pages[0]);
29
+ <% end %>
30
+
25
31
  Alchemy.growl("<%= j @notice %>");
26
32
  Alchemy.closeCurrentDialog();
27
33
  } else {
@@ -34,7 +34,7 @@
34
34
  <li class="<%= cycle('even', 'odd') %>">
35
35
  <% page_link = link_to element.display_name_with_preview_text,
36
36
  edit_admin_page_path(page, anchor: "element_#{element.id}") %>
37
- <% ingredients = picture_ingredients.collect(&:translated_role).to_sentence %>
37
+ <% ingredients = picture_ingredients.map { |p| Alchemy::IngredientEditor.new(p).translated_role }.to_sentence %>
38
38
  <% if element.public? %>
39
39
  <%= render_icon('window-maximize', style: 'regular') %>
40
40
  <% else %>
@@ -1,14 +1 @@
1
- <%- if audio_view.attachment -%>
2
- <%= content_tag :audio,
3
- controls: audio_view.controls,
4
- autoplay: audio_view.autoplay,
5
- loop: audio_view.loop,
6
- muted: audio_view.muted do %>
7
- <%= tag :source,
8
- src: alchemy.show_attachment_path(
9
- audio_view.attachment,
10
- format: audio_view.attachment.suffix
11
- ),
12
- type: audio_view.attachment.file_mime_type %>
13
- <% end %>
14
- <%- end -%>
1
+ <%= render audio_view.as_view_component -%>
@@ -1 +1 @@
1
- <%= Alchemy.t(boolean_view.value, scope: "ingredient_values.boolean") unless boolean_view.value.nil? -%>
1
+ <%= render boolean_view.as_view_component -%>
@@ -1,9 +1,3 @@
1
- <%- date_format = datetime_view.settings_value(:date_format,
2
- local_assigns.fetch(:options, {})) -%>
3
- <%- if datetime_view.value.present? -%>
4
- <%- if date_format == 'rfc822' -%>
5
- <%= datetime_view.value.to_s(:rfc822) %>
6
- <%- else -%>
7
- <%= l(datetime_view.value, format: date_format) %>
8
- <%- end -%>
9
- <%- end -%>
1
+ <%= render datetime_view.as_view_component(
2
+ **local_assigns.slice(:options)
3
+ ) -%>
@@ -1,17 +1,4 @@
1
- <%- if attachment = file_view.attachment -%>
2
- <%- html_options = local_assigns.fetch(:html_options, {}) -%>
3
- <%= link_to(
4
- file_view.link_text.presence ||
5
- file_view.settings_value(:link_text, local_assigns.fetch(:options, {})) ||
6
- attachment.name,
7
- attachment.url(
8
- download: true,
9
- name: attachment.slug,
10
- format: attachment.suffix
11
- ),
12
- {
13
- class: file_view.css_class.presence,
14
- title: file_view.title.presence
15
- }.merge(html_options)
1
+ <%= render file_view.as_view_component(
2
+ **local_assigns.slice(:options),
3
+ **local_assigns.slice(:html_options)
16
4
  ) -%>
17
- <%- end -%>
@@ -1,10 +1,4 @@
1
- <%- html_options = local_assigns.fetch(:html_options, {}) -%>
2
-
3
- <%= content_tag "h#{headline_view.level}",
4
- headline_view.value,
5
- id: headline_view.dom_id.presence,
6
- class: [
7
- headline_view.size ? "h#{headline_view.size}" : nil,
8
- html_options[:class]
9
- ]
10
- %>
1
+ <%= render headline_view.as_view_component(
2
+ **local_assigns.slice(:options),
3
+ **local_assigns.slice(:html_options)
4
+ ) -%>
@@ -1 +1 @@
1
- <%= raw html_view.value -%>
1
+ <%= render html_view.as_view_component -%>
@@ -1,9 +1,4 @@
1
- <%- if link_view.value.present? -%>
2
- <%- html_options = {
3
- target: link_view.link_target == "blank" ? "_blank" : nil
4
- }.merge(local_assigns.fetch(:html_options, {})) -%>
5
- <%= link_to(link_view.value, html_options) do -%>
6
- <%= link_view.settings_value(:text, local_assigns.fetch(:options, {})) ||
7
- link_view.value -%>
8
- <%- end -%>
9
- <%- end -%>
1
+ <%= render link_view.as_view_component(
2
+ **local_assigns.slice(:options),
3
+ **local_assigns.slice(:html_options)
4
+ ) -%>
@@ -1 +1 @@
1
- <%= render node_view.node if node_view.node %>
1
+ <%= render node_view.as_view_component -%>
@@ -1,4 +1 @@
1
- <% page = page_view.page %>
2
- <% if page %>
3
- <%= link_to page.name, alchemy.show_page_path(urlname: page.urlname) %>
4
- <% end %>
1
+ <%= render page_view.as_view_component -%>
@@ -1,5 +1,4 @@
1
- <%= Alchemy::PictureView.new(
2
- picture_view,
3
- local_assigns[:options],
4
- local_assigns[:html_options]
5
- ).render %>
1
+ <%= render picture_view.as_view_component(
2
+ **local_assigns.slice(:options),
3
+ **local_assigns.slice(:html_options)
4
+ ) -%>
@@ -5,8 +5,17 @@
5
5
  <%= ingredient_label(richtext_editor) %>
6
6
  <div class="tinymce_container">
7
7
  <%= f.text_area :value,
8
- class: richtext_editor.tinymce_class_name,
9
- id: "tinymce_#{richtext_editor.id}" %>
8
+ class: "has_tinymce",
9
+ id: richtext_editor.element_id %>
10
10
  </div>
11
11
  <% end %>
12
+ <% if richtext_editor.has_custom_tinymce_config? %>
13
+ <script type="text/javascript" charset="utf-8">
14
+ Alchemy.Tinymce.setCustomConfig("<%= richtext_editor.element_id %>", {
15
+ <% richtext_editor.custom_tinymce_config.each do |k, v| %>
16
+ <%= k %>: <%== v.to_json %>,
17
+ <% end %>
18
+ });
19
+ </script>
20
+ <% end %>
12
21
  <% end %>
@@ -1,3 +1,3 @@
1
- <%- options = local_assigns.fetch(:options, {}) -%>
2
- <%- plain_text = !!richtext_view.settings_value(:plain_text, options) -%>
3
- <%= raw richtext_view.public_send(plain_text ? :stripped_body : :value) -%>
1
+ <%= render richtext_view.as_view_component(
2
+ **local_assigns.slice(:options)
3
+ ) -%>
@@ -1 +1 @@
1
- <%= select_view.value %>
1
+ <%= render select_view.as_view_component -%>
@@ -1,20 +1,4 @@
1
- <%- options = local_assigns.fetch(:options, {}) -%>
2
- <%- html_options = local_assigns.fetch(:html_options, {}) -%>
3
- <%- if text_view.link.blank? || text_view.settings_value(:disable_link, options) -%>
4
- <%- if text_view.dom_id.present? -%>
5
- <%= content_tag :a, text_view.value, id: text_view.dom_id %>
6
- <% else %>
7
- <%= text_view.value -%>
8
- <%- end -%>
9
- <%- else -%>
10
- <%= link_to(
11
- text_view.value,
12
- url_for(text_view.link),
13
- {
14
- id: text_view.dom_id.presence,
15
- title: text_view.link_title,
16
- target: (text_view.link_target == "blank" ? "_blank" : nil),
17
- 'data-link-target' => text_view.link_target
18
- }.merge(html_options)
1
+ <%= render text_view.as_view_component(
2
+ **local_assigns.slice(:options),
3
+ **local_assigns.slice(:html_options)
19
4
  ) -%>
20
- <%- end -%>
@@ -1,18 +1,3 @@
1
- <%- if video_view.attachment -%>
2
- <%= content_tag :video,
3
- controls: video_view.controls,
4
- autoplay: video_view.autoplay,
5
- loop: video_view.loop,
6
- muted: video_view.muted,
7
- playsinline: video_view.playsinline,
8
- preload: video_view.preload.presence,
9
- width: video_view.width.presence,
10
- height: video_view.height.presence do %>
11
- <%= tag :source,
12
- src: alchemy.show_attachment_path(
13
- video_view.attachment,
14
- format: video_view.attachment.suffix
15
- ),
16
- type: video_view.attachment.file_mime_type %>
17
- <% end %>
18
- <%- end -%>
1
+ <%= render video_view.as_view_component(
2
+ **local_assigns.slice(:html_options)
3
+ ) -%>
@@ -5,6 +5,7 @@
5
5
  onclick: 'new Alchemy.LinkDialog(this).open(); return false;',
6
6
  class: "icon_button#{ingredient_editor.linked? ? ' linked' : ''} link-ingredient",
7
7
  "data-parent-selector": "[data-ingredient-id='#{ingredient_editor.id}']",
8
+ "data-language-id": ingredient_editor.page&.language_id,
8
9
  title: Alchemy.t(:place_link),
9
10
  id: "edit_link_#{ingredient_editor.id}"
10
11
  ) %>
@@ -34,6 +34,7 @@
34
34
  class: picture_editor.linked? ? "linked" : nil,
35
35
  title: Alchemy.t(:link_image),
36
36
  "data-parent-selector": "[data-ingredient-id='#{picture_editor.id}']",
37
+ "data-language-id": picture_editor.page&.language_id,
37
38
  id: "edit_link_#{picture_editor.id}"
38
39
  } do %>
39
40
  <span class="disabled" tabindex="-1"><%= render_icon(:link) %></span>
@@ -25,21 +25,19 @@
25
25
  // Store regular expression for external link url matching.
26
26
  Alchemy.link_url_regexp = <%= link_url_regexp.inspect %>;
27
27
  // Holds the default Alchemy TinyMCE configuration
28
- Alchemy.Tinymce = {
29
- defaults: {
30
- plugins: '<%= Alchemy::Tinymce.plugins.join(',') %>',
31
- <% Alchemy::Tinymce.init.each do |k, v| %>
32
- <%= k %>: <%== v.to_json %>,
33
- <% end %>
34
- }
28
+ Alchemy.TinymceDefaults = {
29
+ plugins: '<%= Alchemy::Tinymce.plugins.join(',') %>',
30
+ <% Alchemy::Tinymce.init.each do |k, v| %>
31
+ <%= k %>: <%== v.to_json %>,
32
+ <% end %>
35
33
  };
36
34
  </script>
37
35
  <%= render 'alchemy/admin/partials/routes' %>
38
36
  <%= javascript_include_tag('alchemy/admin/all', 'data-turbolinks-track' => true) %>
39
37
  <% if respond_to?(:javascript_pack_tag) %>
40
- <%= javascript_pack_tag('alchemy/admin', 'data-turbolinks-track' => true, defer: true) %>
38
+ <%= javascript_pack_tag('alchemy/admin', 'data-turbolinks-track' => true) %>
41
39
  <% else %>
42
- <%= javascript_include_tag('alchemy_admin', 'data-turbolinks-track' => true, defer: true) %>
40
+ <%= javascript_include_tag('alchemy_admin', 'data-turbolinks-track' => true) %>
43
41
  <% end %>
44
42
  <%= yield :javascript_includes %>
45
43
  </head>
data/bin/setup ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ require "fileutils"
3
+
4
+ # path to dummy application root.
5
+ APP_ROOT = File.expand_path("../spec/dummy", __dir__)
6
+
7
+ # path to alchemy gem
8
+ GEM_ROOT = File.expand_path("../", __dir__)
9
+
10
+ def system!(*args)
11
+ system(*args) || abort("\n== Command #{args} failed ==")
12
+ end
13
+
14
+ FileUtils.chdir GEM_ROOT do
15
+ puts "\n== Linking Admin JS package =="
16
+ system! "yarn link"
17
+ puts "== Installing dependencies =="
18
+ system! "yarn install"
19
+ system! "gem install bundler --conservative"
20
+ system("bundle check") || system!("bundle install")
21
+ end
22
+
23
+ FileUtils.chdir APP_ROOT do
24
+ puts "\n== Installing Alchemy into dummy app =="
25
+ system!("bin/rails javascript:install:esbuild")
26
+ system!("bin/rails g alchemy:install --skip --skip-demo-files --auto-accept")
27
+
28
+ puts "\n== Link Alchemy admin package =="
29
+ system! "yarn link @alchemy_cms/admin"
30
+ system! "yarn install"
31
+
32
+ puts "\n== Removing old logs and tempfiles =="
33
+ system! "bin/rails log:clear tmp:clear"
34
+ end
35
+
36
+ puts "\n== Alchemy is ready 🎉 =="
37
+ puts "Start server by typing:\n\n bin/start"
data/bin/start ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require "fileutils"
3
+
4
+ # path to dummy application root.
5
+ APP_ROOT = File.expand_path("../spec/dummy", __dir__)
6
+
7
+ # path to alchemy gem
8
+ GEM_ROOT = File.expand_path("../", __dir__)
9
+
10
+ def system!(*args)
11
+ system(*args) || abort("\n== Command #{args} failed ==")
12
+ end
13
+
14
+ FileUtils.chdir APP_ROOT do
15
+ puts "\n== Starting dummy app =="
16
+ system! "bin/dev"
17
+ end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Add Alchemy assets for precompiling
3
4
  Rails.application.config.assets.precompile << "alchemy_manifest.js"