Class: Alchemy::Admin::IngredientEditor

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/alchemy/admin/ingredient_editor.rb

Overview

Adapter component for rendering ingredient editors.

Handles both deprecated partial-based editors and component based editors. Use with_collection for efficient batch rendering of ingredients.

Examples:

Component based editors (no element_form needed)

<%= render Alchemy::Admin::IngredientEditor.with_collection(
  element.ungrouped_ingredients
) %>

With element_form for deprecated partials

<%= render Alchemy::Admin::IngredientEditor.with_collection(
  element.ungrouped_ingredients,
  element_form: f
) %>

Instance Method Summary collapse

Constructor Details

#initialize(ingredient:, element_form: nil) ⇒ IngredientEditor

Returns a new instance of IngredientEditor.

Parameters:

  • ingredient (Alchemy::Ingredient)

    The ingredient to render an editor for

  • element_form (ActionView::Helpers::FormBuilder, nil) (defaults to: nil)

    Optional form builder for deprecated partials



26
27
28
29
# File 'app/components/alchemy/admin/ingredient_editor.rb', line 26

def initialize(ingredient:, element_form: nil)
  @ingredient = ingredient
  @element_form = element_form
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/alchemy/admin/ingredient_editor.rb', line 31

def call
  if has_editor_partial?
    Alchemy::Deprecation.warn "      Ingredient editor partials are deprecated!\n      Please create a `\#{@ingredient.class.name}Editor` class inheriting from `Alchemy::Ingredients::BaseEditor`.\n    WARN\n    Alchemy::Deprecation.silence do\n      render partial: \"alchemy/ingredients/\#{@ingredient.partial_name}_editor\",\n        locals: {element_form: @element_form},\n        object: Alchemy::IngredientEditor.new(@ingredient)\n    end\n  else\n    render @ingredient.as_editor_component\n  end\nend\n"