From f0ed7a0ad1b0dc8674d035ecc530929c09bb56a2 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 10 Oct 2019 11:17:06 +0200 Subject: [PATCH] Remove local options from essence editors Passing options as locals to essence editors is not possible anymore. Static values should be set on the content settings on the contents defintion in elements.yml instead. For dynamic values please use a custom essence class. --- app/helpers/alchemy/admin/essences_helper.rb | 32 ++++----------- app/helpers/alchemy/elements_block_helper.rb | 4 +- .../alchemy/admin/essence_files/edit.html.erb | 2 +- .../essences/_essence_boolean_editor.html.erb | 7 +--- .../essences/_essence_date_editor.html.erb | 2 +- .../essences/_essence_file_editor.html.erb | 10 ++--- .../essences/_essence_picture_editor.html.erb | 5 +-- .../essences/_essence_select_editor.html.erb | 13 +++--- .../essences/_essence_text_editor.html.erb | 10 ++--- .../shared/_essence_picture_tools.html.erb | 17 +++----- .../alchemy/essence/templates/editor.html.erb | 1 - .../alchemy/elements_block_helper_spec.rb | 4 +- .../essences/essence_boolean_editor_spec.rb | 30 +++++++++----- .../essences/essence_date_editor_spec.rb | 18 ++++++++ .../essences/essence_picture_editor_spec.rb | 11 +++-- .../essences/essence_select_editor_spec.rb | 35 ++++++++++++++++ .../essences/essence_text_editor_spec.rb | 41 ++++++++++++++----- 17 files changed, 145 insertions(+), 97 deletions(-) create mode 100644 spec/views/essences/essence_date_editor_spec.rb create mode 100644 spec/views/essences/essence_select_editor_spec.rb diff --git a/app/helpers/alchemy/admin/essences_helper.rb b/app/helpers/alchemy/admin/essences_helper.rb index d67c15c7f6..941c05023a 100644 --- a/app/helpers/alchemy/admin/essences_helper.rb +++ b/app/helpers/alchemy/admin/essences_helper.rb @@ -7,22 +7,8 @@ module EssencesHelper include Alchemy::Admin::ContentsHelper # 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 - Passing options to `render_essence_editor` is deprecated and will be removed from Alchemy 5.0. - Add your static `#{options.keys}` options to the `#{content.name}` content definitions `settings` of `#{content.element&.name}` element. - For dynamic options consider adding your own essence class. - WARN - end - if !html_options.empty? - Alchemy::Deprecation.warn <<~WARN - Passing html_options to `render_essence_editor` is deprecated and will be removed in Alchemy 5.0 without replacement. - WARN - end - render_essence(content, :editor, {for_editor: options}, html_options) + def render_essence_editor(content) + render_essence(content, :editor) end deprecate :render_essence_editor, deprecator: Alchemy::Deprecation @@ -32,16 +18,16 @@ 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 = {}) + # + def render_essence_editor_by_name(element, name) if element.blank? return warning('Element is nil', Alchemy.t(:no_element_given)) end content = element.content_by_name(name) if content.nil? - render_missing_content(element, name, options) + render_missing_content(element, name) else - render_essence_editor(content, options, html_options) + render_essence_editor(content) end end deprecate :render_essence_editor_by_name, deprecator: Alchemy::Deprecation @@ -68,9 +54,9 @@ 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} + # + def render_missing_content(element, name) + render 'alchemy/admin/contents/missing', {element: element, name: name} end deprecate :render_missing_content, deprecator: Alchemy::Deprecation diff --git a/app/helpers/alchemy/elements_block_helper.rb b/app/helpers/alchemy/elements_block_helper.rb index b0df5dde98..eb7636f307 100644 --- a/app/helpers/alchemy/elements_block_helper.rb +++ b/app/helpers/alchemy/elements_block_helper.rb @@ -65,8 +65,8 @@ def essence(name) # 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) + def edit(name) + helpers.render_essence_editor_by_name(element, name.to_s) end deprecate :edit, deprecator: Alchemy::Deprecation end diff --git a/app/views/alchemy/admin/essence_files/edit.html.erb b/app/views/alchemy/admin/essence_files/edit.html.erb index cd96b70516..25fab7e877 100644 --- a/app/views/alchemy/admin/essence_files/edit.html.erb +++ b/app/views/alchemy/admin/essence_files/edit.html.erb @@ -1,4 +1,4 @@ -<% css_classes = @content.settings_value(:css_classes, local_assigns.fetch(:options, {})) %> +<% css_classes = @content.settings[:css_classes] %> <%= alchemy_form_for [:admin, @essence_file] do |f| %> <%= f.input :link_text %> diff --git a/app/views/alchemy/essences/_essence_boolean_editor.html.erb b/app/views/alchemy/essences/_essence_boolean_editor.html.erb index 0c61ffe25a..e767e6c84f 100644 --- a/app/views/alchemy/essences/_essence_boolean_editor.html.erb +++ b/app/views/alchemy/essences/_essence_boolean_editor.html.erb @@ -1,11 +1,6 @@
- <%= check_box_tag content.form_field_name, 1, - content.ingredient.presence || content.settings_value( - :default_value, local_assigns.fetch(:options, {}) - ), - class: local_assigns.fetch(:html_options, {})[:class], - style: local_assigns.fetch(:html_options, {})[:style] %> + <%= check_box_tag content.form_field_name, 1, content.ingredient %> diff --git a/app/views/alchemy/essences/_essence_date_editor.html.erb b/app/views/alchemy/essences/_essence_date_editor.html.erb index b32394161f..bb933a3123 100644 --- a/app/views/alchemy/essences/_essence_date_editor.html.erb +++ b/app/views/alchemy/essences/_essence_date_editor.html.erb @@ -4,7 +4,7 @@ content.essence, :date, { name: content.form_field_name, id: content.form_field_id, - value: content.settings_value(:default_value, local_assigns.fetch(:options, {})) + value: content.ingredient } ) %>