Class: Alchemy::ElementEditor
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Alchemy::ElementEditor
- Defined in:
- app/decorators/alchemy/element_editor.rb
Instance Method Summary collapse
-
#contents ⇒ Object
Returns content editor instances for defined contents.
-
#css_classes ⇒ Object
CSS classes for the element editor partial.
-
#deprecation_notice ⇒ Object
Returns a deprecation notice for elements marked deprecated.
-
#editable? ⇒ Boolean
Tells us, if we should show the element footer and form inputs.
-
#respond_to?(method_name) ⇒ Boolean
Fixes Rails partial renderer calling to_model on the object which reveals the delegated element instead of this decorator.
- #to_partial_path ⇒ Object
Instance Method Details
#contents ⇒ Object
Returns content editor instances for defined contents
Creates contents on demand if the content is not yet present on the element
16 17 18 19 20 |
# File 'app/decorators/alchemy/element_editor.rb', line 16 def contents element.definition.fetch(:contents, []).map do |content| Alchemy::ContentEditor.new(find_or_create_content(content[:name])) end end |
#css_classes ⇒ Object
CSS classes for the element editor partial.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/decorators/alchemy/element_editor.rb', line 23 def css_classes [ "element-editor", content_definitions.present? ? "with-contents" : "without-contents", 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? ? "visible" : "hidden", ].join(" ") end |
#deprecation_notice ⇒ Object
Returns a deprecation notice for elements marked deprecated
You can either use localizations or pass a String as notice in the element definition.
Custom deprecation notices
Use general element deprecation notice
- name: old_element
deprecated: true
Add a translation to your locale file for a per element notice.
en:
alchemy:
element_deprecation_notices:
old_element: Foo baz widget is deprecated
or use the global translation that apply to all deprecated elements.
en:
alchemy:
element_deprecation_notice: Foo baz widget is deprecated
or pass string as deprecation notice.
- name: old_element
deprecated: This element will be removed soon.
82 83 84 85 86 87 88 89 90 91 |
# File 'app/decorators/alchemy/element_editor.rb', line 82 def deprecation_notice case definition["deprecated"] when String definition["deprecated"] when TrueClass Alchemy.t(name, scope: :element_deprecation_notices, default: Alchemy.t(:element_deprecated)) end end |
#editable? ⇒ Boolean
Tells us, if we should show the element footer and form inputs.
38 39 40 41 42 |
# File 'app/decorators/alchemy/element_editor.rb', line 38 def editable? return false if folded? content_definitions.present? || taggable? end |
#respond_to?(method_name) ⇒ Boolean
Fixes Rails partial renderer calling to_model on the object which reveals the delegated element instead of this decorator.
46 47 48 49 50 |
# File 'app/decorators/alchemy/element_editor.rb', line 46 def respond_to?(method_name) 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 |