From beb1058801d4a847a223ed843262a6d809d20668 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 10 Oct 2019 23:52:27 +0200 Subject: [PATCH 1/2] Deprecate element editors Render all essence editors for each content an element has instead. Fall back to render element editor if present. --- app/helpers/alchemy/admin/elements_helper.rb | 6 ++++++ app/helpers/alchemy/admin/essences_helper.rb | 8 ++++++-- app/helpers/alchemy/elements_block_helper.rb | 3 ++- app/views/alchemy/admin/elements/_element.html.erb | 10 +++++++++- .../alchemy/elements/_all_you_can_eat_editor.html.erb | 11 ----------- .../views/alchemy/elements/_article_editor.html.erb | 6 ------ .../app/views/alchemy/elements/_bild_editor.html.erb | 3 --- .../alchemy/elements/_contactform_editor.html.erb | 6 ------ .../views/alchemy/elements/_download_editor.html.erb | 3 --- .../alchemy/elements/_erb_element_editor.html.erb | 3 --- .../views/alchemy/elements/_gallery_editor.html.erb | 1 - .../alchemy/elements/_gallery_picture_editor.html.erb | 3 --- .../views/alchemy/elements/_header_editor.html.erb | 3 --- .../views/alchemy/elements/_headline_editor.html.erb | 1 - .../alchemy/elements/_left_column_editor.html.erb | 1 - .../app/views/alchemy/elements/_news_editor.html.erb | 5 ----- .../alchemy/elements/_right_column_editor.html.erb | 3 --- .../views/alchemy/elements/_search_editor.html.erb | 1 - .../app/views/alchemy/elements/_slide_editor.html.erb | 4 ---- .../views/alchemy/elements/_slider_editor.html.erb | 2 -- .../app/views/alchemy/elements/_text_editor.html.erb | 3 --- spec/helpers/alchemy/admin/elements_helper_spec.rb | 4 +++- 22 files changed, 26 insertions(+), 64 deletions(-) delete mode 100644 spec/dummy/app/views/alchemy/elements/_all_you_can_eat_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_article_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_bild_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_contactform_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_download_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_erb_element_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_gallery_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_gallery_picture_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_header_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_headline_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_left_column_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_news_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_right_column_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_search_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_slide_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_slider_editor.html.erb delete mode 100644 spec/dummy/app/views/alchemy/elements/_text_editor.html.erb diff --git a/app/helpers/alchemy/admin/elements_helper.rb b/app/helpers/alchemy/admin/elements_helper.rb index 24bdc847fa..0a440b587c 100644 --- a/app/helpers/alchemy/admin/elements_helper.rb +++ b/app/helpers/alchemy/admin/elements_helper.rb @@ -48,12 +48,18 @@ module ElementsHelper # @note If the partial is not found # alchemy/elements/_editor_not_found.html.erb gets rendered. # + # @deprecated Using element editor partials is deprecated and will be removed in Alchemy 5.0 def render_editor(element) if element.nil? warning('Element is nil') render "alchemy/elements/editor_not_found", {name: 'nil'} return end + Alchemy::Deprecation.warn <<~WARN + Using element editor partials is deprecated and will be removed in Alchemy 5.0. + You can delete the `app/views/alchemy/elements/_#{element.name}_editor` partial + and Alchemy will render the content editors for you. + WARN render "alchemy/elements/#{element.name}_editor", element: element rescue ActionView::MissingTemplate => e diff --git a/app/helpers/alchemy/admin/essences_helper.rb b/app/helpers/alchemy/admin/essences_helper.rb index e8ab271293..e3bfa63885 100644 --- a/app/helpers/alchemy/admin/essences_helper.rb +++ b/app/helpers/alchemy/admin/essences_helper.rb @@ -8,6 +8,7 @@ module EssencesHelper # Renders the Content editor partial from the given Content. # For options see -> render_essence + # @deprecated def render_essence_editor(content, options = {}, html_options = {}) if !options.empty? Alchemy::Deprecation.warn <<~WARN @@ -23,6 +24,7 @@ def render_essence_editor(content, options = {}, html_options = {}) end render_essence(content, :editor, {for_editor: options}, html_options) end + deprecate :render_essence_editor, deprecator: Alchemy::Deprecation # Renders the Content editor partial found in views/contents/ for the content with name inside the passed Element. # For options see -> render_essence @@ -30,7 +32,7 @@ def render_essence_editor(content, options = {}, html_options = {}) # Content creation on the fly: # # If you update the elements.yml file after creating an element this helper displays a error message with an option to create the content. - # + # @deprecated def render_essence_editor_by_name(element, name, options = {}, html_options = {}) if element.blank? return warning('Element is nil', Alchemy.t(:no_element_given)) @@ -42,6 +44,7 @@ def render_essence_editor_by_name(element, name, options = {}, html_options = {} render_essence_editor(content, options, html_options) end end + deprecate :render_essence_editor_by_name, deprecator: Alchemy::Deprecation # Returns all public pages from current language as an option tags string suitable or the Rails +select_tag+ helper. # @@ -65,10 +68,11 @@ def pages_for_select(pages = nil, selected = nil, prompt = "Choose page", page_a end # Renders the missing content partial - # + # @deprecated def render_missing_content(element, name, options) render 'alchemy/admin/contents/missing', {element: element, name: name, options: options} end + deprecate :render_missing_content, deprecator: Alchemy::Deprecation # Renders a thumbnail for given EssencePicture content with correct cropping and size def essence_picture_thumbnail(content, options = {}) diff --git a/app/helpers/alchemy/elements_block_helper.rb b/app/helpers/alchemy/elements_block_helper.rb index df43db00db..98c4fe28dd 100644 --- a/app/helpers/alchemy/elements_block_helper.rb +++ b/app/helpers/alchemy/elements_block_helper.rb @@ -56,11 +56,12 @@ def essence(name) end # Block-level helper class for element editors. - # + # @deprecated class ElementEditorHelper < BlockHelper def edit(name, *args) helpers.render_essence_editor_by_name(element, name.to_s, *args) end + deprecate :edit, deprecator: Alchemy::Deprecation end # Block-level helper for element views. Constructs a DOM element wrapping diff --git a/app/views/alchemy/admin/elements/_element.html.erb b/app/views/alchemy/admin/elements/_element.html.erb index c19c571dfd..32b2dab55c 100644 --- a/app/views/alchemy/admin/elements/_element.html.erb +++ b/app/views/alchemy/admin/elements/_element.html.erb @@ -22,7 +22,15 @@ <% element.definition[:warning].tap do |warning| %> <%= render_message(:warning, sanitize(warning)) if warning %> <% end %> - <%== render_editor(element) %> + <% if lookup_context.exists?("#{element.name}_editor", ["alchemy/elements"], true) %> + <%= render_editor(element) %> + <% else %> + <%= element_editor_for(element) do %> + <% element.contents.each do |content| %> + <%= render_essence(content, :editor) %> + <% end %> + <% end %> + <% end %> <% if element.taggable? %> diff --git a/spec/dummy/app/views/alchemy/elements/_all_you_can_eat_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_all_you_can_eat_editor.html.erb deleted file mode 100644 index 561cc5aee9..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_all_you_can_eat_editor.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :essence_text %> - <%= el.edit :essence_picture %> - <%= el.edit :essence_richtext %> - <%= el.edit :essence_select %> - <%= el.edit :essence_boolean %> - <%= el.edit :essence_date %> - <%= el.edit :essence_file %> - <%= el.edit :essence_html %> - <%= el.edit :essence_link %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_article_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_article_editor.html.erb deleted file mode 100644 index f96d9a4b64..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_article_editor.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :intro %> - <%= el.edit :headline %> - <%= el.edit :image %> - <%= el.edit :text %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_bild_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_bild_editor.html.erb deleted file mode 100644 index fecffdfc5c..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_bild_editor.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :image %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_contactform_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_contactform_editor.html.erb deleted file mode 100644 index b309b233b5..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_contactform_editor.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :mail_from %> - <%= el.edit :mail_to %> - <%= el.edit :subject %> - <%= el.edit :success_page %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_download_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_download_editor.html.erb deleted file mode 100644 index 12f1ebcfdd..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_download_editor.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :file %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_erb_element_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_erb_element_editor.html.erb deleted file mode 100644 index 682a317705..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_erb_element_editor.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :text %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_gallery_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_gallery_editor.html.erb deleted file mode 100644 index 04d1c86241..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_gallery_editor.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= element_editor_for(element) %> diff --git a/spec/dummy/app/views/alchemy/elements/_gallery_picture_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_gallery_picture_editor.html.erb deleted file mode 100644 index 8080dffb2f..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_gallery_picture_editor.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :picture %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_header_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_header_editor.html.erb deleted file mode 100644 index fecffdfc5c..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_header_editor.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :image %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_headline_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_headline_editor.html.erb deleted file mode 100644 index c9e59948c0..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_headline_editor.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render_essence_editor_by_name(element, 'headline') %> diff --git a/spec/dummy/app/views/alchemy/elements/_left_column_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_left_column_editor.html.erb deleted file mode 100644 index dcec57c1a2..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_left_column_editor.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= element_editor_for(element) -%> diff --git a/spec/dummy/app/views/alchemy/elements/_news_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_news_editor.html.erb deleted file mode 100644 index b99b0a368f..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_news_editor.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :date %> - <%= el.edit :news_headline %> - <%= el.edit :body %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_right_column_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_right_column_editor.html.erb deleted file mode 100644 index d224bd7c58..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_right_column_editor.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :title %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_search_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_search_editor.html.erb deleted file mode 100644 index dcec57c1a2..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_search_editor.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= element_editor_for(element) -%> diff --git a/spec/dummy/app/views/alchemy/elements/_slide_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_slide_editor.html.erb deleted file mode 100644 index 900c738d7e..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_slide_editor.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :picture %> - <%= el.edit :caption %> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_slider_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_slider_editor.html.erb deleted file mode 100644 index 7448643b5b..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_slider_editor.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -<%= element_editor_for(element) do |el| -%> -<%- end -%> diff --git a/spec/dummy/app/views/alchemy/elements/_text_editor.html.erb b/spec/dummy/app/views/alchemy/elements/_text_editor.html.erb deleted file mode 100644 index 682a317705..0000000000 --- a/spec/dummy/app/views/alchemy/elements/_text_editor.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= element_editor_for(element) do |el| -%> - <%= el.edit :text %> -<%- end -%> diff --git a/spec/helpers/alchemy/admin/elements_helper_spec.rb b/spec/helpers/alchemy/admin/elements_helper_spec.rb index 43250148ca..0a701d2032 100644 --- a/spec/helpers/alchemy/admin/elements_helper_spec.rb +++ b/spec/helpers/alchemy/admin/elements_helper_spec.rb @@ -22,7 +22,9 @@ module Alchemy end it "renders the element's editor partial" do - is_expected.to have_selector('div.content_editor > label', text: 'Headline') + element_editor_partial_name = "alchemy/elements/#{element.name}_editor" + expect(helper).to receive(:render).with(element_editor_partial_name, element: element) { '' } + subject end context 'with element editor partial not found' do From e3e1414eed1dfd39257ece04c2fb1c659315c088 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 16 Oct 2019 11:44:46 +0200 Subject: [PATCH 2/2] Remove element editor generator We do not need a element editor partial anymore. Alchemy handles this for you. --- .../generators/alchemy/elements/elements_generator.rb | 1 - .../alchemy/elements/templates/editor.html.erb | 9 --------- .../alchemy/elements/templates/editor.html.haml | 8 -------- .../alchemy/elements/templates/editor.html.slim | 8 -------- 4 files changed, 26 deletions(-) delete mode 100644 lib/rails/generators/alchemy/elements/templates/editor.html.erb delete mode 100644 lib/rails/generators/alchemy/elements/templates/editor.html.haml delete mode 100644 lib/rails/generators/alchemy/elements/templates/editor.html.slim diff --git a/lib/rails/generators/alchemy/elements/elements_generator.rb b/lib/rails/generators/alchemy/elements/elements_generator.rb index ea12938804..c1244d9cfe 100644 --- a/lib/rails/generators/alchemy/elements/elements_generator.rb +++ b/lib/rails/generators/alchemy/elements/elements_generator.rb @@ -19,7 +19,6 @@ def create_partials raise "Element name '#{element['name']}' has wrong format. Only lowercase and non whitespace characters allowed." end - conditional_template "editor.html.#{template_engine}", "#{elements_dir}/_#{@element_name}_editor.html.#{template_engine}" conditional_template "view.html.#{template_engine}", "#{elements_dir}/_#{@element_name}_view.html.#{template_engine}" end end diff --git a/lib/rails/generators/alchemy/elements/templates/editor.html.erb b/lib/rails/generators/alchemy/elements/templates/editor.html.erb deleted file mode 100644 index a7b0f25bb9..0000000000 --- a/lib/rails/generators/alchemy/elements/templates/editor.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<%- if @contents.any? || @element['picture_gallery'] -%> -<%%= element_editor_for(element) do |el| -%> -<%- @contents.each do |content| -%> - <%%= el.edit :<%= content["name"] %> %> -<%- end -%> -<%%- end -%> -<%- else -%> -<%%= element_editor_for(element) -%> -<%- end -%> diff --git a/lib/rails/generators/alchemy/elements/templates/editor.html.haml b/lib/rails/generators/alchemy/elements/templates/editor.html.haml deleted file mode 100644 index 7c26c0f11b..0000000000 --- a/lib/rails/generators/alchemy/elements/templates/editor.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -<%- if @contents.any? || @element['picture_gallery'] -%> -= element_editor_for(element) do |el| -<%- @contents.each do |content| -%> - = el.edit :<%= content["name"] %> -<%- end -%> -<%- else -%> -= element_editor_for(element) -<%- end -%> diff --git a/lib/rails/generators/alchemy/elements/templates/editor.html.slim b/lib/rails/generators/alchemy/elements/templates/editor.html.slim deleted file mode 100644 index 7c26c0f11b..0000000000 --- a/lib/rails/generators/alchemy/elements/templates/editor.html.slim +++ /dev/null @@ -1,8 +0,0 @@ -<%- if @contents.any? || @element['picture_gallery'] -%> -= element_editor_for(element) do |el| -<%- @contents.each do |content| -%> - = el.edit :<%= content["name"] %> -<%- end -%> -<%- else -%> -= element_editor_for(element) -<%- end -%>