module Wallaby::StylingHelper

Helper methods to build custom elements

Constants

FONT_AWESOME_MAPPING

backforward compatible with FontAwesome 4 @see this fa migration document fontawesome.com/how-to-use/on-the-web/setup/upgrading-from-version-4

Public Instance Methods

fa_icon(*args, &block) click to toggle source

Shortcut to generate FontAwesome icon using tag <i>. @overload fa_icon(*names, html_options)

@param names [Array<String>] names of the icon
@param html_options [Hash] HTML options for tag <i>

@return [String] HTML I element

# File lib/helpers/wallaby/styling_helper.rb, line 33
def fa_icon(*args, &block)
  html_options = args.extract_options!
  html_options[:class] = Array html_options[:class]
  html_options[:class] << 'fa'
  args.each { |suffix| html_options[:class] << "fa-#{fa_map suffix}" }

  content_tag :i, nil, html_options, &block
end
fa_map(name, major = nil) click to toggle source

@param name [String] @return [String] FontAwesome icon name

# File lib/helpers/wallaby/styling_helper.rb, line 88
def fa_map(name, major = nil)
  @map ||= begin
    major ||= Gem.loaded_specs['font-awesome-sass'].try(:version).try(:segments).try(:first)
    FONT_AWESOME_MAPPING[major] || {}
  end
  @map[name] || name
end
html_classes(string_or_array, options = {}) click to toggle source

Shortcut to build up the HTML options as keyword arguments @param string_or_array [String, Array<String>] @param options [Hash] @return [Hash]

# File lib/helpers/wallaby/styling_helper.rb, line 24
def html_classes(string_or_array, options = {})
  { html_options: options.merge(class: string_or_array) }
end
imodal(title, body, html_options = {}) click to toggle source

Build up modal @param title [String] @param body [String] @param html_options [Hash] @return [String] modal HTML

# File lib/helpers/wallaby/styling_helper.rb, line 59
def imodal(title, body, html_options = {})
  label ||= html_options.delete(:label) \
              || html_options.delete(:icon) || fa_icon('clone')
  content_tag :span, class: 'modaler' do
    concat link_to(label, '#', data: { target: '#imodal', toggle: 'modal' })
    concat content_tag(:span, title, class: 'modaler__title')
    concat content_tag(:span, body, class: 'modaler__body')
  end
end
itooltip(title, icon_suffix = 'info-circle', html_options = {}) click to toggle source

Build up tooltip @param title [String] @param icon_suffix [String] @param html_options [Hash] @return [String] tooltip HTML

# File lib/helpers/wallaby/styling_helper.rb, line 47
def itooltip(title, icon_suffix = 'info-circle', html_options = {})
  html_options[:title] = title
  (html_options[:data] ||= {}).merge! toggle: 'tooltip', placement: 'top'

  fa_icon icon_suffix, html_options
end
muted(text_content) click to toggle source

Grey text @param text_content [String] @return [String] HTML I element

# File lib/helpers/wallaby/styling_helper.rb, line 82
def muted(text_content)
  content_tag :i, "<#{text_content}>", class: 'text-muted'
end
na() click to toggle source

@return [String] grey N/A

# File lib/helpers/wallaby/styling_helper.rb, line 75
def na
  muted wt 'labels.na'
end
null() click to toggle source

@return [String] grey null

# File lib/helpers/wallaby/styling_helper.rb, line 70
def null
  muted wt 'labels.empty'
end