Module: Decidim::LayoutHelper
- Included in:
- AddressCell, Amendable::EmendationActionsCell, AuthorCell, CardMCell, DiffCell, EndorsementButtonsCell, FollowButtonCell, IconHelper, UserConversationCell, UserConversationsCell, VersionsListItemCell, WizardStepFormCell
- Defined in:
- app/helpers/decidim/layout_helper.rb
Overview
View helpers related to the layout.
Instance Method Summary collapse
- #_icon_classes(options = {}) ⇒ Object
- #extended_navigation_bar(items, max_items: 5) ⇒ Object
-
#external_icon(path, options = {}) ⇒ Object
Outputs a SVG icon from an external file.
-
#favicon ⇒ Object
Public: Generates a set of meta tags that generate the different favicon versions for an organization.
-
#icon(name, options = {}) ⇒ Object
Outputs an SVG-based icon.
-
#organization_colors ⇒ Object
Renders a view with the customizable CSS variables in two flavours: 1.
-
#role(options = {}) ⇒ Object
Allows to create role attribute according to accessibility rules.
Instance Method Details
#_icon_classes(options = {}) ⇒ Object
76 77 78 79 80 |
# File 'app/helpers/decidim/layout_helper.rb', line 76 def _icon_classes( = {}) classes = [:remove_icon_class] ? [] : ["icon"] classes += [[:class]] classes.compact end |
#extended_navigation_bar(items, max_items: 5) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/helpers/decidim/layout_helper.rb', line 82 def (items, max_items: 5) return unless items.any? extra_items = items.slice((max_items + 1)..-1) || [] active_item = items.find { |item| item[:active] } render partial: "decidim/shared/extended_navigation_bar", locals: { items: items, extra_items: extra_items, active_item: active_item, max_items: max_items } end |
#external_icon(path, options = {}) ⇒ Object
Outputs a SVG icon from an external file. It apparently renders an image tag, but then a JS script kicks in and replaces it with an inlined SVG version.
path - The asset’s path
Returns an <img /> tag with the SVG icon.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/decidim/layout_helper.rb', line 57 def external_icon(path, = {}) classes = _icon_classes() + ["external-icon"] if path.split(".").last == "svg" attributes = { class: classes.join(" ") }.merge() asset = Rails.application.assets_manifest.find_sources(path).first asset.gsub("<svg ", "<svg#{tag_builder.(attributes)} ").html_safe else image_tag(path, class: classes.join(" "), style: "display: none") end end |
#favicon ⇒ Object
Public: Generates a set of meta tags that generate the different favicon versions for an organization.
Returns a safe String with the versions.
10 11 12 13 14 15 16 |
# File 'app/helpers/decidim/layout_helper.rb', line 10 def favicon return if current_organization.favicon.blank? safe_join(Decidim::OrganizationFaviconUploader::SIZES.map do |version, size| favicon_link_tag(current_organization.favicon.send(version).url, sizes: "#{size}x#{size}") end) end |
#icon(name, options = {}) ⇒ Object
Outputs an SVG-based icon.
name - The String with the icon name. options - The Hash options used to customize the icon (default {}):
:width - The Number of width in pixels (optional).
:height - The Number of height in pixels (optional).
:title - The title for the SVG element (optional, similar to alt for img)
:aria_label - The String to set as aria label (optional).
:aria_hidden - The Truthy value to enable aria_hidden (optional).
:role - The String to set as the role (optional).
:class - The String to add as a CSS class (optional).
Returns a String.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/decidim/layout_helper.rb', line 31 def icon(name, = {}) html_properties = {} html_properties["width"] = [:width] html_properties["height"] = [:height] html_properties["aria-label"] = [:aria_label] || [:"aria-label"] || ["aria-label"] html_properties["role"] = [:role] || "img" html_properties["aria-hidden"] = [:aria_hidden] || [:"aria-hidden"] || ["aria-hidden"] html_properties["class"] = (["icon--#{name}"] + _icon_classes()).join(" ") content_tag :svg, html_properties do inner = content_tag :title, ["title"] || html_properties["aria-label"] inner += content_tag :use, nil, role: [:role], "href" => "#{asset_path("decidim/icons.svg")}#icon-#{name}" inner end end |
#organization_colors ⇒ Object
Renders a view with the customizable CSS variables in two flavours:
-
as a hexadecimal valid CSS color (ie: #ff0000)
-
as a disassembled RGB components (ie: 255,0,0)
Example:
–primary: #ff0000; –primary-rgb: 255,0,0
Hexadecimal variables can be used as a normal CSS color:
color: var(–primary)
While the disassembled variant can be used where you need to manipulate the color somehow (ie: adding a background transparency):
background-color: rgba(var(–primary-rgb), 0.5)
113 114 115 116 |
# File 'app/helpers/decidim/layout_helper.rb', line 113 def organization_colors css = current_organization.colors.each.map { |k, v| "--#{k}: #{v};--#{k}-rgb: #{v[1..2].hex},#{v[3..4].hex},#{v[5..6].hex};" }.join render partial: "layouts/decidim/organization_colors", locals: { css: css } end |
#role(options = {}) ⇒ Object
Allows to create role attribute according to accessibility rules
Returns role attribute string if role option is specified
72 73 74 |
# File 'app/helpers/decidim/layout_helper.rb', line 72 def role( = {}) "role=\"#{[:role]}\" " if [:role] end |