alchemy_cms 6.1.10 → 7.0.0.pre.a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +0 -3
  3. data/.gitignore +1 -6
  4. data/CHANGELOG.md +19 -44
  5. data/Gemfile +1 -1
  6. data/Rakefile +14 -9
  7. data/alchemy_cms.gemspec +2 -3
  8. data/app/assets/javascripts/alchemy/alchemy.dirty.js.coffee +1 -1
  9. data/app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee +18 -32
  10. data/app/assets/javascripts/alchemy/alchemy.elements_window.js.coffee +2 -2
  11. data/app/assets/javascripts/alchemy/alchemy.gui.js.coffee +2 -2
  12. data/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee +27 -29
  13. data/app/assets/stylesheets/alchemy/elements.scss +16 -35
  14. data/app/assets/stylesheets/alchemy/forms.scss +0 -4
  15. data/app/assets/stylesheets/alchemy/node-select.scss +2 -2
  16. data/app/controllers/alchemy/admin/attachments_controller.rb +0 -1
  17. data/app/controllers/alchemy/admin/elements_controller.rb +7 -32
  18. data/app/controllers/alchemy/admin/pages_controller.rb +1 -1
  19. data/app/controllers/alchemy/admin/pictures_controller.rb +1 -1
  20. data/app/controllers/alchemy/admin/resources_controller.rb +1 -18
  21. data/app/controllers/alchemy/api/elements_controller.rb +0 -2
  22. data/app/controllers/alchemy/api/pages_controller.rb +8 -4
  23. data/app/controllers/alchemy/messages_controller.rb +9 -9
  24. data/app/controllers/alchemy/pages_controller.rb +23 -18
  25. data/app/decorators/alchemy/element_editor.rb +10 -30
  26. data/app/helpers/alchemy/admin/elements_helper.rb +0 -2
  27. data/app/helpers/alchemy/elements_block_helper.rb +5 -42
  28. data/app/helpers/alchemy/elements_helper.rb +3 -11
  29. data/app/helpers/alchemy/pages_helper.rb +0 -4
  30. data/app/models/alchemy/attachment.rb +6 -3
  31. data/app/models/alchemy/base_record.rb +2 -0
  32. data/app/models/alchemy/eager_loading.rb +0 -1
  33. data/app/models/alchemy/element/element_ingredients.rb +1 -8
  34. data/app/models/alchemy/element/presenters.rb +9 -25
  35. data/app/models/alchemy/element.rb +2 -18
  36. data/app/models/alchemy/ingredient.rb +17 -6
  37. data/app/models/alchemy/ingredients/audio.rb +2 -0
  38. data/app/models/alchemy/ingredients/datetime.rb +3 -1
  39. data/app/models/alchemy/ingredients/file.rb +7 -0
  40. data/app/models/alchemy/ingredients/headline.rb +6 -0
  41. data/app/models/alchemy/ingredients/link.rb +2 -0
  42. data/app/models/alchemy/ingredients/node.rb +2 -0
  43. data/app/models/alchemy/ingredients/page.rb +2 -0
  44. data/app/models/alchemy/ingredients/picture.rb +11 -0
  45. data/app/models/alchemy/ingredients/richtext.rb +6 -0
  46. data/app/models/alchemy/ingredients/select.rb +1 -0
  47. data/app/models/alchemy/ingredients/text.rb +8 -0
  48. data/app/models/alchemy/ingredients/video.rb +2 -0
  49. data/app/models/alchemy/node.rb +9 -6
  50. data/app/models/alchemy/page/page_elements.rb +5 -26
  51. data/app/models/alchemy/page/page_layouts.rb +0 -14
  52. data/app/models/alchemy/page/page_natures.rb +0 -10
  53. data/app/models/alchemy/page.rb +0 -10
  54. data/app/models/alchemy/picture/transformations.rb +0 -30
  55. data/app/models/alchemy/picture/url.rb +1 -1
  56. data/app/models/alchemy/picture.rb +14 -13
  57. data/app/models/alchemy/picture_thumb/create.rb +7 -18
  58. data/app/models/alchemy/picture_thumb/file_store.rb +33 -0
  59. data/app/models/alchemy/picture_thumb.rb +10 -10
  60. data/app/models/concerns/alchemy/picture_thumbnails.rb +2 -6
  61. data/app/serializers/alchemy/element_serializer.rb +1 -6
  62. data/app/services/alchemy/delete_elements.rb +1 -7
  63. data/app/services/alchemy/duplicate_element.rb +1 -6
  64. data/app/views/alchemy/admin/elements/_element.html.erb +5 -22
  65. data/app/views/alchemy/admin/elements/create.js.erb +1 -1
  66. data/app/views/alchemy/admin/elements/fold.js.erb +2 -2
  67. data/app/views/alchemy/admin/elements/order.js.erb +1 -1
  68. data/app/views/alchemy/admin/elements/update.js.erb +1 -2
  69. data/app/views/alchemy/admin/pages/_external_link.html.erb +2 -2
  70. data/app/views/alchemy/admin/pages/_file_link.html.erb +2 -2
  71. data/app/views/alchemy/admin/pages/_internal_link.html.erb +2 -2
  72. data/app/views/alchemy/admin/pages/_table.html.erb +0 -6
  73. data/app/views/alchemy/admin/pages/_tinymce_custom_config.html.erb +3 -6
  74. data/app/views/alchemy/admin/pages/edit.html.erb +1 -1
  75. data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +1 -3
  76. data/app/views/alchemy/admin/pictures/_infos.html.erb +4 -6
  77. data/app/views/alchemy/admin/resources/_per_page_select.html.erb +1 -1
  78. data/app/views/alchemy/ingredients/_boolean_editor.html.erb +1 -1
  79. data/app/views/alchemy/ingredients/_headline_editor.html.erb +1 -1
  80. data/app/views/alchemy/ingredients/_html_editor.html.erb +1 -1
  81. data/app/views/alchemy/ingredients/_node_editor.html.erb +1 -1
  82. data/app/views/alchemy/ingredients/_picture_editor.html.erb +4 -4
  83. data/app/views/alchemy/ingredients/_select_editor.html.erb +2 -2
  84. data/app/views/alchemy/ingredients/_text_editor.html.erb +1 -1
  85. data/app/views/alchemy/ingredients/shared/_link_tools.html.erb +3 -3
  86. data/app/views/alchemy/pages/_meta_data.html.erb +0 -1
  87. data/app/views/layouts/alchemy/admin.html.erb +5 -1
  88. data/config/alchemy/config.yml +6 -6
  89. data/config/brakeman.ignore +56 -57
  90. data/config/locales/alchemy.en.yml +99 -113
  91. data/config/routes.rb +1 -16
  92. data/db/migrate/20230121212637_alchemy_six_point_one.rb +248 -0
  93. data/lib/alchemy/cache_digests/template_tracker.rb +6 -7
  94. data/lib/alchemy/config.rb +2 -2
  95. data/lib/alchemy/deprecation.rb +1 -1
  96. data/lib/alchemy/errors.rb +0 -11
  97. data/lib/alchemy/hints.rb +10 -10
  98. data/lib/alchemy/permissions.rb +4 -17
  99. data/lib/alchemy/routing_constraints.rb +3 -3
  100. data/lib/alchemy/searchable_resource.rb +38 -0
  101. data/lib/alchemy/seeder.rb +2 -8
  102. data/lib/alchemy/tasks/tidy.rb +0 -38
  103. data/lib/alchemy/test_support/capybara_helpers.rb +69 -0
  104. data/lib/alchemy/test_support/factories/element_factory.rb +0 -6
  105. data/lib/alchemy/test_support/factories/ingredient_factory.rb +1 -1
  106. data/lib/alchemy/test_support/factories/page_factory.rb +4 -2
  107. data/lib/alchemy/test_support/having_picture_thumbnails_examples.rb +0 -20
  108. data/lib/alchemy/test_support/shared_dom_ids_examples.rb +1 -1
  109. data/lib/alchemy/test_support/shared_ingredient_examples.rb +1 -1
  110. data/lib/alchemy/tinymce.rb +1 -18
  111. data/lib/alchemy/upgrader/seven_point_zero.rb +45 -0
  112. data/lib/alchemy/upgrader/tasks/.keep +0 -0
  113. data/lib/alchemy/upgrader.rb +8 -3
  114. data/lib/alchemy/version.rb +1 -1
  115. data/lib/alchemy.rb +0 -19
  116. data/lib/alchemy_cms.rb +1 -2
  117. data/lib/generators/alchemy/elements/elements_generator.rb +0 -1
  118. data/lib/generators/alchemy/elements/templates/view.html.erb +1 -10
  119. data/lib/generators/alchemy/elements/templates/view.html.haml +1 -9
  120. data/lib/generators/alchemy/elements/templates/view.html.slim +1 -9
  121. data/lib/generators/alchemy/install/files/alchemy.en.yml +7 -8
  122. data/lib/generators/alchemy/install/files/application.html.erb +1 -1
  123. data/lib/generators/alchemy/install/install_generator.rb +18 -34
  124. data/lib/generators/alchemy/install/templates/elements.yml.tt +12 -12
  125. data/lib/non_stupid_digest_assets.rb +1 -1
  126. data/lib/tasks/alchemy/thumbnails.rake +2 -21
  127. data/lib/tasks/alchemy/tidy.rake +1 -12
  128. data/lib/tasks/alchemy/upgrade.rake +10 -47
  129. data/package/dist/admin.js +16 -0
  130. data/package/dist/admin.js.map +7 -0
  131. data/package.json +5 -3
  132. metadata +18 -147
  133. data/app/controllers/alchemy/admin/contents_controller.rb +0 -21
  134. data/app/controllers/alchemy/admin/essence_audios_controller.rb +0 -30
  135. data/app/controllers/alchemy/admin/essence_files_controller.rb +0 -31
  136. data/app/controllers/alchemy/admin/essence_pictures_controller.rb +0 -43
  137. data/app/controllers/alchemy/admin/essence_videos_controller.rb +0 -34
  138. data/app/controllers/alchemy/api/contents_controller.rb +0 -52
  139. data/app/decorators/alchemy/content_editor.rb +0 -119
  140. data/app/helpers/alchemy/admin/contents_helper.rb +0 -42
  141. data/app/helpers/alchemy/admin/essences_helper.rb +0 -31
  142. data/app/models/alchemy/content/factory.rb +0 -143
  143. data/app/models/alchemy/content.rb +0 -247
  144. data/app/models/alchemy/element/element_contents.rb +0 -200
  145. data/app/models/alchemy/element/element_essences.rb +0 -133
  146. data/app/models/alchemy/essence_audio.rb +0 -13
  147. data/app/models/alchemy/essence_boolean.rb +0 -20
  148. data/app/models/alchemy/essence_date.rb +0 -25
  149. data/app/models/alchemy/essence_file.rb +0 -49
  150. data/app/models/alchemy/essence_headline.rb +0 -41
  151. data/app/models/alchemy/essence_html.rb +0 -23
  152. data/app/models/alchemy/essence_link.rb +0 -21
  153. data/app/models/alchemy/essence_node.rb +0 -19
  154. data/app/models/alchemy/essence_page.rb +0 -17
  155. data/app/models/alchemy/essence_picture.rb +0 -67
  156. data/app/models/alchemy/essence_picture_view.rb +0 -90
  157. data/app/models/alchemy/essence_richtext.rb +0 -44
  158. data/app/models/alchemy/essence_select.rb +0 -19
  159. data/app/models/alchemy/essence_text.rb +0 -23
  160. data/app/models/alchemy/essence_video.rb +0 -13
  161. data/app/serializers/alchemy/content_serializer.rb +0 -17
  162. data/app/serializers/alchemy/essence_boolean_serializer.rb +0 -10
  163. data/app/serializers/alchemy/essence_date_serializer.rb +0 -10
  164. data/app/serializers/alchemy/essence_file_serializer.rb +0 -13
  165. data/app/serializers/alchemy/essence_html_serializer.rb +0 -10
  166. data/app/serializers/alchemy/essence_link_serializer.rb +0 -13
  167. data/app/serializers/alchemy/essence_picture_serializer.rb +0 -28
  168. data/app/serializers/alchemy/essence_richtext_serializer.rb +0 -11
  169. data/app/serializers/alchemy/essence_select_serializer.rb +0 -10
  170. data/app/serializers/alchemy/essence_text_serializer.rb +0 -22
  171. data/app/views/alchemy/admin/contents/create.js.erb +0 -21
  172. data/app/views/alchemy/admin/essence_audios/edit.html.erb +0 -7
  173. data/app/views/alchemy/admin/essence_files/edit.html.erb +0 -21
  174. data/app/views/alchemy/admin/essence_pictures/destroy.js.erb +0 -5
  175. data/app/views/alchemy/admin/essence_pictures/edit.html.erb +0 -30
  176. data/app/views/alchemy/admin/essence_pictures/save_link.js.erb +0 -3
  177. data/app/views/alchemy/admin/essence_pictures/update.js.erb +0 -8
  178. data/app/views/alchemy/admin/essence_videos/edit.html.erb +0 -12
  179. data/app/views/alchemy/essences/_essence_audio_editor.html.erb +0 -4
  180. data/app/views/alchemy/essences/_essence_audio_view.html.erb +0 -15
  181. data/app/views/alchemy/essences/_essence_boolean_editor.html.erb +0 -11
  182. data/app/views/alchemy/essences/_essence_boolean_view.html.erb +0 -2
  183. data/app/views/alchemy/essences/_essence_date_editor.html.erb +0 -16
  184. data/app/views/alchemy/essences/_essence_date_view.html.erb +0 -10
  185. data/app/views/alchemy/essences/_essence_file_editor.html.erb +0 -54
  186. data/app/views/alchemy/essences/_essence_file_view.html.erb +0 -18
  187. data/app/views/alchemy/essences/_essence_headline_editor.html.erb +0 -36
  188. data/app/views/alchemy/essences/_essence_headline_view.html.erb +0 -10
  189. data/app/views/alchemy/essences/_essence_html_editor.html.erb +0 -10
  190. data/app/views/alchemy/essences/_essence_html_view.html.erb +0 -2
  191. data/app/views/alchemy/essences/_essence_link_editor.html.erb +0 -30
  192. data/app/views/alchemy/essences/_essence_link_view.html.erb +0 -10
  193. data/app/views/alchemy/essences/_essence_node_editor.html.erb +0 -27
  194. data/app/views/alchemy/essences/_essence_node_view.html.erb +0 -1
  195. data/app/views/alchemy/essences/_essence_page_editor.html.erb +0 -26
  196. data/app/views/alchemy/essences/_essence_page_view.html.erb +0 -5
  197. data/app/views/alchemy/essences/_essence_picture_editor.html.erb +0 -59
  198. data/app/views/alchemy/essences/_essence_picture_view.html.erb +0 -6
  199. data/app/views/alchemy/essences/_essence_richtext_editor.html.erb +0 -14
  200. data/app/views/alchemy/essences/_essence_richtext_view.html.erb +0 -4
  201. data/app/views/alchemy/essences/_essence_select_editor.html.erb +0 -28
  202. data/app/views/alchemy/essences/_essence_select_view.html.erb +0 -2
  203. data/app/views/alchemy/essences/_essence_text_editor.html.erb +0 -29
  204. data/app/views/alchemy/essences/_essence_text_view.html.erb +0 -17
  205. data/app/views/alchemy/essences/_essence_video_editor.html.erb +0 -4
  206. data/app/views/alchemy/essences/_essence_video_view.html.erb +0 -19
  207. data/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb +0 -59
  208. data/app/views/alchemy/essences/shared/_linkable_essence_tools.html.erb +0 -20
  209. data/app/views/alchemy/pages/show.rss.builder +0 -21
  210. data/db/migrate/20200226213334_alchemy_four_point_four.rb +0 -313
  211. data/db/migrate/20200423073425_create_alchemy_essence_nodes.rb +0 -11
  212. data/db/migrate/20200504210159_remove_site_id_from_nodes.rb +0 -28
  213. data/db/migrate/20200505215518_add_language_id_foreign_key_to_alchemy_pages.rb +0 -8
  214. data/db/migrate/20200511113603_add_menu_type_to_alchemy_nodes.rb +0 -27
  215. data/db/migrate/20200514091507_make_page_layoutpage_null_false.rb +0 -6
  216. data/db/migrate/20200519073500_remove_visible_from_alchemy_pages.rb +0 -24
  217. data/db/migrate/20200617110713_create_alchemy_picture_thumbs.rb +0 -22
  218. data/db/migrate/20200907111332_remove_tri_state_booleans.rb +0 -33
  219. data/db/migrate/20201207131309_create_page_versions.rb +0 -19
  220. data/db/migrate/20201207135820_add_page_version_id_to_alchemy_elements.rb +0 -76
  221. data/db/migrate/20210205143548_rename_public_on_and_public_until_on_alchemy_pages.rb +0 -10
  222. data/db/migrate/20210326105046_add_sanitized_body_to_alchemy_essence_richtexts.rb +0 -7
  223. data/db/migrate/20210406093436_add_alchemy_essence_headlines.rb +0 -12
  224. data/db/migrate/20210506135919_create_essence_audios.rb +0 -19
  225. data/db/migrate/20210506140258_create_essence_videos.rb +0 -23
  226. data/db/migrate/20210508091432_create_alchemy_ingredients.rb +0 -22
  227. data/db/migrate/20220514072456_restrict_on_delete_page_id_foreign_key_from_alchemy_nodes.rb +0 -13
  228. data/db/migrate/20220622130905_add_playsinline_to_alchemy_essence_videos.rb +0 -9
  229. data/lib/alchemy/essence.rb +0 -250
  230. data/lib/alchemy/tasks/usage.rb +0 -34
  231. data/lib/alchemy/test_support/essence_shared_examples.rb +0 -271
  232. data/lib/alchemy/test_support/factories/content_factory.rb +0 -20
  233. data/lib/alchemy/test_support/factories/essence_audio_factory.rb +0 -7
  234. data/lib/alchemy/test_support/factories/essence_file_factory.rb +0 -7
  235. data/lib/alchemy/test_support/factories/essence_page_factory.rb +0 -7
  236. data/lib/alchemy/test_support/factories/essence_picture_factory.rb +0 -11
  237. data/lib/alchemy/test_support/factories/essence_text_factory.rb +0 -7
  238. data/lib/alchemy/test_support/factories/essence_video_factory.rb +0 -7
  239. data/lib/alchemy/upgrader/five_point_zero.rb +0 -41
  240. data/lib/alchemy/upgrader/six_point_zero.rb +0 -21
  241. data/lib/alchemy/upgrader/tasks/add_page_versions.rb +0 -33
  242. data/lib/alchemy/upgrader/tasks/element_views_updater.rb +0 -34
  243. data/lib/alchemy/upgrader/tasks/harden_gutentag_migrations.rb +0 -29
  244. data/lib/alchemy/upgrader/tasks/ingredients_migrator.rb +0 -73
  245. data/lib/generators/alchemy/essence/essence_generator.rb +0 -49
  246. data/lib/generators/alchemy/essence/templates/editor.html.erb +0 -17
  247. data/lib/generators/alchemy/essence/templates/view.html.erb +0 -2
  248. data/lib/generators/alchemy/install/files/babel.config.js +0 -64
  249. data/lib/tasks/alchemy/usage.rake +0 -44
