Class: Bootstrap3Helper::Panel

Inherits:
Component show all
Defined in:
lib/bootstrap3_helper/panel.rb

Overview

Used to rapidly build Bootstrap Panel Components.

Instance Method Summary collapse

Methods inherited from Component

#concat, #config, #content_tag, #parse_arguments, #parse_context_or_options, #parse_tag_or_options, #uuid

Constructor Details

#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ Panel

Creates a new Panel object.

Parameters:

  • template (ActionView)
    • Template in which your are binding too.

  • context_or_options (NilClass|String|Symbol|Hash) (defaults to: nil)
    • Bootstrap class context, or options hash.

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

Options Hash (opts):

  • :id (String)
    • The ID of the element

  • :class (String)
    • Custom class for the component.

  • :data (Hash)
    • Any data attributes for the element.

  • :config_type (Symbol)
    • Used to change config from Panel to Accordion.



17
18
19
20
21
22
23
24
25
26
# File 'lib/bootstrap3_helper/panel.rb', line 17

def initialize(template, context_or_options = nil, opts = {}, &block)
  super(template)
  @context, args = parse_context_or_options(context_or_options, opts)

  @id          = args.fetch(:id,          '')
  @class       = args.fetch(:class,       '')
  @data        = args.fetch(:data,        nil)
  @config_type = args.fetch(:config_type, :panels)
  @content     = block || proc { '' }
end

Instance Method Details

#body(tag_or_options = nil, opts = {}, &block) ⇒ String

Used to generate the body component for the panel.

Parameters:

  • tag_or_options (Symbol|String|Hash|NilClass) (defaults to: nil)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :id (String)
  • :class (String)
  • :data (Hash)
  • :aria (Hash)

Returns:

  • (String)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/bootstrap3_helper/panel.rb', line 94

def body(tag_or_options = nil, opts = {}, &block)
  tag, args = parse_tag_or_options(tag_or_options, opts)

  id    = args.fetch(:id,    nil)
  klass = args.fetch(:class, '')
  data  = args.fetch(:data,  {})
  aria  = args.fetch(:aria,  {})

  (
    tag || config({ @config_type => :body }, :div),
    id:    id,
    class: "panel-body #{klass}",
    data:  data,
    aria:  aria,
    &block
  )
end

Used to generate the footer component for the panel.

Parameters:

  • tag_or_options (Symbol|String|Hash|NilClass) (defaults to: nil)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :id (String)
  • :class (String)
  • :data (Hash)
  • :aria (Hash)

Returns:

  • (String)


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/bootstrap3_helper/panel.rb', line 122

def footer(tag_or_options = nil, opts = {}, &block)
  tag, args = parse_tag_or_options(tag_or_options, opts)

  id    = args.fetch(:id,    nil)
  klass = args.fetch(:class, '')
  data  = args.fetch(:data,  {})
  aria  = args.fetch(:aria,  {})

  (
    tag || config({ @config_type => :footer }, :div),
    id:    id,
    class: "panel-footer #{klass}",
    data:  data,
    aria:  aria,
    &block
  )
end

#header(tag_or_options = nil, opts = {}, &block) ⇒ String

Used to generate the header component for the panel.

Parameters:

  • tag_or_options (Symbol|String|Hash|NilClass) (defaults to: nil)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :id (String)
  • :class (String)
  • :data (Hash)
  • :aria (Hash)

Returns:

  • (String)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bootstrap3_helper/panel.rb', line 38

def header(tag_or_options = nil, opts = {}, &block)
  tag, args = parse_tag_or_options(tag_or_options, opts)

  id    = args.fetch(:id,    nil)
  klass = args.fetch(:class, '')
  data  = args.fetch(:data,  {})
  aria  = args.fetch(:aria,  {})

  (
    tag || config({ @config_type => :header }, :div),
    id:    id,
    class: "panel-heading #{klass}",
    data:  data,
    aria:  aria,
    &block
  )
end

#title(tag_or_options = nil, opts = {}, &block) ⇒ String

Builds a title component for the panel.

Parameters:

  • tag_or_options (Symbol|String|Hash|NilClass) (defaults to: nil)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :id (String)
  • :class (String)
  • :data (Hash)
  • :aria (Hash)

Returns:

  • (String)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bootstrap3_helper/panel.rb', line 66

def title(tag_or_options = nil, opts = {}, &block)
  tag, args = parse_tag_or_options(tag_or_options, opts)

  id    = args.fetch(:id,    nil)
  klass = args.fetch(:class, '')
  data  = args.fetch(:data,  {})
  aria  = args.fetch(:aria,  {})

  (
    tag || config({ @config_type => :title }, :h3),
    id:    id,
    class: "panel-title #{klass}",
    data:  data,
    aria:  aria,
    &block
  )
end

#to_sString

Used to render the html for the entire panel object.

Returns:

  • (String)


144
145
146
147
148
# File 'lib/bootstrap3_helper/panel.rb', line 144

def to_s
   :div, id: @id, class: container_classes, data: @data do
    @content.call(self)
  end
end