Module: Kadmin::BootstrapHelper

Defined in:
app/helpers/kadmin/bootstrap_helper.rb

Overview

Collection of Bootstrap helpers

Instance Method Summary collapse

Instance Method Details

#alert(type, text: '', dismissible: true, &block) ⇒ Object

Generates HTML for a bootstrap alert message, optionally closable.

Parameters:

  • type (String)

    the type of the alert: danger, success, info, warning, or any alert- defined in your CSS

  • text (String) (defaults to: '')

    optionally some text if you're not going to pass a block

  • dismissible (Boolean) (defaults to: true)

    if true, adds a close button to the alert. Requires JS enabled

  • block (Proc)

    optional block to pass if you want add more complex HTML inside



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 22

def alert(type, text: '', dismissible: true, &block)
  css_classes = %W(alert alert-#{type})
  css_classes << 'alert-dismissible' if dismissible

  block_content = capture(&block)

  html = nil
  unless block_content.blank? && text.blank?
    html = (:div, '', class: css_classes.join(' '), role: 'alert') do
      content = text.html_safe

      if dismissible
        button = button_tag(type: 'button', class: 'close', 'data-dismiss': 'alert') do
          (:span, '&times', {}, false)
        end
        content.concat(button)
      end

      content.concat(capture(&block)) if block_given?
    end
  end

  return html
end

#glyphicon(icon) ⇒ Object

Parameters:

  • icon (String)

    the part after glyphicon-

See Also:



6
7
8
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 6

def glyphicon(icon)
  return (:span, ' ', class: "glyphicon glyphicon-#{icon}", 'aria-hidden': 'true')
end

#glyphicon_if_else(condition, icon_true, icon_false) ⇒ Object

Parameters:

  • condition (Boolean)

    condition of evaluate

  • icon_true (String)

    the glyphicon to use if true

  • icon_false (String)

    the glyphicon to use if false



13
14
15
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 13

def glyphicon_if_else(condition, icon_true, icon_false)
  return condition ? glyphicon(icon_true) : glyphicon(icon_false)
end

Parameters:

  • url_options (Hash, String)

    anything accepted by link_to and image_tag

  • max_height (Integer)

    maximum height of the thumbnail



49
50
51
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 49

def thumbnail_link(url_options, max_height)
  return link_to(image_tag(url_options), url_options, class: 'thumbnail', style: "max-height: #{max_height}px", target: 'new')
end