Module: Kadmin::BootstrapHelper

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

Overview

Collection of Bootstrap helpers

Instance Method Summary collapse

Instance Method Details

#create_custom_label(label, label_for = '', required = false, display_help = true, title = '', message = '', label_class = 'control-label') ⇒ Object

Custom label generator using bootstrap i.e. * for mendatory feilds, help icon and popover for help

Parameters:

  • label (String)

    text for the view

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

    is ID of the html element for which we are displaying label.

  • Display (Boolean)

    the red asteric to indicate mendatory field.

  • to (Boolean)

    decide weither we need to display the help iocn or not

  • Title (String)

    of the popover

  • Body (String)

    text of popover

  • classname (String)

    for the label.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 54

def create_custom_label(label, label_for = '', required = false, display_help = true, title = '', message = '', label_class = 'control-label')
  label = t(label)
  label = label.html_safe

  require_html = required ? '<span class="required-field"><span>' : ''
  icon_html = "<i class='fa fa-question-circle' style='color:green'></i>"

  display_message = ''
  if display_help
    message = t(message)
    message = message.gsub('"', '\"')
    message = message.gsub("'", "\'")
    html_message = message.html_safe

    title = t(title)
    title = title.html_safe
    display_message = "<span data-toggle='popover' title='#{title}' data-placement='top' data-trigger='hover' data-content='#{html_message}'>#{icon_html}</span>"
  end

  return "<label for='#{label_for}' class='#{label_class}'' >#{require_html}#{label} #{display_message}</label>".html_safe
end

Generates a navigation drop down for bootstrap

Parameters:

  • prompt (String)

    dropdown prompt

  • links (Array<Hash,String>) (defaults to: [])

    list of links to add within the dropdown



34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 34

def dropdown(prompt, links = [])
  button_content = (:span, '', class: 'caret').prepend(prompt)
  button = button_tag(button_content, type: 'button', data: { toggle: 'dropdown' }, class: 'btn btn-sm')
  list = (:ul, '', class: 'dropdown-menu') do
    links.reduce(ActiveSupport::SafeBuffer.new) do |buffer, link|
      buffer + (:li, link)
    end
  end

  return (:div, button + list, class: 'dropdown', style: 'display: inline-block;')
end

#glyphicon(icon) ⇒ Object

Parameters:

  • the (String)

    name of the icon you want

See Also:

  • icons: http://fontawesome.io/icons/


8
9
10
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 8

def glyphicon(icon)
  return "<i class='fa fa-#{icon}' aria-hidden='true'></i>".html_safe
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



15
16
17
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 15

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



21
22
23
24
25
26
27
28
29
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 21

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