alchemy_cms 4.6.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (386) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +33 -1
  3. data/.github/workflows/stale.yml +1 -1
  4. data/.gitignore +20 -2
  5. data/.hound.yml +2 -1
  6. data/.prettierrc +6 -0
  7. data/.rubocop.yml +30 -9
  8. data/CHANGELOG.md +102 -1
  9. data/Gemfile +24 -22
  10. data/README.md +32 -20
  11. data/Rakefile +11 -8
  12. data/alchemy_cms.gemspec +6 -5
  13. data/app/assets/javascripts/alchemy/admin.js +1 -5
  14. data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +2 -1
  15. data/app/assets/javascripts/alchemy/alchemy.element_editors.js.coffee +0 -2
  16. data/app/assets/javascripts/alchemy/alchemy.page_sorter.js +17 -17
  17. data/app/assets/javascripts/alchemy/node_select.js +39 -0
  18. data/app/assets/javascripts/alchemy/templates/index.js +1 -0
  19. data/app/assets/javascripts/alchemy/templates/node.hbs +16 -0
  20. data/app/assets/stylesheets/alchemy/admin.scss +3 -2
  21. data/app/assets/stylesheets/alchemy/base.scss +0 -1
  22. data/app/assets/stylesheets/alchemy/elements.scss +1 -1
  23. data/app/assets/stylesheets/alchemy/forms.scss +5 -0
  24. data/app/assets/stylesheets/alchemy/navigation.scss +1 -0
  25. data/app/assets/stylesheets/alchemy/node-select.scss +43 -0
  26. data/app/assets/stylesheets/alchemy/nodes.scss +1 -1
  27. data/app/assets/stylesheets/alchemy/sitemap.scss +5 -1
  28. data/app/assets/stylesheets/alchemy/tables.scss +1 -24
  29. data/app/assets/stylesheets/alchemy/tags.scss +2 -2
  30. data/app/controllers/alchemy/admin/attachments_controller.rb +8 -7
  31. data/app/controllers/alchemy/admin/base_controller.rb +13 -33
  32. data/app/controllers/alchemy/admin/clipboard_controller.rb +5 -4
  33. data/app/controllers/alchemy/admin/contents_controller.rb +1 -2
  34. data/app/controllers/alchemy/admin/dashboard_controller.rb +10 -9
  35. data/app/controllers/alchemy/admin/elements_controller.rb +20 -20
  36. data/app/controllers/alchemy/admin/essence_pictures_controller.rb +12 -14
  37. data/app/controllers/alchemy/admin/languages_controller.rb +35 -2
  38. data/app/controllers/alchemy/admin/layoutpages_controller.rb +5 -2
  39. data/app/controllers/alchemy/admin/nodes_controller.rb +5 -4
  40. data/app/controllers/alchemy/admin/pages_controller.rb +51 -63
  41. data/app/controllers/alchemy/admin/pictures_controller.rb +16 -16
  42. data/app/controllers/alchemy/admin/resources_controller.rb +21 -13
  43. data/app/controllers/alchemy/admin/sites_controller.rb +18 -0
  44. data/app/controllers/alchemy/admin/styleguide_controller.rb +1 -0
  45. data/app/controllers/alchemy/admin/tags_controller.rb +5 -3
  46. data/app/controllers/alchemy/admin/trash_controller.rb +6 -6
  47. data/app/controllers/alchemy/api/base_controller.rb +2 -2
  48. data/app/controllers/alchemy/api/contents_controller.rb +4 -4
  49. data/app/controllers/alchemy/api/elements_controller.rb +8 -8
  50. data/app/controllers/alchemy/api/nodes_controller.rb +37 -1
  51. data/app/controllers/alchemy/api/pages_controller.rb +14 -23
  52. data/app/controllers/alchemy/attachments_controller.rb +5 -5
  53. data/app/controllers/alchemy/base_controller.rb +10 -9
  54. data/app/controllers/alchemy/messages_controller.rb +16 -23
  55. data/app/controllers/alchemy/pages_controller.rb +13 -11
  56. data/app/controllers/concerns/alchemy/admin/archive_overlay.rb +3 -2
  57. data/app/controllers/concerns/alchemy/admin/current_language.rb +23 -0
  58. data/app/controllers/concerns/alchemy/admin/uploader_responses.rb +5 -5
  59. data/app/controllers/concerns/alchemy/legacy_page_redirects.rb +4 -4
  60. data/app/controllers/concerns/alchemy/page_redirects.rb +2 -9
  61. data/app/controllers/concerns/alchemy/site_redirects.rb +2 -2
  62. data/app/decorators/alchemy/element_editor.rb +39 -0
  63. data/app/helpers/alchemy/admin/attachments_helper.rb +6 -6
  64. data/app/helpers/alchemy/admin/base_helper.rb +38 -35
  65. data/app/helpers/alchemy/admin/contents_helper.rb +3 -3
  66. data/app/helpers/alchemy/admin/elements_helper.rb +3 -88
  67. data/app/helpers/alchemy/admin/essences_helper.rb +8 -117
  68. data/app/helpers/alchemy/admin/form_helper.rb +1 -1
  69. data/app/helpers/alchemy/admin/navigation_helper.rb +24 -23
  70. data/app/helpers/alchemy/admin/pages_helper.rb +4 -4
  71. data/app/helpers/alchemy/admin/pictures_helper.rb +4 -6
  72. data/app/helpers/alchemy/admin/tags_helper.rb +8 -7
  73. data/app/helpers/alchemy/base_helper.rb +13 -8
  74. data/app/helpers/alchemy/elements_block_helper.rb +2 -31
  75. data/app/helpers/alchemy/elements_helper.rb +12 -58
  76. data/app/helpers/alchemy/pages_helper.rb +24 -174
  77. data/app/helpers/alchemy/url_helper.rb +4 -3
  78. data/app/mailers/alchemy/base_mailer.rb +1 -1
  79. data/app/mailers/alchemy/messages_mailer.rb +1 -1
  80. data/app/models/alchemy/attachment.rb +24 -19
  81. data/app/models/alchemy/base_record.rb +2 -5
  82. data/app/models/alchemy/content.rb +33 -38
  83. data/app/models/alchemy/content/factory.rb +24 -31
  84. data/app/models/alchemy/element.rb +45 -53
  85. data/app/models/alchemy/element/definitions.rb +4 -4
  86. data/app/models/alchemy/element/element_contents.rb +9 -6
  87. data/app/models/alchemy/element/element_essences.rb +4 -3
  88. data/app/models/alchemy/element/presenters.rb +3 -2
  89. data/app/models/alchemy/element_to_page.rb +1 -1
  90. data/app/models/alchemy/essence_boolean.rb +1 -3
  91. data/app/models/alchemy/essence_date.rb +2 -3
  92. data/app/models/alchemy/essence_file.rb +5 -5
  93. data/app/models/alchemy/essence_html.rb +1 -3
  94. data/app/models/alchemy/essence_link.rb +1 -3
  95. data/app/models/alchemy/essence_node.rb +18 -0
  96. data/app/models/alchemy/essence_page.rb +3 -16
  97. data/app/models/alchemy/essence_picture.rb +18 -17
  98. data/app/models/alchemy/essence_picture_view.rb +7 -6
  99. data/app/models/alchemy/essence_richtext.rb +1 -3
  100. data/app/models/alchemy/essence_select.rb +1 -3
  101. data/app/models/alchemy/essence_text.rb +0 -2
  102. data/app/models/alchemy/folded_page.rb +1 -0
  103. data/app/models/alchemy/language.rb +21 -35
  104. data/app/models/alchemy/language/code.rb +4 -4
  105. data/app/models/alchemy/legacy_page_url.rb +1 -1
  106. data/app/models/alchemy/message.rb +3 -3
  107. data/app/models/alchemy/node.rb +27 -4
  108. data/app/models/alchemy/page.rb +46 -127
  109. data/app/models/alchemy/page/fixed_attributes.rb +3 -2
  110. data/app/models/alchemy/page/page_elements.rb +35 -44
  111. data/app/models/alchemy/page/page_naming.rb +20 -70
  112. data/app/models/alchemy/page/page_natures.rb +7 -34
  113. data/app/models/alchemy/page/page_scopes.rb +23 -29
  114. data/app/models/alchemy/page/url_path.rb +0 -2
  115. data/app/models/alchemy/picture.rb +40 -30
  116. data/app/models/alchemy/picture/preprocessor.rb +26 -0
  117. data/app/models/alchemy/picture/transformations.rb +9 -7
  118. data/app/models/alchemy/picture/url.rb +9 -7
  119. data/app/models/alchemy/site.rb +6 -36
  120. data/app/models/alchemy/site/layout.rb +2 -2
  121. data/app/models/concerns/alchemy/touch_elements.rb +24 -0
  122. data/app/serializers/alchemy/content_serializer.rb +0 -3
  123. data/app/serializers/alchemy/essence_boolean_serializer.rb +3 -3
  124. data/app/serializers/alchemy/essence_date_serializer.rb +3 -3
  125. data/app/serializers/alchemy/essence_file_serializer.rb +4 -2
  126. data/app/serializers/alchemy/essence_html_serializer.rb +3 -3
  127. data/app/serializers/alchemy/essence_link_serializer.rb +3 -3
  128. data/app/serializers/alchemy/essence_picture_serializer.rb +5 -4
  129. data/app/serializers/alchemy/essence_richtext_serializer.rb +3 -3
  130. data/app/serializers/alchemy/essence_select_serializer.rb +3 -3
  131. data/app/serializers/alchemy/essence_text_serializer.rb +5 -4
  132. data/app/serializers/alchemy/node_serializer.rb +2 -0
  133. data/app/serializers/alchemy/page_tree_serializer.rb +9 -13
  134. data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +1 -2
  135. data/app/views/alchemy/admin/attachments/_file_to_assign.html.erb +1 -2
  136. data/app/views/alchemy/admin/attachments/_files_list.html.erb +4 -4
  137. data/app/views/alchemy/admin/contents/create.js.erb +1 -3
  138. data/app/views/alchemy/admin/elements/_element.html.erb +9 -18
  139. data/app/views/alchemy/admin/elements/create.js.erb +1 -1
  140. data/app/views/alchemy/admin/elements/fold.js.erb +1 -1
  141. data/app/views/alchemy/admin/elements/index.html.erb +3 -3
  142. data/app/views/alchemy/admin/essence_files/assign.js.erb +1 -6
  143. data/app/views/alchemy/admin/essence_files/edit.html.erb +1 -1
  144. data/app/views/alchemy/admin/essence_pictures/assign.js.erb +1 -7
  145. data/app/views/alchemy/admin/essence_pictures/crop.html.erb +1 -1
  146. data/app/views/alchemy/admin/essence_pictures/edit.html.erb +7 -7
  147. data/app/views/alchemy/admin/essence_pictures/update.js.erb +1 -1
  148. data/app/views/alchemy/admin/languages/_form.html.erb +5 -5
  149. data/app/views/alchemy/admin/languages/_table.html.erb +3 -3
  150. data/app/views/alchemy/admin/languages/edit.html.erb +1 -0
  151. data/app/views/alchemy/admin/languages/index.html.erb +23 -4
  152. data/app/views/alchemy/admin/languages/new.html.erb +1 -0
  153. data/app/views/alchemy/admin/layoutpages/index.html.erb +3 -3
  154. data/app/views/alchemy/admin/nodes/_form.html.erb +18 -15
  155. data/app/views/alchemy/admin/nodes/_node.html.erb +1 -5
  156. data/app/views/alchemy/admin/nodes/index.html.erb +3 -4
  157. data/app/views/alchemy/admin/pages/_create_language_form.html.erb +0 -8
  158. data/app/views/alchemy/admin/pages/_form.html.erb +0 -1
  159. data/app/views/alchemy/admin/pages/_new_page_form.html.erb +1 -0
  160. data/app/views/alchemy/admin/pages/_page.html.erb +11 -19
  161. data/app/views/alchemy/admin/pages/_page_infos.html.erb +0 -4
  162. data/app/views/alchemy/admin/pages/edit.html.erb +1 -1
  163. data/app/views/alchemy/admin/pages/info.html.erb +0 -9
  164. data/app/views/alchemy/admin/pages/unlock.js.erb +13 -6
  165. data/app/views/alchemy/admin/partials/_remote_search_form.html.erb +0 -2
  166. data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +1 -5
  167. data/app/views/alchemy/admin/pictures/_overlay_picture_list.html.erb +1 -1
  168. data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +1 -2
  169. data/app/views/alchemy/admin/pictures/index.html.erb +18 -3
  170. data/app/views/alchemy/admin/pictures/show.html.erb +1 -1
  171. data/app/views/alchemy/admin/resources/_resource.html.erb +1 -1
  172. data/app/views/alchemy/admin/resources/_table.html.erb +2 -2
  173. data/app/views/alchemy/admin/resources/index.html.erb +21 -22
  174. data/app/views/alchemy/admin/sites/_form.html.erb +8 -0
  175. data/app/views/alchemy/admin/sites/edit.html.erb +1 -0
  176. data/app/views/alchemy/admin/sites/index.html.erb +21 -9
  177. data/app/views/alchemy/admin/sites/new.html.erb +1 -0
  178. data/app/views/alchemy/admin/tags/index.html.erb +2 -2
  179. data/app/views/alchemy/essences/_essence_boolean_editor.html.erb +10 -12
  180. data/app/views/alchemy/essences/_essence_date_editor.html.erb +11 -8
  181. data/app/views/alchemy/essences/_essence_file_editor.html.erb +16 -17
  182. data/app/views/alchemy/essences/_essence_file_view.html.erb +1 -1
  183. data/app/views/alchemy/essences/_essence_html_editor.html.erb +8 -5
  184. data/app/views/alchemy/essences/_essence_link_editor.html.erb +18 -15
  185. data/app/views/alchemy/essences/_essence_node_editor.html.erb +27 -0
  186. data/app/views/alchemy/essences/_essence_node_view.html.erb +1 -0
  187. data/app/views/alchemy/essences/_essence_page_editor.html.erb +14 -11
  188. data/app/views/alchemy/essences/_essence_picture_editor.html.erb +22 -20
  189. data/app/views/alchemy/essences/_essence_richtext_editor.html.erb +10 -7
  190. data/app/views/alchemy/essences/_essence_select_editor.html.erb +12 -16
  191. data/app/views/alchemy/essences/_essence_text_editor.html.erb +18 -17
  192. data/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb +6 -11
  193. data/app/views/alchemy/pages/show.rss.builder +3 -2
  194. data/app/views/layouts/alchemy/admin.html.erb +1 -0
  195. data/babel.config.js +12 -0
  196. data/bin/rails +5 -4
  197. data/config/alchemy/config.yml +23 -16
  198. data/config/brakeman.ignore +1 -1
  199. data/config/initializers/assets.rb +2 -1
  200. data/config/initializers/dragonfly.rb +2 -1
  201. data/config/initializers/mime_types.rb +1 -0
  202. data/config/initializers/mini_profiler.rb +3 -2
  203. data/config/initializers/simple_form.rb +6 -6
  204. data/config/locales/alchemy.en.yml +23 -8
  205. data/config/routes.rb +25 -24
  206. data/config/spring.rb +3 -2
  207. data/db/migrate/20200226213334_alchemy_four_point_four.rb +313 -0
  208. data/db/migrate/20200423073425_create_alchemy_essence_nodes.rb +11 -0
  209. data/db/migrate/20200504210159_remove_site_id_from_nodes.rb +28 -0
  210. data/db/migrate/20200505215518_add_language_id_foreign_key_to_alchemy_pages.rb +8 -0
  211. data/db/migrate/20200511113603_add_menu_type_to_alchemy_nodes.rb +27 -0
  212. data/db/migrate/20200514091507_make_page_layoutpage_null_false.rb +6 -0
  213. data/db/migrate/20200519073500_remove_visible_from_alchemy_pages.rb +24 -0
  214. data/lib/alchemy/admin/locale.rb +3 -1
  215. data/lib/alchemy/admin/preview_url.rb +85 -0
  216. data/lib/alchemy/auth_accessors.rb +8 -7
  217. data/lib/alchemy/cache_digests/template_tracker.rb +5 -4
  218. data/lib/alchemy/config.rb +3 -5
  219. data/lib/alchemy/configuration_methods.rb +3 -1
  220. data/lib/alchemy/controller_actions.rb +6 -5
  221. data/lib/alchemy/deprecation.rb +2 -1
  222. data/lib/alchemy/elements_finder.rb +5 -5
  223. data/lib/alchemy/engine.rb +23 -8
  224. data/lib/alchemy/errors.rb +0 -7
  225. data/lib/alchemy/essence.rb +17 -16
  226. data/lib/alchemy/filetypes.rb +5 -5
  227. data/lib/alchemy/forms/builder.rb +4 -4
  228. data/lib/alchemy/hints.rb +1 -1
  229. data/lib/alchemy/i18n.rb +2 -1
  230. data/lib/alchemy/install/tasks.rb +41 -0
  231. data/lib/alchemy/modules.rb +12 -12
  232. data/lib/alchemy/name_conversions.rb +5 -5
  233. data/lib/alchemy/on_page_layout/callbacks_runner.rb +1 -0
  234. data/lib/alchemy/page_layout.rb +15 -12
  235. data/lib/alchemy/paths.rb +1 -1
  236. data/lib/alchemy/permissions.rb +7 -6
  237. data/lib/alchemy/resource.rb +25 -15
  238. data/lib/alchemy/resources_helper.rb +12 -18
  239. data/lib/alchemy/routing_constraints.rb +1 -1
  240. data/lib/alchemy/seeder.rb +42 -14
  241. data/lib/alchemy/shell.rb +13 -10
  242. data/lib/alchemy/taggable.rb +1 -0
  243. data/lib/alchemy/tasks/tidy.rb +4 -3
  244. data/lib/alchemy/test_support/config_stubbing.rb +1 -0
  245. data/lib/alchemy/test_support/essence_shared_examples.rb +72 -72
  246. data/lib/alchemy/test_support/factories.rb +1 -1
  247. data/lib/alchemy/test_support/factories/attachment_factory.rb +5 -5
  248. data/lib/alchemy/test_support/factories/content_factory.rb +6 -6
  249. data/lib/alchemy/test_support/factories/dummy_user_factory.rb +7 -7
  250. data/lib/alchemy/test_support/factories/element_factory.rb +9 -9
  251. data/lib/alchemy/test_support/factories/essence_file_factory.rb +3 -3
  252. data/lib/alchemy/test_support/factories/essence_page_factory.rb +3 -3
  253. data/lib/alchemy/test_support/factories/essence_picture_factory.rb +4 -4
  254. data/lib/alchemy/test_support/factories/essence_text_factory.rb +3 -3
  255. data/lib/alchemy/test_support/factories/language_factory.rb +21 -14
  256. data/lib/alchemy/test_support/factories/node_factory.rb +8 -8
  257. data/lib/alchemy/test_support/factories/page_factory.rb +15 -27
  258. data/lib/alchemy/test_support/factories/picture_factory.rb +5 -5
  259. data/lib/alchemy/test_support/factories/site_factory.rb +7 -6
  260. data/lib/alchemy/test_support/integration_helpers.rb +1 -0
  261. data/lib/alchemy/test_support/shared_contexts.rb +5 -4
  262. data/lib/alchemy/test_support/shared_uploader_examples.rb +4 -3
  263. data/lib/alchemy/tinymce.rb +15 -13
  264. data/lib/alchemy/upgrader.rb +8 -7
  265. data/lib/alchemy/upgrader/five_point_zero.rb +41 -0
  266. data/lib/alchemy/upgrader/tasks/element_views_updater.rb +4 -4
  267. data/lib/alchemy/upgrader/tasks/harden_gutentag_migrations.rb +29 -0
  268. data/lib/alchemy/version.rb +1 -1
  269. data/lib/alchemy_cms.rb +52 -50
  270. data/lib/{rails/generators → generators}/alchemy/base.rb +5 -4
  271. data/lib/{rails/generators → generators}/alchemy/elements/elements_generator.rb +13 -9
  272. data/lib/{rails/generators → generators}/alchemy/elements/templates/view.html.erb +0 -0
  273. data/lib/{rails/generators → generators}/alchemy/elements/templates/view.html.haml +0 -0
  274. data/lib/{rails/generators → generators}/alchemy/elements/templates/view.html.slim +0 -0
  275. data/lib/{rails/generators → generators}/alchemy/essence/essence_generator.rb +15 -13
  276. data/lib/generators/alchemy/essence/templates/editor.html.erb +17 -0
  277. data/lib/{rails/generators → generators}/alchemy/essence/templates/view.html.erb +0 -0
  278. data/lib/{rails/generators → generators}/alchemy/install/files/_article.html.erb +0 -0
  279. data/lib/{rails/generators → generators}/alchemy/install/files/_standard.html.erb +0 -0
  280. data/lib/{rails/generators → generators}/alchemy/install/files/alchemy.en.yml +0 -0
  281. data/lib/generators/alchemy/install/files/alchemy_admin.js +1 -0
  282. data/lib/{rails/generators → generators}/alchemy/install/files/all.css +0 -0
  283. data/lib/{rails/generators → generators}/alchemy/install/files/all.js +0 -0
  284. data/lib/{rails/generators → generators}/alchemy/install/files/application.html.erb +0 -0
  285. data/lib/{rails/generators → generators}/alchemy/install/files/article.scss +0 -0
  286. data/lib/generators/alchemy/install/install_generator.rb +169 -0
  287. data/lib/{rails/generators → generators}/alchemy/install/templates/dragonfly.rb.tt +0 -0
  288. data/lib/{rails/generators → generators}/alchemy/install/templates/elements.yml.tt +0 -0
  289. data/lib/{rails/generators → generators}/alchemy/install/templates/menus.yml.tt +0 -0
  290. data/lib/{rails/generators → generators}/alchemy/install/templates/page_layouts.yml.tt +0 -0
  291. data/lib/{rails/generators → generators}/alchemy/menus/menus_generator.rb +2 -2
  292. data/lib/{rails/generators → generators}/alchemy/menus/templates/node.html.erb +1 -4
  293. data/lib/{rails/generators → generators}/alchemy/menus/templates/node.html.haml +1 -4
  294. data/lib/{rails/generators → generators}/alchemy/menus/templates/node.html.slim +1 -4
  295. data/lib/{rails/generators → generators}/alchemy/menus/templates/wrapper.html.erb +1 -1
  296. data/lib/{rails/generators → generators}/alchemy/menus/templates/wrapper.html.haml +1 -1
  297. data/lib/{rails/generators → generators}/alchemy/menus/templates/wrapper.html.slim +1 -1
  298. data/lib/{rails/generators → generators}/alchemy/module/module_generator.rb +3 -2
  299. data/lib/{rails/generators → generators}/alchemy/module/templates/ability.rb.tt +0 -0
  300. data/lib/{rails/generators → generators}/alchemy/module/templates/controller.rb.tt +0 -0
  301. data/lib/{rails/generators → generators}/alchemy/module/templates/module_config.rb.tt +0 -0
  302. data/lib/{rails/generators → generators}/alchemy/page_layouts/page_layouts_generator.rb +5 -4
  303. data/lib/{rails/generators → generators}/alchemy/page_layouts/templates/layout.html.erb +0 -0
  304. data/lib/{rails/generators → generators}/alchemy/page_layouts/templates/layout.html.haml +0 -0
  305. data/lib/{rails/generators → generators}/alchemy/page_layouts/templates/layout.html.slim +0 -0
  306. data/lib/{rails/generators → generators}/alchemy/site_layouts/site_layouts_generator.rb +4 -2
  307. data/lib/{rails/generators → generators}/alchemy/site_layouts/templates/layout.html.erb +0 -0
  308. data/lib/{rails/generators → generators}/alchemy/site_layouts/templates/layout.html.haml +0 -0
  309. data/lib/{rails/generators → generators}/alchemy/site_layouts/templates/layout.html.slim +0 -0
  310. data/lib/{rails/generators → generators}/alchemy/views/views_generator.rb +7 -6
  311. data/lib/kaminari/scoped_pagination_url_helper.rb +1 -0
  312. data/lib/tasks/alchemy/db.rake +3 -19
  313. data/lib/tasks/alchemy/install.rake +5 -48
  314. data/lib/tasks/alchemy/tidy.rake +9 -8
  315. data/lib/tasks/alchemy/upgrade.rake +18 -116
  316. data/package.json +45 -0
  317. data/package/admin.js +14 -0
  318. data/package/src/__tests__/i18n.spec.js +70 -0
  319. data/package/src/i18n.js +48 -0
  320. data/package/src/node_tree.js +72 -0
  321. data/package/src/translations.js +32 -0
  322. data/package/src/utils/__tests__/ajax.spec.js +124 -0
  323. data/package/src/utils/__tests__/events.spec.js +38 -0
  324. data/package/src/utils/ajax.js +48 -0
  325. data/package/src/utils/events.js +16 -0
  326. data/vendor/assets/fonts/fa-regular-400.eot +0 -0
  327. data/vendor/assets/fonts/fa-regular-400.svg +798 -358
  328. data/vendor/assets/fonts/fa-regular-400.ttf +0 -0
  329. data/vendor/assets/fonts/fa-regular-400.woff +0 -0
  330. data/vendor/assets/fonts/fa-regular-400.woff2 +0 -0
  331. data/vendor/assets/fonts/fa-solid-900.eot +0 -0
  332. data/vendor/assets/fonts/fa-solid-900.svg +4933 -1408
  333. data/vendor/assets/fonts/fa-solid-900.ttf +0 -0
  334. data/vendor/assets/fonts/fa-solid-900.woff +0 -0
  335. data/vendor/assets/fonts/fa-solid-900.woff2 +0 -0
  336. data/vendor/assets/javascripts/jquery_plugins/jquery.ui.nestedSortable.js +1 -2
  337. data/vendor/assets/stylesheets/fontawesome/_core.scss +5 -0
  338. data/vendor/assets/stylesheets/fontawesome/_fixed-width.scss +1 -1
  339. data/vendor/assets/stylesheets/fontawesome/_icons.scss +651 -2
  340. data/vendor/assets/stylesheets/fontawesome/_mixins.scss +0 -1
  341. data/vendor/assets/stylesheets/fontawesome/_rotated-flipped.scss +3 -2
  342. data/vendor/assets/stylesheets/fontawesome/_stacked.scss +1 -1
  343. data/vendor/assets/stylesheets/fontawesome/_variables.scss +662 -9
  344. data/vendor/assets/stylesheets/fontawesome/fontawesome.scss +2 -2
  345. data/vendor/assets/stylesheets/fontawesome/regular.scss +23 -0
  346. data/vendor/assets/stylesheets/fontawesome/solid.scss +24 -0
  347. metadata +112 -88
  348. data/app/assets/javascripts/alchemy/alchemy.i18n.js.coffee +0 -32
  349. data/app/assets/javascripts/alchemy/alchemy.node_tree.js +0 -66
  350. data/app/assets/javascripts/alchemy/alchemy.translations.js.coffee +0 -29
  351. data/app/assets/javascripts/alchemy/alchemy.utils.js +0 -45
  352. data/app/helpers/alchemy/essences_helper.rb +0 -119
  353. data/app/models/concerns/alchemy/content_touching.rb +0 -23
  354. data/app/serializers/alchemy/legacy_element_serializer.rb +0 -15
  355. data/app/views/alchemy/admin/contents/_missing.html.erb +0 -17
  356. data/app/views/alchemy/admin/pages/_menu_fields.html.erb +0 -37
  357. data/app/views/alchemy/admin/pages/configure_external.html.erb +0 -32
  358. data/app/views/alchemy/elements/_editor_not_found.html.erb +0 -4
  359. data/app/views/alchemy/navigation/_image_link.html.erb +0 -14
  360. data/app/views/alchemy/navigation/_link.html.erb +0 -19
  361. data/app/views/alchemy/navigation/_renderer.html.erb +0 -29
  362. data/db/migrate/20180226123013_alchemy_four_point_zero.rb +0 -363
  363. data/db/migrate/20180227224537_migrate_tags_to_gutentag.rb +0 -41
  364. data/db/migrate/20180519204655_add_fixed_to_alchemy_elements.rb +0 -6
  365. data/db/migrate/20191016073858_create_alchemy_essence_pages.rb +0 -8
  366. data/db/migrate/20191029212236_create_alchemy_nodes.rb +0 -24
  367. data/db/migrate/20200226081535_add_site_id_to_alchemy_nodes.rb +0 -15
  368. data/lib/alchemy/ssl_protection.rb +0 -34
  369. data/lib/alchemy/tasks/helpers.rb +0 -81
  370. data/lib/alchemy/test_support/controller_requests.rb +0 -93
  371. data/lib/alchemy/upgrader/four_point_four.rb +0 -52
  372. data/lib/alchemy/upgrader/four_point_one.rb +0 -42
  373. data/lib/alchemy/upgrader/four_point_six.rb +0 -50
  374. data/lib/alchemy/upgrader/four_point_two.rb +0 -85
  375. data/lib/alchemy/upgrader/tasks/cells_migration.rb +0 -43
  376. data/lib/alchemy/upgrader/tasks/cells_upgrader.rb +0 -148
  377. data/lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb +0 -28
  378. data/lib/alchemy/upgrader/tasks/harden_acts_as_taggable_on_migrations.rb +0 -27
  379. data/lib/alchemy/upgrader/tasks/picture_gallery_migration.rb +0 -65
  380. data/lib/alchemy/upgrader/tasks/picture_gallery_upgrader.rb +0 -210
  381. data/lib/rails/generators/alchemy/essence/templates/editor.html.erb +0 -15
  382. data/lib/rails/generators/alchemy/install/install_generator.rb +0 -60
  383. data/lib/tasks/alchemy/convert.rake +0 -97
  384. data/vendor/assets/javascripts/sortable/Sortable.min.js +0 -2
  385. data/vendor/assets/stylesheets/fontawesome/fa-regular.scss +0 -22
  386. data/vendor/assets/stylesheets/fontawesome/fa-solid.scss +0 -23
