module FluentIcons
class Fluent
attr_reader :path, :options, :width, :height, :symbol, :keywords, :weight, :style, :prefix
def initialize(symbol, options = {})
@symbol = symbol.to_s
@style = (options.delete(:style) || 'regular').to_s
@weight = (options.delete(:weight) || 20).to_s
@prefix = (options.delete(:prefix) || 'fluent').to_s
fluent = get_fluent_path(@symbol, style, weight)
if (fluent = get_fluent_path(@symbol, style, weight))&.dig(:path).nil?
@path = ""
else
@path = fluent[:path]
end
@width = (options[:width] || weight).to_i
@height = (options[:height] || weight).to_i
@options = options.dup
@options.merge!({
class: classes,
viewBox: [0, 0, width, height].join(' ').to_s,
version: '1.1'
})
@options.merge!(a11y)
end
def to_svg
"".strip
end
private
def html_attributes
attrs = ''
options.each { |attr, value| attrs += "#{ attr }=\"#{ value }\" " }
attrs.strip
end
def classes
"#{ prefix } #{ prefix }-#{ symbol } #{ options[:class] } ".strip
end
def a11y
accessible = { }
if options['aria-label'].nil?
accessible['aria-hidden'] = true
else
accessible['role'] = 'img'
end
accessible
end
def get_fluent_path(symbol, style, weight)
if (icon = FluentIcons::SYMBOLS[symbol])
return {
name: icon['name'],
keywords: [],
path: icon.dig('icons', style, weight)
}
end
end
end
end