Module: SvgIconHelper
- Defined in:
- app/helpers/svg_icon_helper.rb
Overview
app/helpers/svg_icon_helper.rb
Instance Method Summary collapse
Instance Method Details
#svg_icon(name, size: 24, type: :outline, classes: [], color: 'currentColor', stroke_width: 2) ⇒ View
This method is abstract.
Render the appropriate icon based on the name and type
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/svg_icon_helper.rb', line 5 def svg_icon(name, size: 24, type: :outline, classes: [], color: 'currentColor', stroke_width: 2) return if name.blank? classes = if size <= 24 ['icon', classes].flatten.compact.join(' ') else classes.compact.flatten.join(' ') end key = "icon_partial_path:#{name}:#{type}" (partial, stroke) = Rails.cache.fetch(key, expires_in: SystemConfiguration.long_cache) do preferred_path = I18n.exists?("nav.icons.#{name}") ? 'icons/' + I18n.t("nav.icons.#{name}") : "icons/#{type}/#{name}" outline_path = "icons/outline/#{name}" filled_path = "icons/filled/#{name}" [preferred_path, outline_path, filled_path].collect do |path| [preferred_path, color] if lookup_context.exists?(path, [], true) end.compact.first end tag.svg(xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: size, height: size, class: classes, fill: 'none', stroke: stroke, 'stroke-width': stroke_width, 'stroke-linecap': 'round', 'stroke-linejoin': 'round', title: name) do render partial end rescue StandardError => e puts "Error: #{e}" tag.svg(xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: size, height: size, class: classes, fill: 'none', stroke: 'red', 'stroke-width': stroke_width, 'stroke-linecap': 'round', 'stroke-linejoin': 'round', data: { bs_toggle: :tooltip }, title: "#{type}/#{name}") do render 'icons/outline/bug' end end |