Skip to content

Commit

Permalink
Remove deprecated render element editor helpers
Browse files Browse the repository at this point in the history
Elements do not need an editor partial anymore.
  • Loading branch information
tvdeyen committed Oct 22, 2019
1 parent 3cf522a commit dcc2544
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 177 deletions.
9 changes: 0 additions & 9 deletions app/controllers/alchemy/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ module Alchemy
#
# Disabling the page caching is strongly recommended!
#
# The editor view for your element should have this layout:
#
# <%= element_editor_for(element) do |el| %>
# <%= el.edit :mail_from %>
# <%= el.edit :mail_to %>
# <%= el.edit :subject %>
# <%= el.edit :success_page %>
# <% end %>
#
# Please have a look at the +alchemy/config/config.yml+ file for further Message settings.
#
class MessagesController < Alchemy::BaseController
Expand Down
67 changes: 0 additions & 67 deletions app/helpers/alchemy/admin/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,9 @@
module Alchemy
module Admin
module ElementsHelper
include Alchemy::ElementsBlockHelper
include Alchemy::Admin::BaseHelper
include Alchemy::Admin::ContentsHelper
include Alchemy::Admin::EssencesHelper

# Renders a {Alchemy::Element} editor partial.
#
# A element editor partial is the form presented to the content author in page edit mode.
#
# The partial is located in <tt>app/views/alchemy/elements</tt>.
#
# == Partial naming
#
# The partials have to be named after the name of the element as defined in the <tt>elements.yml</tt> file and has to be suffixed with <tt>_editor</tt>.
#
# === Example
#
# Given a headline element
#
# # elements.yml
# - name: headline
# contents:
# - name: text
# type: EssenceText
#
# Then your element editor partial has to be named:
#
# app/views/alchemy/elements/_headline_editor.html.{erb|haml|slim}
#
# === Element partials generator
#
# You can use this handy generator to let Alchemy generate the partials for you:
#
# $ rails generate alchemy:elements --skip
#
# == Usage
#
# <%= render_editor(Alchemy::Element.published.named(:headline).first) %>
#
# @param [Alchemy::Element] element
# The element you want to render the editor for
#
# @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
warning(%(
Element editor partial not found for #{element.name}.\n
#{e}
))
render "alchemy/elements/editor_not_found", {
name: element.name,
error: "Element editor partial not found.<br>Use <code>rails generate alchemy:elements</code> to generate it."
}
end

# Returns an elements array for select helper.
#
# @param [Array] elements definitions
Expand Down
29 changes: 0 additions & 29 deletions app/helpers/alchemy/elements_block_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@ def essence(name)
end
end

# Block-level helper class for element editors.
# @deprecated
class ElementEditorHelper < BlockHelper
def edit(name)
helpers.render_essence_editor_by_name(element, name.to_s)
end
deprecate :edit, deprecator: Alchemy::Deprecation
end

# Block-level helper for element views. Constructs a DOM element wrapping
# your content element and provides a block helper object you can use for
# concise access to Alchemy's various helpers.
Expand Down Expand Up @@ -140,25 +131,5 @@ def element_view_for(element, options = {})
# that's it!
output
end

# Block-level helper for element editors. Provides a block helper object
# you can use for concise access to Alchemy's various helpers.
#
# === Example:
#
# <%= element_editor_for(element) do |el| %>
# <%= el.edit :title %>
# <%= el.edit :body %>
# <%= el.edit :target_url %>
# <% end %>
#
# @param [Alchemy::Element] element
# The element to display.
#
def element_editor_for(element)
capture do
yield ElementEditorHelper.new(self, element: element) if block_given?
end
end
end
end
6 changes: 1 addition & 5 deletions app/views/alchemy/admin/elements/_element.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
<% element.definition[:warning].tap do |warning| %>
<%= render_message(:warning, sanitize(warning)) if warning %>
<% end %>
<% if lookup_context.exists?("#{element.name}_editor", ["alchemy/elements"], true) %>
<%= render_editor(element) %>
<% else %>
<%= render element.contents.map { |content| Alchemy::ContentEditor.new(content) } %>
<% end %>
<%= render element.contents.map { |content| Alchemy::ContentEditor.new(content) } %>
</div>

<% if element.taggable? %>
Expand Down
4 changes: 0 additions & 4 deletions app/views/alchemy/elements/_editor_not_found.html.erb

This file was deleted.

34 changes: 0 additions & 34 deletions spec/helpers/alchemy/admin/elements_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,6 @@

module Alchemy
describe Admin::ElementsHelper do
let(:page) { build_stubbed(:alchemy_page, :public) }
let(:element) { build_stubbed(:alchemy_element, page: page) }

describe "#render_editor" do
subject { render_editor(element) }

context 'with nil element' do
let(:element) { nil }

it { is_expected.to be_nil }
end

context 'with element record given' do
let(:element) do
create(:alchemy_element, :with_contents, name: 'headline')
end

it "renders the element's editor partial" do
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
let(:element) { build_stubbed(:alchemy_element, name: 'not_present') }

it "renders the editor not found partial" do
is_expected.to have_selector('div.warning')
is_expected.to have_content('Element editor partial not found')
end
end
end
end

describe "#elements_for_select" do
context "passing element instances" do
let(:element_objects) do
Expand Down
29 changes: 0 additions & 29 deletions spec/helpers/alchemy/elements_block_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ module Alchemy
end
end

describe '#element_editor_for' do
it "should yield an instance of ElementEditorHelper" do
expect { |b| element_editor_for(element, &b) }.
to yield_with_args(ElementsBlockHelper::ElementEditorHelper)
end

it "should not add any extra elements" do
expect(element_editor_for(element) do
'view'
end).to eq('view')
end
end

describe 'ElementsBlockHelper::ElementViewHelper' do
let(:scope) { double }
subject { ElementsBlockHelper::ElementViewHelper.new(scope, element: element) }
Expand Down Expand Up @@ -126,21 +113,5 @@ module Alchemy
end
end
end

describe 'ElementsBlockHelper::ElementEditorHelper' do
let(:scope) { double }
subject { ElementsBlockHelper::ElementEditorHelper.new(scope, element: element) }

it 'should have a reference to the specified element' do
subject.element == element
end

describe '#edit' do
it "should delegate to the render_essence_editor_by_name helper" do
expect(scope).to receive(:render_essence_editor_by_name).with(element, "title")
subject.edit(:title)
end
end
end
end
end

0 comments on commit dcc2544

Please sign in to comment.