Class: Maglev::Editor::Settings::BaseComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Maglev::Editor::Settings::BaseComponent
show all
- Defined in:
- app/components/maglev/editor/settings/base_component.rb
Direct Known Subclasses
Checkbox::CheckboxComponent, CollectionItem::CollectionItemComponent, Color::ColorComponent, Divider::DividerComponent, Hint::HintComponent, Icon::IconComponent, Image::ImageComponent, Link::LinkComponent, Select::SelectComponent, Text::RichtextComponent, Text::TextComponent, Text::TextareaComponent
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(definition:, value:, paths:, scope:) ⇒ BaseComponent
Returns a new instance of BaseComponent.
9
10
11
12
13
14
15
16
17
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 9
def initialize(definition:, value:, paths:, scope:)
@definition = definition
@value = value
@paths = paths
@input_scope = scope[:input]
@i18n_scope = scope[:i18n]
after_initialize
end
|
Instance Attribute Details
#definition ⇒ Object
Returns the value of attribute definition.
7
8
9
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 7
def definition
@definition
end
|
#i18n_scope ⇒ Object
Returns the value of attribute i18n_scope.
7
8
9
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 7
def i18n_scope
@i18n_scope
end
|
Returns the value of attribute input_scope.
7
8
9
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 7
def input_scope
@input_scope
end
|
#paths ⇒ Object
Returns the value of attribute paths.
7
8
9
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 7
def paths
@paths
end
|
#value ⇒ Object
Returns the value of attribute value.
7
8
9
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 7
def value
@value
end
|
Instance Method Details
#after_initialize ⇒ Object
49
50
51
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 49
def after_initialize
end
|
#call ⇒ Object
39
40
41
42
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 39
def call
content_tag(:div, "Unknown setting type: #{definition.type} / #{definition.options}",
class: 'bg-red-500 text-white p-4 rounded-md')
end
|
#default_placeholder ⇒ Object
35
36
37
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 35
def default_placeholder
::I18n.t("maglev.editor.settings.#{definition.type}.placeholder")
end
|
#fetch_path(name, context = {}) ⇒ Object
44
45
46
47
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 44
def fetch_path(name, context = {})
path_or_proc = paths.fetch(name, nil)
path_or_proc.is_a?(Proc) ? path_or_proc.call(definition, context) : path_or_proc
end
|
19
20
21
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 19
def input_name
"#{input_scope}[#{definition.id}]"
end
|
23
24
25
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 23
def input_source
input_name.parameterize.underscore
end
|
#label ⇒ Object
27
28
29
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 27
def label
::I18n.t("#{i18n_scope}.settings.#{definition.id}", default: definition.label)
end
|
#placeholder ⇒ Object
31
32
33
|
# File 'app/components/maglev/editor/settings/base_component.rb', line 31
def placeholder
::I18n.t("#{i18n_scope}.settings.#{definition.id}_placeholder", default: default_placeholder)
end
|