Module: Wallaby::StylingHelper

Included in:
BaseHelper
Defined in:
lib/helpers/wallaby/styling_helper.rb

Overview

Helper methods to build custom elements

Constant Summary collapse

FONT_AWESOME_MAPPING =

backforward compatible with FontAwesome 4

See Also:

  • fa migration document https://fontawesome.com/how-to-use/on-the-web/setup/upgrading-from-version-4
{
  4 => {
    clock: 'clock-o',
    bars: 'navicon',
    calendar: 'calendar-o',
    'check-square': 'check-square-o',
    square: 'square-o',
    link: 'chain',
    user: 'user-o'
  }
}.with_indifferent_access.freeze

Instance Method Summary collapse

Instance Method Details

#fa_icon(*names, html_options) ⇒ String

Shortcut to generate FontAwesome icon using tag <i>.

Parameters:

  • names (Array<String>)

    names of the icon

  • html_options (Hash)

    HTML options for tag <i>

Returns:

  • (String)

    HTML I element



33
34
35
36
37
38
39
40
# 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}" }

   :i, nil, html_options, &block
end

#fa_map(name, major = nil) ⇒ String

Returns FontAwesome icon name.

Parameters:

  • name (String)

Returns:

  • (String)

    FontAwesome icon name



88
89
90
91
92
93
94
# 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 = {}) ⇒ Hash

Shortcut to build up the HTML options as keyword arguments

Parameters:

  • string_or_array (String, Array<String>)
  • options (Hash) (defaults to: {})

Returns:

  • (Hash)


24
25
26
# 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 = {}) ⇒ String

Build up modal

Parameters:

  • title (String)
  • body (String)
  • html_options (Hash) (defaults to: {})

Returns:

  • (String)

    modal HTML



59
60
61
62
63
64
65
66
67
# 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')
   :span, class: 'modaler' do
    concat link_to(label, '#', data: { target: '#imodal', toggle: 'modal' })
    concat (:span, title, class: 'modaler__title')
    concat (:span, body, class: 'modaler__body')
  end
end

#itooltip(title, icon_suffix = 'info-circle', html_options = {}) ⇒ String

Build up tooltip

Parameters:

  • title (String)
  • icon_suffix (String) (defaults to: 'info-circle')
  • html_options (Hash) (defaults to: {})

Returns:

  • (String)

    tooltip HTML



47
48
49
50
51
52
# 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) ⇒ String

Grey text

Parameters:

  • text_content (String)

Returns:

  • (String)

    HTML I element



82
83
84
# File 'lib/helpers/wallaby/styling_helper.rb', line 82

def muted(text_content)
   :i, "<#{text_content}>", class: 'text-muted'
end

#naString

Returns grey N/A.

Returns:

  • (String)

    grey N/A



75
76
77
# File 'lib/helpers/wallaby/styling_helper.rb', line 75

def na
  muted wt 'labels.na'
end

#nullString

Returns grey null.

Returns:

  • (String)

    grey null



70
71
72
# File 'lib/helpers/wallaby/styling_helper.rb', line 70

def null
  muted wt 'labels.empty'
end