Class: Voom::Presenters::DSL::Components::Lists::Line

Inherits:
EventBase
  • Object
show all
Extended by:
Gem::Deprecate
Includes:
Mixins::Dialogs, Mixins::Tooltips
Defined in:
lib/voom/presenters/dsl/components/lists/line.rb

Direct Known Subclasses

Header

Constant Summary collapse

CHECKBOX_ATTRIBUTES =
%i[name value checked dirtyable value off_value].freeze

Instance Attribute Summary collapse

Attributes inherited from EventBase

#event_parent_id

Attributes included from Mixins::Event

#events

Attributes inherited from Base

#attributes, #css_class, #draggable, #drop_zone, #id, #tag, #type

Instance Method Summary collapse

Methods included from Mixins::Dialogs

#dialog

Methods included from Mixins::Tooltips

#tooltip

Methods included from Mixins::Event

#event

Methods inherited from Base

#expand!

Methods included from Pluggable

#include_plugins, #plugin, #plugin_module

Methods included from Mixins::YieldTo

#yield_to

Methods included from Serializer

#to_hash

Methods included from Lockable

#locked?

Constructor Details

#initialize(**attribs_, &block) ⇒ Line

Returns a new instance of Line.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 15

def initialize(**attribs_, &block)
  super(type: :line, **attribs_, &block)
  @selected = attribs.delete(:selected) {false}
  @selectable = attribs.delete(:selectable) {false}
  self.text(attribs.delete(:text), attribs) if attribs[:text]
  self.subtitle(attribs.delete(:subtitle)) if attribs[:subtitle]
  self.info(attribs.delete(:info)) if attribs[:info]
  self.body(attribs.delete(:body)) if attribs[:body]
  self.avatar(attribs.delete(:avatar)) if attribs.key?(:avatar)
  self.icon(attribs.delete(:icon)) if attribs.key?(:icon)

  if @selectable
    self.checkbox(attribs.slice(*CHECKBOX_ATTRIBUTES))
  elsif attribs.key?(:checkbox)
    self.checkbox(attribs.delete(:checkbox))
  end
  @components = []
  @actions = []
  expand!
end

Instance Attribute Details

#componentsObject

Returns the value of attribute components.



13
14
15
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 13

def components
  @components
end

#selectableObject

Returns the value of attribute selectable.



13
14
15
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 13

def selectable
  @selectable
end

#selectedObject

Returns the value of attribute selected.



13
14
15
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 13

def selected
  @selected
end

Instance Method Details

#actions(**attribs, &block) ⇒ Object Also known as: action



94
95
96
97
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 94

def actions(**attribs, &block)
  return @actions if locked?
  Lists::Actions.new(@actions, parent: self, **attribs, &block)
end

#avatar(avatar = nil, **attribs, &block) ⇒ Object



57
58
59
60
61
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 57

def avatar(avatar = nil, **attribs, &block)
  return @avatar if locked?
  @avatar = Avatar.new(parent: self, avatar: avatar,
                       **attribs, &block)
end

#body(*text, **attribs, &block) ⇒ Object



52
53
54
55
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 52

def body(*text, **attribs, &block)
  return @body if locked?
  @body = Components::Typography.new(parent: self, type: :body, text: text, **attribs, &block)
end

#checkbox(**attributes, &block) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 69

def checkbox(**attributes, &block)
  return @checkbox if locked?

  # Append [] if the list is selectable and the checkbox's name
  # doesn't already include brackets:
  field_name = attributes.delete(:name).to_s
  field_name += '[]' if @selectable && !field_name.include?('[')

  @checkbox = Components::Checkbox.new(parent: self,
                                       name: field_name,
                                       **attributes,
                                       &block)
end

#hidden_field(**attributes, &block) ⇒ Object



83
84
85
86
87
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 83

def hidden_field(**attributes, &block)
  return @hidden_field if locked?

  @hidden_field = Components::HiddenField.new(parent: self, **attributes, &block)
end

#icon(icon = nil, **attribs, &block) ⇒ Object



63
64
65
66
67
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 63

def icon(icon=nil, **attribs, &block)
  return @icon if locked?
  @icon = Icon.new(parent: self, icon: icon,
                   **attribs, &block)
end

#info(*text, **attribs, &block) ⇒ Object



47
48
49
50
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 47

def info(*text, **attribs, &block)
  return @info if locked?
  @info = Components::Typography.new(parent: self, type: :info, text: text, **attribs, &block)
end


89
90
91
92
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 89

def menu(**attributes, &block)
  return @menu if locked?
  @menu = Components::Menu.new(parent: self, **attributes, &block)
end

#subtitle(*text, **attribs, &block) ⇒ Object



42
43
44
45
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 42

def subtitle(*text, **attribs, &block)
  return @subtitle if locked?
  @subtitle = Components::Typography.new(parent: self, type: :subtitle, text: text, **attribs, &block)
end

#text(*text, **attribs, &block) ⇒ Object Also known as: title



36
37
38
39
# File 'lib/voom/presenters/dsl/components/lists/line.rb', line 36

def text(*text, **attribs, &block)
  return @text if locked?
  @text = Components::Typography.new(parent: self, type: :text, text: text, **attribs, &block)
end