Module: Kadmin::BootstrapHelper

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

Overview

Collection of Bootstrap helpers

Instance Method Summary collapse

Instance Method Details

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



26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 26

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:

  • 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'> </span>".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



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



19
20
21
# File 'app/helpers/kadmin/bootstrap_helper.rb', line 19

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