Class: Alchemy::ElementEditor
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Alchemy::ElementEditor
- Defined in:
- app/decorators/alchemy/element_editor.rb
Instance Method Summary collapse
-
#css_classes ⇒ Object
CSS classes for the element editor partial.
-
#editable? ⇒ Boolean
Tells us, if we should show the element footer and form inputs.
-
#has_ingredients_defined? ⇒ Boolean
Are any ingredients defined?.
-
#ingredients ⇒ Object
Returns ingredient editor instances for defined ingredients.
-
#respond_to?(*args, **kwargs) ⇒ Boolean
Fixes Rails partial renderer calling to_model on the object which reveals the delegated element instead of this decorator.
- #to_partial_path ⇒ Object
-
#translated_group(group) ⇒ Object
Returns the translated ingredient group for displaying in admin editor group headings.
Instance Method Details
#css_classes ⇒ Object
CSS classes for the element editor partial.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/decorators/alchemy/element_editor.rb', line 52 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 |
#editable? ⇒ Boolean
Tells us, if we should show the element footer and form inputs.
67 68 69 |
# File 'app/decorators/alchemy/element_editor.rb', line 67 def editable? ingredient_definitions.any? || taggable? end |
#has_ingredients_defined? ⇒ Boolean
Are any ingredients defined?
24 25 26 |
# File 'app/decorators/alchemy/element_editor.rb', line 24 def has_ingredients_defined? ingredient_definitions.any? end |
#ingredients ⇒ Object
Returns ingredient editor instances for defined ingredients
Creates ingredient on demand if the ingredient is not yet present on the element
16 17 18 19 20 |
# File 'app/decorators/alchemy/element_editor.rb', line 16 def ingredients ingredient_definitions.map do |ingredient| Alchemy::IngredientEditor.new(find_or_create_ingredient(ingredient)) end end |
#respond_to?(*args, **kwargs) ⇒ Boolean
Fixes Rails partial renderer calling to_model on the object which reveals the delegated element instead of this decorator.
73 74 75 76 77 78 |
# File 'app/decorators/alchemy/element_editor.rb', line 73 def respond_to?(*args, **kwargs) method_name = args.first return false if method_name == :to_model super end |
#to_partial_path ⇒ Object
7 8 9 |
# File 'app/decorators/alchemy/element_editor.rb', line 7 def to_partial_path "alchemy/admin/elements/element" 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
43 44 45 46 47 48 49 |
# File 'app/decorators/alchemy/element_editor.rb', line 43 def translated_group(group) Alchemy.t( group, scope: "element_groups.#{element.name}", default: Alchemy.t("element_groups.#{group}", default: group.humanize) ) end |