Module: Elabs::IconsHelper

Defined in:
app/helpers/elabs/icons_helper.rb

Constant Summary collapse

CONTENT_TYPE_ICONS =
{
  'Elabs::Album':   'book',
  'Elabs::Article': 'font',
  'Elabs::Note':    'sticky-note',
  'Elabs::Project': 'cog',
  'Elabs::Upload':  'file'
}.freeze

Instance Method Summary collapse

Instance Method Details

#boolean_icon_tag(value, true_icon = 'check', false_icon = 'times', false_class = '', true_class = '') ⇒ Object


18
19
20
21
22
23
# File 'app/helpers/elabs/icons_helper.rb', line 18

def boolean_icon_tag(value, true_icon = 'check', false_icon = 'times', false_class = '', true_class = '')
  icon_class = [
    "fas fa-#{value ? true_icon : false_icon} fa-fw #{value ? true_class : false_class}"
  ]
  (:i, nil, class: icon_class)
end

#colored_good_or_bad_icon_tag(value, true_icon = 'check', false_icon = 'times', false_is_good = false) ⇒ Object


25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/elabs/icons_helper.rb', line 25

def colored_good_or_bad_icon_tag(value, true_icon = 'check', false_icon = 'times', false_is_good = false)
  if false_is_good
    false_class = 'is-success'
    true_class  = 'is-danger'
  else
    false_class = 'is-danger'
    true_class  = 'is-success'
  end
  boolean_icon_tag value, true_icon, false_icon, false_class, true_class
end

#content_type_icon(type, options) ⇒ Object


53
54
55
56
# File 'app/helpers/elabs/icons_helper.rb', line 53

def content_type_icon(type, options)
  type_icon = CONTENT_TYPE_ICONS.key?(type) ? CONTENT_TYPE_ICONS[type] : 'question'
  icon type_icon, options
end

#content_type_icon_from_entity(entity, options) ⇒ Object


58
59
60
61
# File 'app/helpers/elabs/icons_helper.rb', line 58

def content_type_icon_from_entity(entity, options)
  type = entity.class.name.to_sym
  content_type_icon type, options
end

#icon(name, classes = [], base = 'fas', pack = 'fa') ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/elabs/icons_helper.rb', line 36

def icon(name, classes = [], base = 'fas', pack = 'fa')
  icon_class = ["#{base} #{pack || base}-#{name}"]
  icon_class += classes.map do |c|
    if %w[2x 3x 4x fw pulse spin].include? c
      "#{pack || base}-#{c}"
    else
      c
    end
  end

  (:i, nil, class: icon_class)
end

#icon_text(icon, text, icon_options = [], reverse = false) ⇒ Object


11
12
13
14
15
16
# File 'app/helpers/elabs/icons_helper.rb', line 11

def icon_text(icon, text, icon_options = [], reverse = false)
  format(
    reverse ? _('%<text>s %<icon>s') : _('%<icon>s %<text>s'),
    icon: icon(icon, icon_options), text: text
  ).html_safe
end

#license_icon(license, classes = ['fw']) ⇒ Object


49
50
51
# File 'app/helpers/elabs/icons_helper.rb', line 49

def license_icon(license, classes = ['fw'])
  icon license.icon, classes, 'li', 'li'
end