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
{ 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
-
#fa_icon(*names, html_options) ⇒ String
Shortcut to generate FontAwesome icon using tag <i>.
-
#fa_map(name, major = nil) ⇒ String
FontAwesome icon name.
-
#html_classes(string_or_array, options = {}) ⇒ Hash
Shortcut to build up the HTML options as keyword arguments.
-
#imodal(title, body, html_options = {}) ⇒ String
Build up modal.
-
#itooltip(title, icon_suffix = 'info-circle', html_options = {}) ⇒ String
Build up tooltip.
-
#muted(text_content) ⇒ String
Grey text.
-
#na ⇒ String
Grey N/A.
-
#null ⇒ String
Grey null.
Instance Method Details
#fa_icon(*names, html_options) ⇒ String
Shortcut to generate FontAwesome icon using tag <i>.
33 34 35 36 37 38 39 40 |
# File 'lib/helpers/wallaby/styling_helper.rb', line 33 def fa_icon(*args, &block) = args. [:class] = Array [:class] [:class] << 'fa' args.each { |suffix| [:class] << "fa-#{fa_map suffix}" } content_tag :i, nil, , &block end |
#fa_map(name, major = nil) ⇒ String
Returns 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
24 25 26 |
# File 'lib/helpers/wallaby/styling_helper.rb', line 24 def html_classes(string_or_array, = {}) { html_options: .merge(class: string_or_array) } end |
#imodal(title, body, html_options = {}) ⇒ String
Build up modal
59 60 61 62 63 64 65 66 67 |
# File 'lib/helpers/wallaby/styling_helper.rb', line 59 def imodal(title, body, = {}) label ||= .delete(:label) \ || .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 = {}) ⇒ String
Build up tooltip
47 48 49 50 51 52 |
# File 'lib/helpers/wallaby/styling_helper.rb', line 47 def itooltip(title, icon_suffix = 'info-circle', = {}) [:title] = title ([:data] ||= {}).merge! toggle: 'tooltip', placement: 'top' fa_icon icon_suffix, end |
#muted(text_content) ⇒ String
Grey text
82 83 84 |
# File 'lib/helpers/wallaby/styling_helper.rb', line 82 def muted(text_content) content_tag :i, "<#{text_content}>", class: 'text-muted' end |
#na ⇒ String
Returns grey N/A.
75 76 77 |
# File 'lib/helpers/wallaby/styling_helper.rb', line 75 def na muted wt 'labels.na' end |
#null ⇒ String
Returns grey null.
70 71 72 |
# File 'lib/helpers/wallaby/styling_helper.rb', line 70 def null muted wt 'labels.empty' end |