Module: Megatron::IconHelper

Defined in:
app/helpers/megatron/icon_helper.rb

Instance Method Summary collapse

Instance Method Details

#dasherize(input) ⇒ Object



78
79
80
# File 'app/helpers/megatron/icon_helper.rb', line 78

def dasherize(input)
  input.gsub(/[\W,_]/, '-').gsub(/-{2,}/, '-')
end

#default_class(classnames, default) ⇒ Object



82
83
84
85
86
87
# File 'app/helpers/megatron/icon_helper.rb', line 82

def default_class(classnames, default)
  if classnames.nil? || !classnames.is_a?(String)
    classnames = ''
  end
  classnames.to_s << " #{default}"
end

#deployment_text_icon(type, options = {}, &block) ⇒ Object



89
90
91
92
93
# File 'app/helpers/megatron/icon_helper.rb', line 89

def deployment_text_icon(type, options={}, &block)
  options[:color] ||= type
  options[:fallback] ||= 'deployment'
  text_icon("deployment-#{type}", options, &block)
end

#font_icon(name, options = {}) ⇒ Object



31
32
33
34
# File 'app/helpers/megatron/icon_helper.rb', line 31

def font_icon(name, options={})
  options[:class] = default_class(options[:class], "#{name}_icon")
  (:span, class: options[:class], 'aria-hidden' => true) {  }
end

#icon(name, options = {}, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/megatron/icon_helper.rb', line 7

def icon(name, options={}, &block)
  i = use_svg(name, options).html_safe

  if options[:wrapper]
    i = (:span, class: options[:wrapper].strip) do
      i
    end
  end

  if options[:label]
    i += %Q{<span class="icon-label align-middle">#{options[:label]}</span>}.html_safe
  end

  if block
    i += ('span', class: 'align-middle', &block)
  end

  i
end

#icon_label(name, options = {}, &block) ⇒ Object



46
47
48
# File 'app/helpers/megatron/icon_helper.rb', line 46

def icon_label(name, options={}, &block)
  text_icon(name, options) + ('span', class: 'align-middle', &block)
end

#iconsetObject



3
4
5
# File 'app/helpers/megatron/icon_helper.rb', line 3

def iconset
  Cyborg.plugin.svgs.esvg.svgs
end


41
42
43
44
# File 'app/helpers/megatron/icon_helper.rb', line 41

def nav_icon(name, options={}, &block)
  options[:wrapper] = "nav-icon"
  text_icon(name, options, &block)
end

#pin_tab_icon(path, color = 'black') ⇒ Object



27
28
29
# File 'app/helpers/megatron/icon_helper.rb', line 27

def pin_tab_icon(path, color='black')
  %Q{<link rel="mask-icon" mask href="#{path}" color="#{color}">}.html_safe
end

#set_icon_classes(options, defaults = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/helpers/megatron/icon_helper.rb', line 50

def set_icon_classes(options, defaults={})
  options[:class] = (options[:class] || '') << " #{defaults[:class]}"

  if options[:wrapper]
    options[:wrapper] = '' unless options[:wrapper].is_a?(String)
    options[:wrapper] = (options[:wrapper] || '') << " #{defaults[:wrapper]}"
  end

  # Automate adding color classes, blue becomes blue-text
  # This should allow us to change it later more easily if necessary
  if options[:color]
    if options[:color].to_s.start_with?('#')
      options[:style] ||= ''
      options[:style] << " color: #{options[:color].strip}"
    else
      options[:class] << " #{options[:color].to_s.strip}-text"
    end
  end

  # Automate adding size classes, x-small becomes x-small-text
  # This should allow us to change it later more easily if necessary
  if options[:size]
    options[:class] << " #{dasherize(options[:size].to_s.strip)}-text"
  end

  options
end

#text_icon(name, options = {}, &block) ⇒ Object



36
37
38
39
# File 'app/helpers/megatron/icon_helper.rb', line 36

def text_icon(name, options={}, &block)
  options = set_icon_classes(options, class: 'text-icon', wrapper: 'icon-wrapper')
  icon(name.to_s, options, &block)
end