Class: Nexmo::OAS::Renderer::Presenters::ContentSwitcher

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo/oas/renderer/presenters/content_switcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format:, label: nil, theme_light:, force_type: nil) ⇒ ContentSwitcher

Returns a new instance of ContentSwitcher.



10
11
12
13
14
15
16
# File 'lib/nexmo/oas/renderer/presenters/content_switcher.rb', line 10

def initialize(format:, label: nil, theme_light:, force_type: nil)
  @format = format
  @panels = []
  @label = label
  @force_type = force_type
  @theme_light = theme_light
end

Instance Attribute Details

#panelsObject (readonly)

Returns the value of attribute panels.



8
9
10
# File 'lib/nexmo/oas/renderer/presenters/content_switcher.rb', line 8

def panels
  @panels
end

Instance Method Details

#add_content(title:, content:, tab_id:, active:) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/nexmo/oas/renderer/presenters/content_switcher.rb', line 18

def add_content(title:, content:, tab_id:, active:)
  @panels.push({
                   'title' => title,
                   'content' => content,
                   'x-tab-id' => tab_id,
                   'active' => active,
               })
end

#idObject



42
43
44
# File 'lib/nexmo/oas/renderer/presenters/content_switcher.rb', line 42

def id
  @id ||= "s-#{SecureRandom.hex}"
end

#renderObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nexmo/oas/renderer/presenters/content_switcher.rb', line 27

def render
  type = 'tabs'
  type = 'dropdown' if @panels.length >= 8

  type = @force_type if @force_type

  [:"open_api/content_switcher/_#{type}", locals: {
      panels: @panels,
      format: @format,
      label: @label,
      switcher: self,
      theme_light: @theme_light,
  }]
end