Module: BarkestCore::HtmlHelper
- Defined in:
- app/helpers/barkest_core/html_helper.rb
Overview
This module contains some helper functions to make generating common HTML elements easier.
Instance Method Summary collapse
-
#check_if(bool_val, size = :small) ⇒ Object
Creates a check glyph icon if the
bool_val
is true. -
#glyph(name, size = nil) ⇒ Object
Creates a glyph icon using the specified
name
andsize
. -
#panel(title, options = { }, &block) ⇒ Object
Creates a panel with the specified title.
Instance Method Details
#check_if(bool_val, size = :small) ⇒ Object
Creates a check glyph icon if the bool_val
is true.
The size
can be nil, :small, :smaller, :big, or :bigger. The default size
is :small.
26 27 28 |
# File 'app/helpers/barkest_core/html_helper.rb', line 26 def check_if(bool_val, size = :small) glyph(:ok, size) if bool_val end |
#glyph(name, size = nil) ⇒ Object
Creates a glyph icon using the specified name
and size
.
The size
can be nil, :small, :smaller, :big, or :bigger. The default size is nil.
11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/barkest_core/html_helper.rb', line 11 def glyph(name, size = nil) size = size.to_s.downcase if %w(small smaller big bigger).include?(size) size = ' glyph-' + size else size = '' end "<i class=\"glyphicon glyphicon-#{h name}#{size}\"></i>".html_safe end |
#panel(title, options = { }, &block) ⇒ Object
Creates a panel with the specified title.
Valid options:
* +type+ can be +primary+, +success+, +info+, +warning+, or +danger+. Default: primary
* +size+ can be any value from 1..12. Default: 6
* +offset+ can be any value from 0..12. Default: 3
* +open_body+ can be true or false. If true, the body division is opened (and closed) by this helper. Default: true
Provide a block to render content within the panel.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/barkest_core/html_helper.rb', line 40 def panel(title, = { }, &block) = { type: 'primary', size: 6, offset: 3, open_body: true }.merge( || {}) [:type] = [:type].to_s.downcase [:type] = 'primary' unless %w(primary success info warning danger).include?([:type]) [:size] = 6 unless (1..12).include?([:size]) [:offset] = 3 unless (0..12).include?([:offset]) ret = "<div class=\"col-md-#{[:size]} col-md-offset-#{[:offset]}\"><div class=\"panel panel-#{[:type]}\"><div class=\"panel-heading\"><h4 class=\"panel-title\">#{h title}</h4></div>" ret += '<div class="panel-body">' if [:open_body] if block_given? content = capture { block.call } ret += h content.to_s end ret += '</div>' if [:open_body] ret += '</div></div>' ret.html_safe end |