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

- (PanelRenderer) initialize

Returns a new instance of PanelRenderer



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

def initialize
  self.panels = []
end

Instance Attribute Details

- (Array<Hash>) panels

Returns:

  • (Array<Hash>)


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

def panels
  @panels
end

Instance Method Details

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

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.



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

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