@@ -8,7 +8,7 @@ module Alchemy
8
8
  "audio/mpeg",
9
9
  "audio/mp4",
10
10
  "audio/wav",
11
- "audio/x-wav"
11
+ "audio/x-wav",
12
12
  ]
13
13
 
14
14
  IMAGE_FILE_TYPES = [
@@ -17,7 +17,7 @@ module Alchemy
17
17
  "image/png",
18
18
  "image/svg+xml",
19
19
  "image/tiff",
20
- "image/x-psd"
20
+ "image/x-psd",
21
21
  ]
22
22
 
23
23
  VCARD_FILE_TYPES = ["text/x-vcard", "application/vcard"]
@@ -29,18 +29,18 @@ module Alchemy
29
29
  "video/mpeg",
30
30
  "video/quicktime",
31
31
  "video/x-msvideo",
32
- "video/x-ms-wmv"
32
+ "video/x-ms-wmv",
33
33
  ]
34
34
 
35
35
  TEXT_FILE_TYPES = [
36
36
  "application/rtf",
37
- "text/plain"
37
+ "text/plain",
38
38
  ]
39
39
 
40
40
  EXCEL_FILE_TYPES = [
41
41
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
42
42
  "application/vnd.ms-excel",
43
- "text/csv"
43
+ "text/csv",
44
44
  ]
