Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate element editors #1643

Merged
merged 2 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/helpers/alchemy/admin/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ module ElementsHelper
# @note If the partial is not found
# <tt>alchemy/elements/_editor_not_found.html.erb</tt> 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
Expand Down
8 changes: 6 additions & 2 deletions app/helpers/alchemy/admin/essences_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,14 +24,15 @@ 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
#
# 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))
Expand All @@ -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.
#
Expand All @@ -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 = {})
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/alchemy/elements_block_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion app/views/alchemy/admin/elements/_element.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
</div>

<% if element.taggable? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions spec/dummy/app/views/alchemy/elements/_bild_editor.html.erb

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions spec/dummy/app/views/alchemy/elements/_header_editor.html.erb

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions spec/dummy/app/views/alchemy/elements/_news_editor.html.erb

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions spec/dummy/app/views/alchemy/elements/_slide_editor.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions spec/dummy/app/views/alchemy/elements/_slider_editor.html.erb

This file was deleted.

3 changes: 0 additions & 3 deletions spec/dummy/app/views/alchemy/elements/_text_editor.html.erb

This file was deleted.

4 changes: 3 additions & 1 deletion spec/helpers/alchemy/admin/elements_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down