Module: Megatron::IconHelper
- Defined in:
- app/helpers/megatron/icon_helper.rb
Constant Summary collapse
- ICON_OPTIONS =
{ config_file: File.('../../../config/esvg.yml', File.dirname(__FILE__)), path: File.('../../assets/esvg/megatron', File.dirname(__FILE__)) }
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
- #set_icon_classes(options, defaults = {}) ⇒ Object
- #text_icon(name, options = {}, &block) ⇒ Object
Instance Method Details
#dasherize(input) ⇒ Object
79 80 81 |
# File 'app/helpers/megatron/icon_helper.rb', line 79 def dasherize(input) input.gsub(/[\W,_]/, '-').gsub(/-{2,}/, '-') end |
#default_class(classnames, default) ⇒ Object
83 84 85 86 87 88 |
# File 'app/helpers/megatron/icon_helper.rb', line 83 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
90 91 92 93 94 |
# File 'app/helpers/megatron/icon_helper.rb', line 90 def deployment_text_icon(type, ={}, &block) [:color] ||= type [:fallback] ||= 'deployment' text_icon("deployment-#{type}", , &block) end |
#font_icon(name, options = {}) ⇒ Object
32 33 34 35 |
# File 'app/helpers/megatron/icon_helper.rb', line 32 def font_icon(name, ={}) [:class] = default_class([:class], "#{name}_icon") content_tag(:span, class: [:class], 'aria-hidden' => true) { } end |
#icon(name, options = {}, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/megatron/icon_helper.rb', line 12 def icon(name, ={}, &block) i = iconset.svg_icon(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">#{options[:label]}</span>}.html_safe end if block i += content_tag('span', class: 'align-middle', &block) end i end |
#icon_label(name, options = {}, &block) ⇒ Object
47 48 49 |
# File 'app/helpers/megatron/icon_helper.rb', line 47 def icon_label(name, ={}, &block) text_icon(name, ) + content_tag('span', class: 'align-middle', &block) end |
#iconset ⇒ Object
8 9 10 |
# File 'app/helpers/megatron/icon_helper.rb', line 8 def iconset svg_icons(ICON_OPTIONS) end |
#nav_icon(name, options = {}, &block) ⇒ Object
42 43 44 45 |
# File 'app/helpers/megatron/icon_helper.rb', line 42 def nav_icon(name, ={}, &block) [:wrapper] = "nav-icon" text_icon(name, , &block) end |
#set_icon_classes(options, defaults = {}) ⇒ Object
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 77 |
# File 'app/helpers/megatron/icon_helper.rb', line 51 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: #{options[:color].strip}" else [: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 [:size] [:class] << " #{dasherize(options[:size].to_s.strip)}-text" end end |
#text_icon(name, options = {}, &block) ⇒ Object
37 38 39 40 |
# File 'app/helpers/megatron/icon_helper.rb', line 37 def text_icon(name, ={}, &block) = set_icon_classes(, class: 'text-icon', wrapper: 'icon-wrapper') icon(name.to_s, , &block) end |