45
45
  end
46
46
  end
@@ -11,7 +11,7 @@ module Alchemy
11
11
  if object.respond_to?(:attribute_fixed?) && object.attribute_fixed?(attribute_name)
12
12
  options[:disabled] = true
13
13
  options[:input_html] = options.fetch(:input_html, {}).merge(
14
- 'data-alchemy-tooltip' => Alchemy.t(:attribute_fixed, attribute_name)
14
+ "data-alchemy-tooltip" => Alchemy.t(:attribute_fixed, attribute_name),
15
15
  )
16
16
  end
17
17
 
@@ -22,10 +22,10 @@ module Alchemy
22
22
  #
23
23
  def submit(label, options = {})
24
24
  options = {
25
- wrapper_html: {class: 'submit'}
25
+ wrapper_html: {class: "submit"},
26
26
  }.update(options)
27
- template.content_tag('div', options.delete(:wrapper_html)) do
28
- template.content_tag('button', label, options.delete(:input_html))
27
+ template.content_tag("div", options.delete(:wrapper_html)) do
28
+ template.content_tag("button", label, options.delete(:input_html))
29
29
  end
30
30
  end
31
31
  end
@@ -35,7 +35,7 @@ module Alchemy
35
35
  # @return String
36
36
  #
37
37
  def hint
