Sha256: 59e6c6fa66ed2166b7ed4d37d3a83b726c4020e38b0701a5b0f4e6fe9aef5e87
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true # Icon helpers for MaterialDesignIcons module MaterialDesignIcons module IconHelper # Creates an icon tag given an icon name and possible icon # modifiers. # # Examples # # mdi_icon "sheep" # # => <i class="mdi md-sheep"></i> # def mdi_icon(names = 'sheep', original_options = {}) options = original_options.deep_dup classes = ['mdi'] classes.concat Private.icon_names(names) classes.concat Array(options.delete(:class)) text = options.delete(:text) right_icon = options.delete(:right) icon = content_tag(:i, nil, options.merge(class: classes)) Private.icon_join(icon, text, right_icon) end module Private extend ActionView::Helpers::OutputSafetyHelper def self.icon_join(icon, text, reverse_order = false) return icon if text.blank? elements = [icon, ERB::Util.html_escape(text)] elements.reverse! if reverse_order safe_join(elements, ' ') end def self.icon_names(names = []) array_value(names).map { |n| "mdi-#{n}" } end def self.array_value(value = []) value.is_a?(Array) ? value : value.to_s.split(/\s+/) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails_material_design_icons-0.7.0 | lib/rails_material_design_icons/icon_helper.rb |