Class: Alchemy::Ingredients::BaseEditor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ingredient, html_options: {}) ⇒ BaseEditor

Returns a new instance of BaseEditor.

Raises:

  • (ArgumentError)


28
29
30
31
32
33
# File 'app/components/alchemy/ingredients/base_editor.rb', line 28

def initialize(ingredient, html_options: {})
  raise ArgumentError, "Ingredient missing!" if ingredient.nil?

  @ingredient = ingredient
  @html_options = html_options
end

Instance Attribute Details

#html_optionsObject (readonly)

Returns the value of attribute html_options.



26
27
28
# File 'app/components/alchemy/ingredients/base_editor.rb', line 26

def html_options
  @html_options
end

#ingredientObject (readonly)

Returns the value of attribute ingredient.



26
27
28
# File 'app/components/alchemy/ingredients/base_editor.rb', line 26

def ingredient
  @ingredient
end

Instance Method Details

#callObject



35
36
37
38
39
40
41
# File 'app/components/alchemy/ingredients/base_editor.rb', line 35

def call
  tag.div(class: css_classes, data: data_attributes, id: dom_id(ingredient)) do
    concat ingredient_id_field
    concat ingredient_label
    concat input_field
  end
end

#form_field_id(column = "value") ⇒ Object

Returns a unique string to be passed to a form field id.

Parameters:

  • column (String) (defaults to: "value")

    A Ingredient column_name. Default is ‘value’



65
66
67
# File 'app/components/alchemy/ingredients/base_editor.rb', line 65

def form_field_id(column = "value")
  "element_#{element.id}_ingredient_#{ingredient.id}_#{column}"
end

#form_field_name(column = "value") ⇒ Object

Returns a string to be passed to Rails form field helpers.

Example:

<%= text_field_tag text_editor.form_field_name, text_editor.value %>

Options:

You can pass an Ingredient column_name. Default is ‘value’

Example:

<%= text_field_tag text_editor.form_field_name(:link), text_editor.value %>


57
58
59
# File 'app/components/alchemy/ingredients/base_editor.rb', line 57

def form_field_name(column = "value")
  "element[ingredients_attributes][#{form_field_counter}][#{column}]"
end