38
- hint = definition['hint']
38
+ hint = definition["hint"]
39
39
  if hint == true
40
40
  Alchemy.t(name, scope: hint_translation_scope)
41
41
  else
@@ -74,11 +74,12 @@ module Alchemy
74
74
 
75
75
  def humanize_default_string!(msg, options)
76
76
  return if options[:default].present?
77
+
77
78
  options[:default] = msg.is_a?(Symbol) ? msg.to_s.humanize : msg
78
79
  end
79
80
 
80
81
  def alchemy_scoped_scope(options)
81
- default_scope = ['alchemy']
82
+ default_scope = ["alchemy"]
82
83
  case options[:scope]
83
84
  when Array
84
85
  default_scope + options[:scope]
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ require "thor"
3
+
4
+ module Alchemy
5
+ module Install
6
+ class Tasks < Thor
7
+ include Thor::Actions
8
+
9
+ no_tasks do
10
+ def inject_routes(auto_accept = false)
11
+ return if File.read("./config/routes.rb").match?("mount Alchemy::Engine")
12
+
13
+ mountpoint = "/"
14
+ unless auto_accept
15
+ mountpoint = ask("- At which path do you want to mount Alchemy CMS at?", default: mountpoint)
16
+ end
17
+ sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
18
+ inject_into_file "./config/routes.rb", "\n mount Alchemy::Engine => '#{mountpoint}'\n", { after: sentinel, verbose: true }
19
+ end
20
+
21
+ def set_primary_language(auto_accept = false)
22
+ code = "en"
23
+ unless auto_accept
24
+ code = ask("- What is the language code of your site's primary language?", default: code)
25
+ end
26
+ name = "English"
27
+ unless auto_accept
28
+ name = ask("- What is the name of your site's primary language?", default: name)
29
+ end
30
+ gsub_file "./config/alchemy/config.yml", /default_language:\n\s\scode:\sen\n\s\sname:\sEnglish/m do
31
+ "default_language:\n code: #{code}\n name: #{name}"
32
+ end
33
+ end
34
+
35
+ def inject_seeder
36
+ append_file "./db/seeds.rb", "Alchemy::Seeder.seed!\n"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -4,7 +4,7 @@ module Alchemy
4
4
  module Modules
