Module: Decidim::LayoutHelper

Defined in:
app/helpers/decidim/layout_helper.rb

Overview

View helpers related to the layout.

Instance Method Summary collapse

Instance Method Details

#_icon_classes(options = {}) ⇒ Object



76
77
78
79
80
# File 'app/helpers/decidim/layout_helper.rb', line 76

def _icon_classes(options = {})
  classes = options[:remove_icon_class] ? [] : ["icon"]
  classes += [options[:class]]
  classes.compact
end

#decidim_page_titleObject



5
6
7
8
# File 'app/helpers/decidim/layout_helper.rb', line 5

def decidim_page_title
  title = content_for(:meta_title)
  title ? "#{title} - #{current_organization.name}" : current_organization.name
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.



63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/decidim/layout_helper.rb', line 63

def external_icon(path, options = {})
  # Ugly hack to prevent PhantomJS from freaking out with SVGs.
  classes = _icon_classes(options) + ["external-icon"]
  return (:span, "?", class: classes.join(" "), "data-src" => path) if Rails.env.test?

  if path.split(".").last == "svg"
    asset = Rails.application.assets_manifest.find_sources(path).first
    asset.gsub("<svg ", "<svg class=\"#{classes.join(" ")}\" ").html_safe
  else
    image_tag(path, class: classes.join(" "), style: "display: none")
  end
end

#faviconObject

Public: Generates a set of meta tags that generate the different favicon versions for an organization.

Returns a safe String with the versions.



14
15
16
17
18
19
20
# File 'app/helpers/decidim/layout_helper.rb', line 14

def favicon
  return unless current_organization.favicon.present?

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/decidim/layout_helper.rb', line 34

def icon(name, options = {})
  # Ugly hack to work around the issue of phantomjs not sending js events
  # when clicking on a SVG element.
  if Rails.env.test?
    return (:span, "?", class: "icon icon--#{name}")
  end

  html_properties = {}

  html_properties["width"] = options[:width]
  html_properties["height"] = options[:height]
  html_properties["aria-label"] = options[:aria_label]
  html_properties["role"] = options[:role]
  html_properties["aria-hidden"] = options[:aria_hidden]

  html_properties["class"] = (["icon--#{name}"] + _icon_classes(options)).join(" ")

   :svg, html_properties do
     :use, nil, "xlink:href" => "#{asset_url("decidim/icons.svg")}#icon-#{name}"
  end
end