Class: Decidim::IconRegistry

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/lib/decidim/icon_registry.rb

Instance Method Summary collapse

Constructor Details

#initializeIconRegistry

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

#allObject



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).

Parameters:

  • name (String)

    The name of the icon. It will be used to find the icon later.

  • icon (String)

    The id of the icon. It will be used to load the icon from remixicon library.

  • category (String)

    The category name. It will be used to group the icons by category.

  • description (String)

    The description of the icon. It will be used to show the purpose of the icon in DDG.

  • engine (String)

    The engine name. It is used internally to identify the module where the icon is being used.



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