5
5
  mattr_accessor :alchemy_modules
6
6
 
7
- @@alchemy_modules = YAML.load_file(File.expand_path('../../config/alchemy/modules.yml', __dir__))
7
+ @@alchemy_modules = YAML.load_file(File.expand_path("../../config/alchemy/modules.yml", __dir__))
8
8
 
9
9
  class << self
10
10
  def included(base)
@@ -28,11 +28,11 @@ module Alchemy
28
28
  definition_hash = module_definition.deep_stringify_keys
29
29
 
30
30
  ### Validate controller(s) existence
31
- if definition_hash['navigation'].is_a?(Hash)
32
- defined_controllers = [definition_hash['navigation']['controller']]
31
+ if definition_hash["navigation"].is_a?(Hash)
32
+ defined_controllers = [definition_hash["navigation"]["controller"]]
33
33
 
34
- if definition_hash['navigation']['sub_navigation'].is_a?(Array)
35
- defined_controllers.concat(definition_hash['navigation']['sub_navigation'].map{ |x| x['controller'] })
34
+ if definition_hash["navigation"]["sub_navigation"].is_a?(Array)
35
+ defined_controllers.concat(definition_hash["navigation"]["sub_navigation"].map{ |x| x["controller"] })
36
36
  end
37
37
 
