Class: Alchemy::IngredientEditor
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Alchemy::IngredientEditor
- Defined in:
- app/decorators/alchemy/ingredient_editor.rb
Instance Method Summary collapse
- #css_classes ⇒ Object deprecated Deprecated.
- #data_attributes ⇒ Object deprecated Deprecated.
- #form_field_id(column = "value") ⇒ Object deprecated Deprecated.
- #form_field_name(column = "value") ⇒ Object deprecated Deprecated.
- #format_validation ⇒ Object deprecated Deprecated.
- #has_warnings? ⇒ Boolean deprecated Deprecated.
- #length_validation ⇒ Object deprecated Deprecated.
- #linked? ⇒ Boolean deprecated Deprecated.
- #presence_validation? ⇒ Boolean deprecated Deprecated.
-
#respond_to?(method_name) ⇒ Boolean
Fixes Rails partial renderer calling to_model on the object which reveals the delegated ingredient instead of this decorator.
- #to_partial_path ⇒ Object deprecated Deprecated.
- #translated_role ⇒ Object deprecated Deprecated.
- #validations ⇒ Object deprecated Deprecated.
- #warnings ⇒ Object deprecated Deprecated.
Instance Method Details
#css_classes ⇒ Object
Deprecated.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 39 def css_classes [ "ingredient-editor", partial_name, deprecated? ? "deprecated" : nil, (respond_to?(:level_options) && .any?) ? "with-level-select" : nil, (respond_to?(:size_options) && .many?) ? "with-size-select" : nil, settings[:linkable] ? "linkable" : nil, settings[:anchor] ? "with-anchor" : nil ].compact end |
#data_attributes ⇒ Object
Deprecated.
53 54 55 56 57 58 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 53 def data_attributes { ingredient_id: id, ingredient_role: role } end |
#form_field_id(column = "value") ⇒ Object
Deprecated.
Returns a unique string to be passed to a form field id.
85 86 87 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 85 def form_field_id(column = "value") "element_#{element.id}_ingredient_#{id}_#{column}" end |
#form_field_name(column = "value") ⇒ Object
Deprecated.
Returns a string to be passed to Rails form field tags to ensure it can be used with Rails’ nested attributes.
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 %>
76 77 78 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 76 def form_field_name(column = "value") "element[ingredients_attributes][#{form_field_counter}][#{column}]" end |
#format_validation ⇒ Object
Deprecated.
130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 130 def format_validation format = validations.select { _1.is_a?(Hash) }.find { _1[:format] }&.fetch(:format) return nil unless format # If format is a string or symbol, resolve it from config format_matchers if format.is_a?(String) || format.is_a?(Symbol) Alchemy.config.format_matchers.get(format) else format end end |
#has_warnings? ⇒ Boolean
Deprecated.
99 100 101 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 99 def has_warnings? definition.blank? || deprecated? end |
#length_validation ⇒ Object
Deprecated.
144 145 146 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 144 def length_validation validations.select { _1.is_a?(Hash) }.find { _1[:length] }&.fetch(:length) end |
#linked? ⇒ Boolean
Deprecated.
105 106 107 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 105 def linked? link.try(:present?) end |
#presence_validation? ⇒ Boolean
Deprecated.
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 150 def presence_validation? validations.any? do |validation| case validation when :presence, "presence" true when Hash validation[:presence] == true || validation["presence"] == true else false end end end |
#respond_to?(method_name) ⇒ Boolean
Fixes Rails partial renderer calling to_model on the object which reveals the delegated ingredient instead of this decorator.
92 93 94 95 96 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 92 def respond_to?(method_name) return false if method_name == :to_model super end |
#to_partial_path ⇒ Object
Deprecated.
8 9 10 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 8 def to_partial_path "alchemy/ingredients/#{partial_name}_editor" end |
#translated_role ⇒ Object
Deprecated.
Returns the translated role for displaying in labels
Translate it in your locale yml file:
alchemy:
ingredient_roles:
foo: Bar
Optionally you can scope your ingredient role to an element:
alchemy:
ingredient_roles:
article:
foo: Baz
29 30 31 32 33 34 35 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 29 def translated_role Alchemy.t( role, scope: "ingredient_roles.#{element.name}", default: Alchemy.t("ingredient_roles.#{role}", default: role.humanize) ) end |
#validations ⇒ Object
Deprecated.
124 125 126 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 124 def validations definition.validate end |
#warnings ⇒ Object
Deprecated.
111 112 113 114 115 116 117 118 119 120 |
# File 'app/decorators/alchemy/ingredient_editor.rb', line 111 def warnings return unless has_warnings? if definition.blank? Logger.warn("ingredient '#{role}' is missing its definition! Please check your element definitions.") Alchemy.t(:ingredient_definition_missing) else definition.deprecation_notice(element_name: element&.name) end end |