Class: Decidim::IconRegistry
- Inherits:
-
Object
- Object
- Decidim::IconRegistry
- Defined in:
- decidim-core/lib/decidim/icon_registry.rb
Instance Method Summary collapse
- #all ⇒ Object
- #categories(field = :category) ⇒ Object
- #find(name) ⇒ Object
-
#initialize ⇒ IconRegistry
constructor
A new instance of IconRegistry.
-
#register(name:, icon:, description:, category:, engine:) ⇒ Object
It allows detecting with icons are valid remixicons icons, and also for documenting them in the
decidim-design(aka Decidim Design Guide or DDG).
Constructor Details
#initialize ⇒ IconRegistry
Returns a new instance of IconRegistry.
5 6 7 |
# File 'decidim-core/lib/decidim/icon_registry.rb', line 5 def initialize @icons = ActiveSupport::HashWithIndifferentAccess.new end |
Instance Method Details
#all ⇒ Object
35 36 37 |
# File 'decidim-core/lib/decidim/icon_registry.rb', line 35 def all @icons end |
#categories(field = :category) ⇒ Object
39 40 41 |
# File 'decidim-core/lib/decidim/icon_registry.rb', line 39 def categories(field = :category) all.values.group_by { |d| d[field].try(:to_s) } end |
#find(name) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'decidim-core/lib/decidim/icon_registry.rb', line 26 def find(name) if name.blank? Decidim.deprecator.warn "The requested icon is blank." name = "other" end @icons[name] || deprecated(name) end |
#register(name:, icon:, description:, category:, engine:) ⇒ Object
It allows detecting with icons are valid remixicons icons, and also for documenting them in the decidim-design (aka Decidim Design Guide or DDG).
Some of these fields are used to load and work with the icon (name and icon) and others are for documentation purposes in DDG (category, description, and engine).
20 21 22 23 24 |
# File 'decidim-core/lib/decidim/icon_registry.rb', line 20 def register(name:, icon:, description:, category:, engine:) Decidim.deprecator.warn("#{name} already registered. #{@icons[name].inspect}") if @icons[name] @icons[name] = { name:, icon:, description:, category:, engine: } end |