38
38
  validate_controllers_existence(defined_controllers)
@@ -52,7 +52,7 @@ module Alchemy
52
52
  begin
53
53
  controller_name.constantize
54
54
  rescue NameError
55
- raise "Error in AlchemyCMS module definition: '#{definition_hash['name']}'. Could not find the matching controller class #{controller_name.sub(/^::/, '')} for the specified controller: '#{controller_val}'"
55
+ raise "Error in AlchemyCMS module definition: '#{definition_hash["name"]}'. Could not find the matching controller class #{controller_name.sub(/^::/, "")} for the specified controller: '#{controller_val}'"
56
56
  end
57
57
  end
58
58
  end
@@ -66,11 +66,11 @@ module Alchemy
66
66
  def module_definition_for(name_or_params)
67
67
  case name_or_params
68
68
  when String
69
- alchemy_modules.detect { |m| m['name'] == name_or_params }
69
+ alchemy_modules.detect { |m| m["name"] == name_or_params }
70
70
  when Hash
71
71
  name_or_params.stringify_keys!
72
72
  alchemy_modules.detect do |alchemy_module|
73
- module_navi = alchemy_module.fetch('navigation', {})
73
+ module_navi = alchemy_module.fetch("navigation", {})
74
74
  definition_from_mainnavi(module_navi, name_or_params) ||
75
75
  definition_from_subnavi(module_navi, name_or_params)
76
76
  end
@@ -86,7 +86,7 @@ module Alchemy
86
86
  end
87
87
 
88
88
  def definition_from_subnavi(module_navi, params)
89
- subnavi = module_navi['sub_navigation']
89
+ subnavi = module_navi["sub_navigation"]
90
90
  return if subnavi.nil?
91
91
 
92
92
  subnavi.any? do |navi|
@@ -95,15 +95,15 @@ module Alchemy
95
95
  end
96
96
 
97
97
  def controller_matches?(navi, params)
98
- remove_slash(navi['controller']) == remove_slash(params['controller'])
98
+ remove_slash(navi["controller"]) == remove_slash(params["controller"])
99
99
  end
100
100
 
101
101
  def action_matches?(navi, params)
102
- navi['action'] == params['action']
102
+ navi["action"] == params["action"]
103
103
  end
104
104
 
105
105
  def remove_slash(str)
