Skip to content

Commit

Permalink
Merge pull request #3040 from AlchemyCMS/7.3-deprecate-resource-helpers
Browse files Browse the repository at this point in the history
[7.3] Deprecate resources helpers
  • Loading branch information
tvdeyen authored Sep 18, 2024
2 parents a66156a + dcadaaf commit 115da13
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/views/alchemy/admin/resources/_resource.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% Alchemy::Deprecation.warn "The `alchemy/admin/resources/_resource` partial is deprecated. Please `render 'alchemy/admin/resources/_resource_table'` instead and update it to your needs." %>

<tr class="<%= cycle('even', 'odd') %>">
<% if local_assigns[:icon] %>
<td class="icon"><%= render_icon(local_assigns[:icon], size: "xl") %></td>
Expand Down
6 changes: 4 additions & 2 deletions lib/alchemy/resources_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ def resource_relations_names
# Returns the attribute's column for sorting
#
# If the attribute contains a resource_relation, then the table and column for related model will be returned.
#
# @deprecated
def sortable_resource_header_column(attribute)
if (relation = attribute[:relation])
"#{relation[:model_association].name}_#{relation[:attr_method]}"
else
attribute[:name]
end
end
deprecate sortable_resource_header_column: "Please `render Alchemy::Admin::Resource::Table instead`", deprecator: Alchemy::Deprecation

# Renders the row for a resource record in the resources table.
#
Expand All @@ -156,12 +157,13 @@ def sortable_resource_header_column(attribute)
# </tr>
#
# NOTE: Alchemy gives you a local variable named like your resource
#
# @deprecated
def render_resources(icon: nil)
render partial: resource_name, collection: resources_instance_variable, locals: {icon: icon}
rescue ActionView::MissingTemplate
render partial: "resource", collection: resources_instance_variable, locals: {icon: icon}
end
deprecate render_resources: "Please `render Alchemy::Admin::Resource::Table instead`", deprecator: Alchemy::Deprecation

def resource_has_tags
resource_model.respond_to?(:tag_counts) && resource_model.tag_counts.any?
Expand Down
6 changes: 2 additions & 4 deletions spec/libraries/resources_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

require_relative "../../lib/alchemy/i18n"
require_relative "../../lib/alchemy/resource"
require_relative "../../lib/alchemy/resources_helper"
require "rails_helper"

module Namespace
class MyResource
Expand Down Expand Up @@ -269,7 +267,7 @@ def resource_handler
end
end

describe "#render_resources" do
describe "#render_resources", :silence_deprecations do
it "renders a resource collection" do
expect(controller).to receive(:render).with(collection: [resource_item], partial: "my_resource", locals: {icon: nil})
controller.render_resources
Expand Down

0 comments on commit 115da13

Please sign in to comment.