@@ -1,200 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Alchemy
4
- class Element < BaseRecord
5
- # Methods concerning contents for elements
6
- #
7
- module ElementContents
8
- # Find first content from element by given name.
9
- # @deprecated
10
- def content_by_name(name)
11
- contents_by_name(name).first
12
- end
13
-
14
- deprecate content_by_name: :ingredient_by_role, deprecator: Alchemy::Deprecation
15
-
16
- # Find first content from element by given essence type.
17
- # @deprecated
18
- def content_by_type(essence_type)
19
- contents_by_type(essence_type).first
20
- end
21
-
22
- deprecate content_by_type: :ingredient_by_type, deprecator: Alchemy::Deprecation
23
-
24
- # All contents from element by given name.
25
- # @deprecated
26
- def contents_by_name(name)
27
- contents.select { |content| content.name == name.to_s }
28
- end
29
-
30
- deprecate contents_by_name: :ingredients_by_role, deprecator: Alchemy::Deprecation
31
-
32
- alias_method :all_contents_by_name, :contents_by_name
33
-
34
- # All contents from element by given essence type.
35
- # @deprecated
36
- def contents_by_type(essence_type)
37
- contents.select do |content|
38
- content.essence_type == Content.normalize_essence_type(essence_type)
39
- end
40
- end
41
-
42
- deprecate contents_by_type: :ingredients_by_type, deprecator: Alchemy::Deprecation
43
-
44
- alias_method :all_contents_by_type, :contents_by_type
45
-
46
- # Updates all related contents by calling +update_essence+ on each of them.
47
- #
48
- # @param contents_attributes [Hash]
49
- # Hash of contents attributes.
50
- # The keys has to be the #id of the content to update.
51
- # The values a Hash of attribute names and values
52
- #
53
- # @return [Boolean]
54
- # True if +errors+ are blank or +contents_attributes+ hash is nil
55
- #
56
- # == Example
57
- #
58
- # @element.update_contents(
59
- # "1" => {ingredient: "Title"},
60
- # "2" => {link: "https://google.com"}
61
- # )
62
- #
63
- # @deprecated
64
- def update_contents(contents_attributes)
65
- return true if contents_attributes.nil?
66
-
67
- contents.each do |content|
68
- content_hash = contents_attributes[content.id.to_s] || next
69
- content.update_essence(content_hash) || errors.add(:base, :essence_validation_failed)
70
- end
71
- errors.blank?
72
- end
73
-
74
- deprecate :update_contents, deprecator: Alchemy::Deprecation
75
-
76
- # Copy current content's contents to given target element
77
- # @deprecated
78
- def copy_contents_to(element)
79
- contents.map do |content|
80
- Content.copy(content, element_id: element.id)
81
- end
82
- end
83
-
84
- deprecate :copy_contents_to, deprecator: Alchemy::Deprecation
85
-
86
- # Returns the content that is marked as rss title.
87
- #
88
- # Mark a content as rss title in your +elements.yml+ file:
89
- #
90
- # - name: news
91
- # contents:
92
- # - name: headline
93
- # type: EssenceText
94
- # rss_title: true
95
- #
96
- # @deprecated
97
- def content_for_rss_title
98
- content_for_rss_meta("title")
99
- end
100
-
101
- deprecate :content_for_rss_title, deprecator: Alchemy::Deprecation
102
-
103
- # Returns the content that is marked as rss description.
104
- #
105
- # Mark a content as rss description in your +elements.yml+ file:
106
- #
107
- # - name: news
108
- # contents:
109
- # - name: body
110
- # type: EssenceRichtext
111
- # rss_description: true
112
- #
113
- # @deprecated
114
- def content_for_rss_description
115
- content_for_rss_meta("description")
116
- end
117
-
118
- deprecate :content_for_rss_description, deprecator: Alchemy::Deprecation
119
-
120
- # Returns the array with the hashes for all element contents in the elements.yml file
121
- # @deprecated
122
- def content_definitions
123
- return nil if definition.blank?
124
-
125
- definition["contents"]
126
- end
127
-
128
- deprecate content_definitions: :ingredient_definitions, deprecator: Alchemy::Deprecation
129
-
130
- # Returns the definition for given content_name
131
- # @deprecated
132
- def content_definition_for(content_name)
133
- if content_definitions.blank?
134
- log_warning "Element #{name} is missing the content definition for #{content_name}"
135
- nil
136
- else
137
- content_definitions.detect { |d| d["name"] == content_name.to_s }
138
- end
139
- end
140
-
141
- deprecate content_definition_for: :ingredient_definition_for, deprecator: Alchemy::Deprecation
142
-
143
- # Returns an array of all EssenceRichtext contents ids from elements
144
- #
145
- # This is used to re-initialize the TinyMCE editor in the element editor.
146
- #
147
- # @deprecated
148
- def richtext_contents_ids
149
- # This is not very efficient SQL wise I know, but we need to iterate
150
- # recursivly through all descendent elements and I don't know how to do this
151
- # in pure SQL. Anyone with a better idea is welcome to submit a patch.
152
- ids = contents.select(&:has_tinymce?).collect(&:id)
153
- expanded_nested_elements = nested_elements.expanded
154
- if expanded_nested_elements.present?
155
- ids += expanded_nested_elements.collect(&:richtext_contents_ids)
156
- end
157
- ids.flatten
158
- end
159
-
160
- deprecate richtext_contents_ids: :richtext_ingredients_ids, deprecator: Alchemy::Deprecation
161
-
162
- # True, if any of the element's contents has essence validations defined.
163
- # @deprecated
164
- def has_validations?
165
- !contents.detect(&:has_validations?).blank?
166
- end
167
-
168
- deprecate :has_validations?, deprecator: Alchemy::Deprecation
169
-
170
- # All element contents where the essence validation has failed.
171
- # @deprecated
172
- def contents_with_errors
173
- contents.select(&:essence_validation_failed?)
174
- end
175
-
176
- deprecate contents_with_errors: :ingredients_with_errors, deprecator: Alchemy::Deprecation
177
-
178
- private
179
-
180
- def content_for_rss_meta(type)
181
- definition = content_definitions.detect { |c| c["rss_#{type}"] }
182
- return if definition.blank?
183
-
184
- contents.detect { |content| content.name == definition["name"] }
185
- end
186
-
187
- # creates the contents for this element as described in the elements.yml
188
- #
189
- # If ingredients are defined as well no contents get created,
190
- # ingredients get created instead.
191
- def create_contents
192
- return if definition.fetch(:ingredients, []).any?
193
-
194
- definition.fetch("contents", []).each do |attributes|
195
- Content.create(attributes.merge(element: self))
196
- end
197
- end
198
- end
199
- end
200
- end
@@ -1,133 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Alchemy
4
- class Element < BaseRecord
5
- module ElementEssences
6
- # Returns the contents essence value (aka. ingredient) for passed content name.
7
- def ingredient(name)
8
- ing = ingredient_by_role(name)
9
- if ing
10
- Alchemy::Deprecation.warn(<<~WARN)
11
- Using `element.ingredient` to get the value of an ingredient is deprecated and will change in Alchemy 6.1
12
- If you want to read the value of an elements ingredient please use `element.value_for(:ingredient_role)` instead.
13
- The next version of Alchemy will return a `Alchemy::Ingredient` record instead.
14
- WARN
15
- ing.value
16
- else
17
- content = content_by_name(name)
18
- return nil if content.blank?
19
-
20
- content.ingredient
21
- end
22
- end
23
-
24
- # True if the element has a content for given name,
25
- # that has an essence value (aka. ingredient) that is not blank.
26
- # @deprecated
27
- def has_ingredient?(name)
28
- ingredient(name).present?
29
- end
30
-
31
- deprecate has_ingredient?: :has_value_for?, deprecator: Alchemy::Deprecation
32
-
33
- # Returns all essence errors in the format of:
34
- #
35
- # {
36
- # content.name => [
37
- # error_message_for_validation_1,
38
- # error_message_for_validation_2
39
- # ]
40
- # }
41
- #
42
- # Get translated error messages with +Element#essence_error_messages+
43
- #
44
- # @deprecated
45
- def essence_errors
46
- essence_errors = {}
47
- contents.each do |content|
48
- if content.essence_validation_failed?
49
- essence_errors[content.name] = content.essence.validation_errors
50
- end
51
- end
52
- essence_errors
53
- end
54
-
55
- deprecate :essence_errors, deprecator: Alchemy::Deprecation
56
-
57
- # Essence validation errors
58
- #
59
- # == Error messages are translated via I18n
60
- #
61
- # Inside your translation file add translations like:
62
- #
63
- # alchemy:
64
- # content_validations:
65
- # name_of_the_element:
66
- # name_of_the_content:
67
- # validation_error_type: Error Message
68
- #
69
- # NOTE: +validation_error_type+ has to be one of:
70
- #
71
- # * blank
72
- # * taken
73
- # * invalid
74
- #
75
- # === Example:
76
- #
77
- # de:
78
- # alchemy:
79
- # content_validations:
80
- # contactform:
81
- # email:
82
- # invalid: 'Die Email hat nicht das richtige Format'
83
- #
84
- #
85
- # == Error message translation fallbacks
86
- #
87
- # In order to not translate every single content for every element
88
- # you can provide default error messages per content name:
89
- #
90
- # === Example
91
- #
92
- # en:
93
- # alchemy:
94
- # content_validations:
95
- # fields:
96
- # email:
97
- # invalid: E-Mail has wrong format
98
- # blank: E-Mail can't be blank
99
- #
100
- # And even further you can provide general field agnostic error messages:
101
- #
102
- # === Example
103
- #
104
- # en:
105
- # alchemy:
106
- # content_validations:
107
- # errors:
108
- # invalid: %{field} has wrong format
109
- # blank: %{field} can't be blank
110
- #
111
- # @deprecated
112
- def essence_error_messages
113
- messages = []
114
- essence_errors.each do |content_name, errors|
115
- errors.each do |error|
116
- messages << Alchemy.t(
117
- "#{name}.#{content_name}.#{error}",
118
- scope: "content_validations",
119
- default: [
120
- "fields.#{content_name}.#{error}".to_sym,
121
- "errors.#{error}".to_sym,
122
- ],
123
- field: Content.translated_label_for(content_name, name),
124
- )
125
- end
126
- end
127
- messages
128
- end
129
-
130
- deprecate essence_error_messages: :ingredient_error_messages, deprecator: Alchemy::Deprecation
131
- end
132
- end
133
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Alchemy
4
- # @deprecated
5
- class EssenceAudio < ActiveRecord::Base
6
- acts_as_essence(
7
- ingredient_column: :attachment,
8
- preview_text_method: :name,
9
- )
10
-
11
- belongs_to :attachment, optional: true
12
- end
13
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # == Schema Information
4
- #
5
- # Table name: alchemy_essence_booleans
6
- #
7
- # id :integer not null, primary key
8
- # value :boolean
9
- # created_at :datetime not null
10
- # updated_at :datetime not null
11
- #
12
-
13
- # Stores boolean values.
14
- # Provides a checkbox in the editor views.
15
- module Alchemy
16
- # @deprecated
17
- class EssenceBoolean < BaseRecord
18
- acts_as_essence ingredient_column: "value"
19
- end
20
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # == Schema Information
4
- #
5
- # Table name: alchemy_essence_dates
6
- #
7
- # id :integer not null, primary key
8
- # date :datetime
9
- # created_at :datetime not null
10
- # updated_at :datetime not null
11
- #
12
-
13
- module Alchemy
14
- # @deprecated
15
- class EssenceDate < BaseRecord
16
- acts_as_essence ingredient_column: "date"
17
-
18
- # Returns self.date for the Element#preview_text method.
19
- def preview_text(_maxlength = nil)
20
- return "" if date.blank?
21
-
22
- ::I18n.l(date, format: :'alchemy.essence_date')
23
- end
24
- end
25
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # == Schema Information
4
- #
5
- # Table name: alchemy_essence_files
6
- #
7
- # id :integer not null, primary key
8
- # attachment_id :integer
9
- # title :string
10
- # css_class :string
11
- # created_at :datetime not null
12
- # updated_at :datetime not null
13
- # link_text :string
14
- #
15
-
16
- module Alchemy
17
- # @deprecated
18
- class EssenceFile < BaseRecord
19
- belongs_to :attachment, optional: true
20
- acts_as_essence ingredient_column: "attachment"
21
-
22
- def attachment_url
23
- return if attachment.nil?
24
-
25
- routes.download_attachment_path(
26
- id: attachment.id,
27
- name: attachment.slug,
28
- format: attachment.suffix,
29
- )
30
- end
31
-
32
- def preview_text(max = 30)
33
- return "" if attachment.blank?
34
-
35
- attachment.name.to_s[0..max - 1]
36
- end
37
-
38
- # Returns a serialized ingredient value for json api
39
- def serialized_ingredient
40
- attachment_url
41
- end
42
-
43
- private
44
-
45
- def routes
46
- @routes ||= Engine.routes.url_helpers
47
- end
48
- end
49
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Alchemy
4
- # @deprecated
5
- class EssenceHeadline < BaseRecord
6
- acts_as_essence
7
-
8
- after_initialize :set_level_and_size
9
-
10
- def preview_text(maxlength = 30)
11
- "H#{level}: #{body}"[0..maxlength - 1]
12
- end
13
-
14
- def level_options
15
- levels.map { |level| ["H#{level}", level] }
16
- end
17
-
18
- def size_options
19
- sizes.map { |size| ["H#{size}", size] }
20
- end
21
-
22
- private
23
-
24
- def content_settings
25
- content&.settings || {}
26
- end
27
-
28
- def levels
29
- content_settings.fetch(:levels, (1..6))
30
- end
31
-
32
- def sizes
33
- content_settings.fetch(:sizes, [])
34
- end
35
-
36
- def set_level_and_size
37
- self.level ||= levels.first
38
- self.size ||= sizes.first
39
- end
40
- end
41
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # == Schema Information
4
- #
5
- # Table name: alchemy_essence_htmls
6
- #
7
- # id :integer not null, primary key
8
- # source :text
9
- # created_at :datetime not null
10
- # updated_at :datetime not null
11
- #
12
-
13
- module Alchemy
14
- # @deprecated
15
- class EssenceHtml < BaseRecord
16
- acts_as_essence ingredient_column: "source"
17
-
18
- # Returns the first x (default = 30) (HTML escaped) characters from self.source for the Element#preview_text method.
19
- def preview_text(maxlength = 30)
20
- ::CGI.escapeHTML(source.to_s)[0..maxlength]
21
- end
22
- end
23
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # == Schema Information
4
- #
5
- # Table name: alchemy_essence_links
6
- #
7
- # id :integer not null, primary key
8
- # link :string
9
- # link_title :string
10
- # link_target :string
11
- # link_class_name :string
12
- # created_at :datetime not null
13
- # updated_at :datetime not null
14
- #
15
-
16
- module Alchemy
17
- # @deprecated
18
- class EssenceLink < BaseRecord
19
- acts_as_essence ingredient_column: "link"
20
- end
21
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Alchemy
4
- # @deprecated
5
- class EssenceNode < BaseRecord
6
- acts_as_essence(
7
- ingredient_column: :node,
8
- preview_text_column: :node_name,
9
- belongs_to: {
10
- class_name: "Alchemy::Node",
11
- foreign_key: :node_id,
12
- inverse_of: :essence_nodes,
13
- optional: true,
14
- },
15
- )
16
-
17
- delegate :name, to: :node, prefix: true, allow_nil: true
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Alchemy
4
- # @deprecated
5
- class EssencePage < BaseRecord
6
- acts_as_essence(
7
- ingredient_column: :page,
8
- preview_text_method: :name,
9
- belongs_to: {
10
- class_name: "Alchemy::Page",
11
- foreign_key: :page_id,
12
- inverse_of: :essence_pages,
13
- optional: true,
14
- },
15
- )
16
- end
17
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # == Schema Information
4
- #
5
- # Table name: alchemy_essence_pictures
6
- #
7
- # id :integer not null, primary key
8
- # picture_id :integer
9
- # caption :string
10
- # title :string
11
- # alt_tag :string
12
- # link :string
13
- # link_class_name :string
14
- # link_title :string
15
- # css_class :string
16
- # link_target :string
17
- # created_at :datetime not null
18
- # updated_at :datetime not null
19
- # crop_from :string
20
- # crop_size :string
21
- # render_size :string
22
- #
23
-
24
- module Alchemy
25
- # @deprecated
26
- class EssencePicture < BaseRecord
27
- include Alchemy::PictureThumbnails
28
-
29
- acts_as_essence ingredient_column: :picture, belongs_to: {
30
- class_name: "Alchemy::Picture",
31
- foreign_key: :picture_id,
32
- inverse_of: :essence_pictures,
33
- optional: true,
34
- }
35
-
36
- delegate :settings, to: :content
37
-
38
- before_save :replace_newlines
39
-
40
- # The name of the picture used as preview text in element editor views.
41
- #
42
- # @param max [Integer]
43
- # The maximum length of the text returned.
44
- #
45
- # @return [String]
46
- def preview_text(max = 30)
47
- return "" if picture.nil?
48
-
49
- picture.name.to_s[0..max - 1]
50
- end
51
-
52
- # Returns a serialized ingredient value for json api
53
- #
54
- # @return [String]
55
- def serialized_ingredient
56
- picture_url(content.settings)
57
- end
58
-
59
- private
60
-
61
- def replace_newlines
62
- return nil if caption.nil?
63
-
64
- caption.gsub!(/(\r\n|\r|\n)/, "<br/>")
65
- end
66
- end
67
- end