106
- str.gsub(/^\//, '')
106
+ str.gsub(/^\//, "")
107
107
  end
108
108
  end
109
109
  end
@@ -10,17 +10,17 @@ module Alchemy
10
10
  # @returns String
11
11
  def convert_to_urlname(name)
12
12
  name
13
- .gsub(/[äÄ]/, 'ae')
14
- .gsub(/[üÜ]/, 'ue')
15
- .gsub(/[öÖ]/, 'oe')
16
- .gsub(/[ß]/, 'ss')
13
+ .gsub(/[äÄ]/, "ae")
14
+ .gsub(/[üÜ]/, "ue")
15
+ .gsub(/[öÖ]/, "oe")
16
+ .gsub(/[ß]/, "ss")
17
17
  .parameterize
18
18
  end
19
19
 
20
20
  # Converts a filename and suffix into a human readable name.
21
21
  #
22
22
  def convert_to_humanized_name(name, suffix)
23
- name.gsub(/\.#{::Regexp.quote(suffix)}$/i, '').tr('_', ' ').strip
23
+ name.gsub(/\.#{::Regexp.quote(suffix)}$/i, "").tr("_", " ").strip
24
24
  end
25
25
  end
26
26
  end
@@ -18,6 +18,7 @@ module Alchemy
18
18
  def run_on_page_layout_callbacks
19
19
  OnPageLayout.callbacks.each do |page_layout, callbacks|
20
20
  next unless call_page_layout_callback_for?(page_layout)
21
+
21
22
  callbacks.each do |callback|
22
23
  if callback.respond_to?(:call)
23
24
  instance_eval(&callback)
@@ -37,7 +37,8 @@ module Alchemy
37
37
  #
38
38
  def get(name)
39
39
  return {} if name.blank?
40
- all.detect { |a| a['name'].casecmp(name).zero? }
40
+
41
+ all.detect { |a| a["name"].casecmp(name).zero? }
41
42
  end
42
43
 
43
44
  def get_all_by_attributes(attributes)
@@ -66,7 +67,7 @@ module Alchemy
66
67
  #
67
68
  def layouts_with_own_for_select(page_layout_name, language_id, only_layoutpages = false)
68
69
  layouts = selectable_layouts(language_id, only_layoutpages)
69
- if layouts.detect { |l| l['name'] == page_layout_name }.nil?
70
+ if layouts.detect { |l| l["name"] == page_layout_name }.nil?
70
71
  @map_array = [[human_layout_name(page_layout_name), page_layout_name]]
71
72
  else
72
73
  @map_array = []
@@ -87,9 +88,9 @@ module Alchemy
87
88
  @language_id = language_id
88
89
  all.select do |layout|
89
90
  if only_layoutpages
90
- layout['layoutpage'] && layout_available?(layout)
91
+ layout["layoutpage"] && layout_available?(layout)
91
92
  else
92
- !layout['layoutpage'] && layout_available?(layout)
93
+ !layout["layoutpage"] && layout_available?(layout)
93
94
  end
94
95
  end
95
96
  end
@@ -98,7 +99,7 @@ module Alchemy
98
99
  #
99
100
  def element_names_for(page_layout)
100
101
  if definition = get(page_layout)
101
- definition.fetch('elements', [])
102
+ definition.fetch("elements", [])
102
103
  else
103
104
  Rails.logger.warn "\n+++ Warning: No layout definition for #{page_layout} found! in page_layouts.yml\n"
104
105
  []
@@ -118,7 +119,7 @@ module Alchemy
118
119
  # The layout name
119
120
  #
120
121
  def human_layout_name(layout)
121
- Alchemy.t(layout, scope: 'page_layout_names', default: layout.to_s.humanize)
122
+ Alchemy.t(layout, scope: "page_layout_names", default: layout.to_s.humanize)
122
123
  end
123
124
 
124
125
  private
@@ -126,13 +127,13 @@ module Alchemy
126
127
  # Returns true if the given layout is unique and not already taken or it should be hidden.
127
128
  #
128
129
  def layout_available?(layout)
129
- !layout['hide'] && !already_taken?(layout) && available_on_site?(layout)
130
+ !layout["hide"] && !already_taken?(layout) && available_on_site?(layout)
130
131
  end
131
132
 
132
133
  # Returns true if this layout is unique and already taken by another page.
133
134
  #
134
135
  def already_taken?(layout)
135
- layout['unique'] && page_with_layout_existing?(layout['name'])
136
+ layout["unique"] && page_with_layout_existing?(layout["name"])
136
137
  end
137
138
 
138
139
  # Returns true if one page already has the given layout
@@ -152,8 +153,10 @@ module Alchemy
152
153
  # page_layouts: [default_intro]
153
154
  #
154
155
  def available_on_site?(layout)
156
+ return false unless Alchemy::Site.current
157
+
155
158
  Alchemy::Site.current.definition.blank? ||
156
- Alchemy::Site.current.definition.fetch('page_layouts', []).include?(layout['name'])
159
+ Alchemy::Site.current.definition.fetch("page_layouts", []).include?(layout["name"])
157
160
  end
158
161
 
159
162
  # Reads the layout definitions from +config/alchemy/page_layouts.yml+.
@@ -162,21 +165,21 @@ module Alchemy
162
165
  if File.exist?(layouts_file_path)
163
166
  YAML.safe_load(ERB.new(File.read(layouts_file_path)).result, YAML_WHITELIST_CLASSES, [], true) || []
164
167
  else
165
- raise LoadError, "Could not find page_layouts.yml file! Please run `rails generate alchemy:scaffold`"
168
+ raise LoadError, "Could not find page_layouts.yml file! Please run `rails generate alchemy:install`"
166
169
  end
167
170
  end
168
171
 
169
172
  # Returns the page_layouts.yml file path
170
173
  #
171
174
  def layouts_file_path
172
- Rails.root.join 'config/alchemy/page_layouts.yml'
175
+ Rails.root.join "config/alchemy/page_layouts.yml"
173
176
  end
174
177
 
175
178
  # Maps given layouts for Rails select form helper.
176
179
  #
177
180
  def mapped_layouts_for_select(layouts)
178
181
  layouts.each do |layout|
179
- @map_array << [human_layout_name(layout['name']), layout["name"]]
182
+ @map_array << [human_layout_name(layout["name"]), layout["name"]]
180
183
  end
181
184
  @map_array
182
185
  end
@@ -29,6 +29,6 @@ module Alchemy
29
29
 
30
30
  # Defaults
31
31
  #
32
- @@admin_path = 'admin'
32
+ @@admin_path = "admin"
33
33
  @@admin_constraints = {}
34
34
  end
@@ -36,7 +36,7 @@ module Alchemy
36
36
  module GuestUser
37
37
  def alchemy_guest_user_rules
38
38
  can([:show, :download], Alchemy::Attachment) { |a| !a.restricted? }
39
- can :see, Alchemy::Page, restricted: false, visible: true
39
+ can :see, Alchemy::Page, restricted: false
40
40
 
41
41
  can :read, Alchemy::Content, Alchemy::Content.available.not_restricted do |c|
42
42
  c.public? && !c.restricted? && !c.trashed?
@@ -64,7 +64,7 @@ module Alchemy
64
64
 
65
65
  # Resources
66
66
  can [:show, :download], Alchemy::Attachment
67
- can :see, Alchemy::Page, restricted: true, visible: true
67
+ can :see, Alchemy::Page, restricted: true
68
68
 
69
69
  can :read, Alchemy::Content, Alchemy::Content.available do |c|
70
70
  c.public? && !c.trashed?
@@ -99,7 +99,7 @@ module Alchemy
99
99
  :alchemy_admin_pages,
100
100
  :alchemy_admin_pictures,
101
101
  :alchemy_admin_tags,
102
- :alchemy_admin_users
102
+ :alchemy_admin_users,
103
103
  ]
104
104
 
105
105
  # Controller actions
@@ -137,7 +137,7 @@ module Alchemy
137
137
  # Navigation
138
138
  can :index, [
139
139
  :alchemy_admin_languages,
140
- :alchemy_admin_users
140
+ :alchemy_admin_users,
141
141
  ]
142
142
 
143
143
  # Controller actions
@@ -150,7 +150,7 @@ module Alchemy
150
150
  :flush,
151
151
  :order,
152
152
  :sort,
153
- :switch_language
153
+ :switch_language,
154
154
  ], Alchemy::Page
155
155
 
156
156
  # Resources which may be locked via template permissions
@@ -164,7 +164,7 @@ module Alchemy
164
164
  can([
165
165
  :create,
166
166
  :destroy,
167
- :publish
167
+ :publish,
168
168
  ], Alchemy::Page) { |p| p.editable_by?(@user) }
169
169
 
170
170
  can :manage, Alchemy::Picture
@@ -200,6 +200,7 @@ module Alchemy
200
200
 
201
201
  def user_role_rules
202
202
  return alchemy_guest_user_rules if @user.alchemy_roles.blank?
203
+
203
204
  @user.alchemy_roles.each do |role|
204
205
  exec_role_rules(role)
205
206
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support'
4
- require 'active_support/core_ext'
5
- require 'active_support/inflector'
3
+ require "active_support"
4
+ require "active_support/core_ext"
5
+ require "active_support/inflector"
6
6
 
7
7
  module Alchemy
8
8
  # = Alchemy::Resource
@@ -101,8 +101,8 @@ module Alchemy
101
101
  attr_accessor :resource_relations, :model_associations
102
102
  attr_reader :model
103
103
 
104
- DEFAULT_SKIPPED_ATTRIBUTES = %w(id updated_at created_at creator_id updater_id)
105
- DEFAULT_SKIPPED_ASSOCIATIONS = %w(creator updater)
104
+ DEFAULT_SKIPPED_ATTRIBUTES = %w(id created_at creator_id)
105
+ DEFAULT_SKIPPED_ASSOCIATIONS = %w(creator)
106
106
  SEARCHABLE_COLUMN_TYPES = [:string, :text]
107
107
 
108
108
  def initialize(controller_path, module_definition = nil, custom_model = nil)
@@ -113,13 +113,14 @@ module Alchemy
113
113
  if !model.respond_to?(:reflect_on_all_associations)
114
114
  raise MissingActiveRecordAssociation
115
115
  end
116
+
116
117
  store_model_associations
117
118
  map_relations
118
119
  end
119
120
  end
120
121
 
121
122
  def resource_array
122
- @_resource_array ||= controller_path_array.reject { |el| el == 'admin' }
123
+ @_resource_array ||= controller_path_array.reject { |el| el == "admin" }
123
124
  end
124
125
 
125
126
  def resources_name
@@ -138,7 +139,7 @@ module Alchemy
138
139
  @_namespaced_resources_name ||= begin
139
140
  resource_name_array = resource_array.dup
140
141
  resource_name_array.delete(engine_name) if in_engine?
141
- resource_name_array.join('_')
142
+ resource_name_array.join("_")
142
143
  end
143
144
  end
144
145
 
@@ -152,6 +153,7 @@ module Alchemy
152
153
  #
153
154
  def model_association_names
154
155
  return unless model_associations
156
+
155
157
  model_associations.map do |assoc|
156
158
  assoc.name.to_sym
157
159
  end
@@ -160,14 +162,22 @@ module Alchemy
160
162
  def attributes
161
163
  @_attributes ||= model.columns.collect do |col|
162
164
  next if skipped_attributes.include?(col.name)
165
+
163
166
  {
164
167
  name: col.name,
165
168
  type: resource_column_type(col),
166
- relation: resource_relation(col.name)
169
+ relation: resource_relation(col.name),
167
170
  }.delete_if { |_k, v| v.nil? }
168
171
  end.compact
169
172
  end
170
173
 
174
+ def sorted_attributes
175
+ @_sorted_attributes ||= attributes.
176
+ sort_by { |attr| attr[:name] == "name" ? 0 : 1 }.
177
+ sort_by! { |attr| attr[:type] == :boolean ? 1 : 0 }.
178
+ sort_by! { |attr| attr[:name] == "updated_at" ? 1 : 0 }
179
+ end
180
+
171
181
  def editable_attributes
172
182
  attributes.reject { |h| restricted_attributes.map(&:to_s).include?(h[:name].to_s) }
173
183
  end
@@ -197,10 +207,10 @@ module Alchemy
197
207
  end
198
208
 
199
209
  def engine_name
200
- @module_definition && @module_definition['engine_name']
210
+ @module_definition && @module_definition["engine_name"]
201
211
  end
202
212
 
203
- # Returns a help text for resource's form
213
+ # Returns a help text for resource's form or nil if no help text is available
204
214
  #
205
215
  # === Example:
206
216
  #
@@ -213,7 +223,7 @@ module Alchemy
213
223
  def help_text_for(attribute)
214
224
  ::I18n.translate!(attribute[:name], scope: [:alchemy, :resource_help_texts, resource_name])
215
225
  rescue ::I18n::MissingTranslationData
216
- false
226
+ nil
217
227
  end
218
228
 
219
229
  # Return attributes that should be viewable but not editable.
@@ -254,16 +264,16 @@ module Alchemy
254
264
  def searchable_relation_attribute(attribute)
255
265
  {
256
266
  name: "#{attribute[:relation][:model_association].name}_#{attribute[:relation][:attr_method]}",
257
- type: attribute[:relation][:attr_type]
267
+ type: attribute[:relation][:attr_type],
258
268
  }
259
269
  end
260
270
 
261
271
  def guess_model_from_controller_path
262
- resource_array.join('/').classify.constantize
272
+ resource_array.join("/").classify.constantize
263
273
  end
264
274
 
265
275
  def controller_path_array
266
- @controller_path.split('/')
276
+ @controller_path.split("/")
267
277
  end
268
278
 
269
279
  def namespace_diff
@@ -286,7 +296,7 @@ module Alchemy
286
296
  def map_relations
287
297
  self.resource_relations = {}
288
298
  model.alchemy_resource_relations.each do |name, options|
289
- name = name.to_s.gsub(/_id$/, '') # ensure that we don't have an id
299
+ name = name.to_s.gsub(/_id$/, "") # ensure that we don't have an id
290
300
  association = association_from_relation_name(name)
291
301
  foreign_key = association.options[:foreign_key] || "#{association.name}_id".to_sym
292
302
  resource_relations[foreign_key] = options.merge(model_association: association, name: name)