Class: TinyAdmin::Views::Components::Widgets

Inherits:
BasicComponent
  • Object
show all
Defined in:
lib/tiny_admin/views/components/widgets.rb

Instance Method Summary collapse

Methods inherited from BasicComponent

#update_attributes

Constructor Details

#initialize(widgets) ⇒ Widgets

Returns a new instance of Widgets.



7
8
9
# File 'lib/tiny_admin/views/components/widgets.rb', line 7

def initialize(widgets)
  @widgets = widgets
end

Instance Method Details

#view_templateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tiny_admin/views/components/widgets.rb', line 11

def view_template
  return if @widgets.nil? || @widgets.empty?

  div(class: 'container widgets') {
    @widgets.each_slice(2).each do |row|
      div(class: 'row') {
        row.each do |widget|
          next unless widget < Phlex::HTML

          div(class: 'col') {
            div(class: 'card') {
              div(class: 'card-body') {
                render widget.new
              }
            }
          }
        end
      }
    end
  }
end