Module: Megatron::IconHelper
- Defined in:
- app/helpers/megatron/icon_helper.rb
Instance Method Summary collapse
- #dasherize(input) ⇒ Object
- #default_class(classnames, default) ⇒ Object
- #deployment_text_icon(type, options = {}, &block) ⇒ Object
- #font_icon(name, options = {}) ⇒ Object
- #icon(name, options = {}, &block) ⇒ Object
- #icon_label(name, options = {}, &block) ⇒ Object
- #iconset ⇒ Object
- #nav_icon(name, options = {}, &block) ⇒ Object
- #pin_tab_icon(path, color = 'black') ⇒ Object
- #set_icon_classes(options, defaults = {}) ⇒ Object
- #text_icon(name, options = {}, &block) ⇒ Object
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, ={}, &block) [:color] ||= type [:fallback] ||= 'deployment' text_icon("deployment-#{type}", , &block) end |
#font_icon(name, options = {}) ⇒ Object
31 32 33 34 |
# File 'app/helpers/megatron/icon_helper.rb', line 31 def font_icon(name, ={}) [:class] = default_class([:class], "#{name}_icon") content_tag(:span, class: [: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, ={}, &block) i = use_svg(name, ).html_safe if [:wrapper] i = content_tag(:span, class: [:wrapper].strip) do i end end if [:label] i += %Q{<span class="icon-label align-middle">#{[:label]}</span>}.html_safe end if block i += content_tag('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, ={}, &block) text_icon(name, ) + content_tag('span', class: 'align-middle', &block) end |
#iconset ⇒ Object
3 4 5 |
# File 'app/helpers/megatron/icon_helper.rb', line 3 def iconset Cyborg.plugin.svgs.esvg.svgs end |
#nav_icon(name, options = {}, &block) ⇒ Object
41 42 43 44 |
# File 'app/helpers/megatron/icon_helper.rb', line 41 def nav_icon(name, ={}, &block) [:wrapper] = "nav-icon" text_icon(name, , &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(, defaults={}) [:class] = ([:class] || '') << " #{defaults[:class]}" if [:wrapper] [:wrapper] = '' unless [:wrapper].is_a?(String) [:wrapper] = ([: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 [:color] if [:color].to_s.start_with?('#') [:style] ||= '' [:style] << " color: #{[:color].strip}" else [:class] << " #{[: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 [:size] [:class] << " #{dasherize([:size].to_s.strip)}-text" end end |
#text_icon(name, options = {}, &block) ⇒ Object
36 37 38 39 |
# File 'app/helpers/megatron/icon_helper.rb', line 36 def text_icon(name, ={}, &block) = set_icon_classes(, class: 'text-icon', wrapper: 'icon-wrapper') icon(name.to_s, , &block) end |