Module: Decidim::IconHelper

Overview

Helpers related to icons

Instance Method Summary collapse

Methods included from LayoutHelper

#_icon_classes, #application_path, #extended_navigation_bar, #external_icon, #favicon, #icon, #organization_colors, #role

Instance Method Details

#component_icon(component, options = {}) ⇒ Object

Public: Returns an icon given an instance of a Component. It defaults to a question mark when no icon is found.

component - The component to generate the icon for. options - a Hash with options

Returns an HTML tag with the icon.



15
16
17
# File 'app/helpers/decidim/icon_helper.rb', line 15

def component_icon(component, options = {})
  manifest_icon(component.manifest, options)
end

#manifest_icon(manifest, options = {}) ⇒ Object

Public: Returns an icon given an instance of a Manifest. It defaults to a question mark when no icon is found.

manifest - The manifest to generate the icon for. options - a Hash with options

Returns an HTML tag with the icon.



26
27
28
29
30
31
32
# File 'app/helpers/decidim/icon_helper.rb', line 26

def manifest_icon(manifest, options = {})
  if manifest.icon
    external_icon manifest.icon, options
  else
    icon "question-mark", options
  end
end

#resource_icon(resource, options = {}) ⇒ Object

Public: Finds the correct icon for the given resource. If the resource has a Component then it uses it to find the icon, otherwise checks for the resource manifest to find the icon.

resource - The resource to generate the icon for. options - a Hash with options

Returns an HTML tag with the icon.



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/decidim/icon_helper.rb', line 42

def resource_icon(resource, options = {})
  if resource.class.name == "Decidim::Comments::Comment"
    icon "comment-square", options
  elsif resource.respond_to?(:component)
    component_icon(resource.component, options)
  elsif resource.respond_to?(:manifest)
    manifest_icon(resource.manifest, options)
  elsif resource.is_a?(Decidim::User)
    icon "person", options
  else
    icon "bell", options
  end
end