class Bh::Classes::Panel

Public Class Methods

new(app = nil, *args, &block) click to toggle source

Differently from other classes, Panel works with no content or block, given that the options is passed, in which case it functions as the content.

Calls superclass method Bh::Classes::Base::new
# File lib/bh/classes/panel.rb, line 9
def initialize(app = nil, *args, &block)
  if args.first.is_a?(Hash) && !block_given?
    args.unshift args.first.delete(:body)
  end

  super
end

Private Class Methods

contexts() click to toggle source

@return [Hash<Symbol, String>] the class that Bootstrap requires to

append to an panel box based on its context.
# File lib/bh/classes/panel.rb, line 61
def self.contexts
  HashWithIndifferentAccess.new(:'panel-default').tap do |klass|
    klass[:primary]   = :'panel-primary'
    klass[:success] = :'panel-success'
    klass[:info]    = :'panel-info'
    klass[:warning] = :'panel-warning'
    klass[:danger]  = :'panel-danger'
  end
end

Public Instance Methods

body() click to toggle source
# File lib/bh/classes/panel.rb, line 37
def body
  if @options[:body]
    @app.content_tag :div, @options[:body], class: 'panel-body'
  end
end
context_class() click to toggle source

@return [#to_s] the content-related class to assign to the panel.

# File lib/bh/classes/panel.rb, line 18
def context_class
  Panel.contexts[@options[:context]]
end
heading() click to toggle source

@return [#to_s] the text to display as the panel header

# File lib/bh/classes/panel.rb, line 28
def heading
  text = title || @options[:heading]
  @app.content_tag :div, text, class: 'panel-heading' if text
end
merge_html!(html) click to toggle source
# File lib/bh/classes/panel.rb, line 33
def merge_html!(html)
  @content ||= html
end
tag() click to toggle source

@return [#to_s] the HTML tag to wrap the panel in.

# File lib/bh/classes/panel.rb, line 23
def tag
  @options.fetch :tag, :div
end

Private Instance Methods

extract_content_from(*args, &block) click to toggle source
Calls superclass method Bh::Classes::Base#extract_content_from
# File lib/bh/classes/panel.rb, line 45
def extract_content_from(*args, &block)
  if block_given?
    super
  else
    @app.content_tag :div, super, class: 'panel-body'
  end
end
title() click to toggle source
# File lib/bh/classes/panel.rb, line 53
def title
  if @options[:title]
    @app.content_tag :h3, @options[:title], class: 'panel-title'
  end
end