Module: RubyCms::ApplicationHelper

Defined in:
app/helpers/ruby_cms/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#ruby_cms_locale_display_name(locale) ⇒ Object



7
8
9
10
# File 'app/helpers/ruby_cms/application_helper.rb', line 7

def ruby_cms_locale_display_name(locale)
  key = "ruby_cms.admin.locales.#{locale}"
  t(key, default: locale.to_s)
end

#ruby_cms_nav_entriesObject



21
22
23
24
25
26
# File 'app/helpers/ruby_cms/application_helper.rb', line 21

def ruby_cms_nav_entries
  RubyCms.visible_nav_registry(
    view_context: self,
    user: (current_user_cms if respond_to?(:current_user_cms))
  )
end

#ruby_cms_safe_svg_fragment(fragment) ⇒ Object

Render an SVG fragment (typically <path …>) safely. Used for nav icons which may come from host app configuration.



30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/ruby_cms/application_helper.rb', line 30

def ruby_cms_safe_svg_fragment(fragment)
  sanitize(
    fragment.to_s,
    tags: %w[svg path g circle rect line polygon polyline ellipse],
    attributes: %w[
      fill stroke stroke-linecap stroke-linejoin stroke-width d
      class viewBox cx cy r x y points x1 y1 x2 y2 aria-hidden aria-label focusable
    ]
  )
end

#ruby_cms_user_display(user) ⇒ Object



12
13
14
15
16
17
18
19
# File 'app/helpers/ruby_cms/application_helper.rb', line 12

def ruby_cms_user_display(user)
  return "" if user.blank?

  %i[email_address email username name].each do |attr|
    return user.public_send(attr) if user.respond_to?(attr) && user.public_send(attr).present?
  end
  user.respond_to?(:id) ? "User ##{user.id}" : user.to_s
end