Class: Alchemy::Admin::ElementEditor
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Alchemy::Admin::ElementEditor
- Defined in:
- app/components/alchemy/admin/element_editor.rb
Instance Attribute Summary collapse
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#parent_element ⇒ Object
readonly
Returns the value of attribute parent_element.
Instance Method Summary collapse
-
#css_classes ⇒ Object
CSS classes for the element editor.
- #display_name ⇒ Object
-
#editable? ⇒ Boolean
Tells us, if we should show the element footer and form inputs.
- #filter_text ⇒ Object
-
#grouped_ingredients ⇒ Hash<String, Array<Alchemy::Ingredient>>
Returns ingredients grouped by their group name.
-
#has_ingredients_defined? ⇒ Boolean
Are any ingredients defined?.
-
#ingredients ⇒ Object
Returns ingredient instances for defined ingredients.
-
#initialize(element:, created: false, parent_element: nil) ⇒ ElementEditor
constructor
A new instance of ElementEditor.
-
#translated_group(group) ⇒ Object
Returns the translated ingredient group for displaying in admin editor group headings.
-
#ungrouped_ingredients ⇒ Object
Returns ingredients that are not part of any group.
Constructor Details
#initialize(element:, created: false, parent_element: nil) ⇒ ElementEditor
Returns a new instance of ElementEditor.
16 17 18 19 20 |
# File 'app/components/alchemy/admin/element_editor.rb', line 16 def initialize(element:, created: false, parent_element: nil) @element = element @created = created @parent_element = parent_element end |
Instance Attribute Details
#created ⇒ Object (readonly)
Returns the value of attribute created.
8 9 10 |
# File 'app/components/alchemy/admin/element_editor.rb', line 8 def created @created end |
#element ⇒ Object (readonly)
Returns the value of attribute element.
8 9 10 |
# File 'app/components/alchemy/admin/element_editor.rb', line 8 def element @element end |
#parent_element ⇒ Object (readonly)
Returns the value of attribute parent_element.
8 9 10 |
# File 'app/components/alchemy/admin/element_editor.rb', line 8 def parent_element @parent_element end |
Instance Method Details
#css_classes ⇒ Object
CSS classes for the element editor.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/components/alchemy/admin/element_editor.rb', line 23 def css_classes [ "element-editor", ingredient_definitions.present? ? "with-ingredients" : "without-ingredients", nestable_elements.any? ? "nestable" : "not-nestable", taggable? ? "taggable" : "not-taggable", folded? ? "folded" : "expanded", compact? ? "compact" : nil, deprecated? ? "deprecated" : nil, fixed? ? "is-fixed" : "not-fixed", public? ? nil : "element-hidden" ] end |
#display_name ⇒ Object
94 95 96 97 98 |
# File 'app/components/alchemy/admin/element_editor.rb', line 94 def display_name parent_element ? "#{parent_element.display_name} > #{element.display_name}" : element.display_name end |
#editable? ⇒ Boolean
Tells us, if we should show the element footer and form inputs.
38 39 40 |
# File 'app/components/alchemy/admin/element_editor.rb', line 38 def editable? ingredient_definitions.any? || taggable? end |
#filter_text ⇒ Object
100 101 102 |
# File 'app/components/alchemy/admin/element_editor.rb', line 100 def filter_text [display_name, element.preview_text].compact_blank.join(" ") end |
#grouped_ingredients ⇒ Hash<String, Array<Alchemy::Ingredient>>
Returns ingredients grouped by their group name
67 68 69 |
# File 'app/components/alchemy/admin/element_editor.rb', line 67 def grouped_ingredients ingredients.select { _1.definition.group }.group_by { _1.definition.group } end |
#has_ingredients_defined? ⇒ Boolean
Are any ingredients defined?
44 45 46 |
# File 'app/components/alchemy/admin/element_editor.rb', line 44 def has_ingredients_defined? ingredient_definitions.any? end |
#ingredients ⇒ Object
Returns ingredient instances for defined ingredients
Creates ingredient on demand if the ingredient is not yet present on the element
53 54 55 56 57 |
# File 'app/components/alchemy/admin/element_editor.rb', line 53 def ingredients ingredient_definitions.map do |ingredient| find_or_create_ingredient(ingredient) end end |
#translated_group(group) ⇒ Object
Returns the translated ingredient group for displaying in admin editor group headings
Translate it in your locale yml file:
alchemy:
element_groups:
foo: Bar
Optionally you can scope your ingredient role to an element:
alchemy:
element_groups:
article:
foo: Baz
86 87 88 89 90 91 92 |
# File 'app/components/alchemy/admin/element_editor.rb', line 86 def translated_group(group) Alchemy.t( group, scope: "element_groups.#{element.name}", default: Alchemy.t("element_groups.#{group}", default: group.humanize) ) end |
#ungrouped_ingredients ⇒ Object
Returns ingredients that are not part of any group
60 61 62 |
# File 'app/components/alchemy/admin/element_editor.rb', line 60 def ungrouped_ingredients ingredients.reject { _1.definition.group } end |