Module: Decidim::IconHelper

Overview

Helpers related to icons

Constant Summary collapse

DEFAULT_RESOURCE_TYPE_ICONS =
{
  "all" => "apps-2-line",
  "Decidim::Proposals::CollaborativeDraft" => "draft-line",
  "Decidim::Comments::Comment" => "chat-1-line",
  "Decidim::Debates::Debate" => "discuss-line",
  "Decidim::Initiative" => "lightbulb-flash-line",
  "Decidim::Meetings::Meeting" => "map-pin-line",
  "Decidim::Blogs::Post" => "pen-nib-line",
  "Decidim::Proposals::Proposal" => "chat-new-line",
  "Decidim::Budgets::Order" => "check-double-line",
  "Decidim::Budgets::Budget" => "coin-line",
  "Decidim::Budgets::Project" => "coin-line",
  "Decidim::Assembly" => "government-line",
  "Decidim::Amendment" => "git-branch-line",
  "Decidim::ParticipatoryProcess" => "treasure-map-line",
  "Decidim::Category" => "price-tag-3-line",
  "Decidim::Scope" => "scan-line",
  "Decidim::Conference" => "mic-line",
  "Decidim::Votings::Voting" => "check-double-fill",
  "Decidim::User" => "user-line",
  "Decidim::UserGroup" => "group-line",
  "comments_count" => "wechat-line",
  "upcoming" => "calendar-2-line",
  "past" => "calendar-check-line",
  "in_person" => "community-line",
  "online" => "webcam-line",
  "hybrid" => "home-wifi-line",
  "official" => "star-line",
  "participants" => "open-arm-line",
  "user_group" => "team-line",
  "user_groups" => "team-line",
  "images" => "image-line",
  "documents" => "file-text-line",
  "like" => "heart-add-line",
  "dislike" => "dislike-line",
  "follow" => "notification-3-line",
  "unfollow" => "notification-3-fill",
  "share" => "share-line",
  "other" => "question-line"
}.freeze

Instance Method Summary collapse

Methods included from LayoutHelper

#_icon_classes, #apple_favicon, #application_path, #current_user_unread_data, #extended_navigation_bar, #external_icon, #favicon, #icon, #legacy_favicon, #organization_colors, #role

Methods included from TooltipHelper

#with_tooltip

Methods included from ModalHelper

#decidim_modal

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.



56
57
58
# File 'decidim-core/app/helpers/decidim/icon_helper.rb', line 56

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.



67
68
69
70
71
72
73
# File 'decidim-core/app/helpers/decidim/icon_helper.rb', line 67

def manifest_icon(manifest, options = {})
  if manifest.respond_to?(:icon) && manifest.icon.present?
    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.



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'decidim-core/app/helpers/decidim/icon_helper.rb', line 83

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

#resource_type_icon(resource_type, options = {}) ⇒ Object



97
98
99
# File 'decidim-core/app/helpers/decidim/icon_helper.rb', line 97

def resource_type_icon(resource_type, options = {})
  icon resource_type_icon_key(resource_type), options
end

#resource_type_icon_key(resource_type) ⇒ Object



101
102
103
# File 'decidim-core/app/helpers/decidim/icon_helper.rb', line 101

def resource_type_icon_key(resource_type)
  DEFAULT_RESOURCE_TYPE_ICONS[resource_type.to_s] || DEFAULT_RESOURCE_TYPE_ICONS["other"]
end

#text_with_resource_icon(resource_name, text) ⇒ Object



105
106
107
108
109
110
# File 'decidim-core/app/helpers/decidim/icon_helper.rb', line 105

def text_with_resource_icon(resource_name, text)
  output = ""
  output += resource_type_icon resource_name
  output +=  :span, text
  output.html_safe
end