Class: JqrHelpers::Helpers::PanelRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/jqr-helpers/helpers.rb

Overview

A renderer used for tabs, accordions, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePanelRenderer

Returns a new instance of PanelRenderer.



13
14
15
# File 'lib/jqr-helpers/helpers.rb', line 13

def initialize
  self.panels = []
end

Instance Attribute Details

#panelsArray<Hash>

Returns:

  • (Array<Hash>)


11
12
13
# File 'lib/jqr-helpers/helpers.rb', line 11

def panels
  @panels
end

Instance Method Details

#panel(title, url_or_options = {}, options = {}, &block) ⇒ Object

Render a panel in the parent container. The panel must have either a URL or a block containing content.

Parameters:

  • title (String)
  • url_or_options (String|Hash) (defaults to: {})

    If a URL is given, it will be here and the options will be the next parameter. If a block is given, this will be the option hash. Options will be passed as is into the HTML <li> tag.

  • options (Hash) (defaults to: {})

    the options if a URL is given.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jqr-helpers/helpers.rb', line 25

def panel(title, url_or_options={}, options={}, &block)
  if url_or_options.is_a?(String)
    url = url_or_options
    content = nil
    id = nil
  else
    options = url_or_options
    content = block
    id = Helpers._random_string
    url = '#' + id
  end
  options.merge!(:id => id)
  panels << {
    :title => title,
    :url => url,
    :options => options,
    :content => content
  }
  nil # suppress output
end