Class: StimulusPlumbers::Components::ActionList::Renderer

Inherits:
Plumber::Base
  • Object
show all
Defined in:
lib/stimulus_plumbers/components/action_list/renderer.rb

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Instance Method Summary collapse

Methods inherited from Plumber::Base

#initialize, #theme

Methods included from Plumber::HtmlOptions

#merge_html_options, #merge_string_option, #normalize_part

Constructor Details

This class inherits a constructor from StimulusPlumbers::Components::Plumber::Base

Instance Method Details

#item(content = nil, url: nil, external: false, active: false, **kwargs, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/stimulus_plumbers/components/action_list/renderer.rb', line 27

def item(content = nil, url: nil, external: false, active: false, **kwargs, &block)
  content      = template.capture(&block) if block_given?
  html_options = merge_html_options(
    { classes: theme.resolve(:action_list_item, active: active).fetch(:classes, "") },
    kwargs
  )

  inner = if url
            html_options[:target] = "_blank" if external
            template.(:a, content, href: url, **html_options)
          else
            html_options[:type] ||= "button"
            template.(:button, content, **html_options)
          end

  template.(:li, inner)
end

#list(**kwargs, &block) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/stimulus_plumbers/components/action_list/renderer.rb', line 7

def list(**kwargs, &block)
  html_options = merge_html_options(
    { classes: theme.resolve(:action_list).fetch(:classes, "") },
    kwargs
  )
  template.(:div, template.capture(&block), **html_options)
end

#section(title: nil, **kwargs, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/stimulus_plumbers/components/action_list/renderer.rb', line 15

def section(title: nil, **kwargs, &block)
  html_options = merge_html_options(kwargs)
  template.(:div, **html_options) do
    template.safe_join(
      [
        (template.(:p, title) if title.present?),
        template.(:ul, template.capture(&block))
      ].compact
    )
  end
end