Module: CmsApplicationHelpers

Includes:
ContentBlocksHelper
Defined in:
lib/generators/ruby_cms/templates/helpers/cms_application_helpers.rb

Instance Method Summary collapse

Methods included from ContentBlocksHelper

#content_block, #content_block_list_items, #content_block_text

Instance Method Details

#cms_available_localesObject

Locales offered in the admin UI — configurable via Settings, intersected with the app's available locales. Used by the topbar language toggle.



46
47
48
49
50
# File 'lib/generators/ruby_cms/templates/helpers/cms_application_helpers.rb', line 46

def cms_available_locales
  configured = Array(RubyCms::Settings.get(:available_locales, default: I18n.available_locales.map(&:to_s)))
  locales = configured.map { |l| l.to_s.to_sym } & I18n.available_locales
  locales.presence || I18n.available_locales
end

#cms_maintenance_active?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/generators/ruby_cms/templates/helpers/cms_application_helpers.rb', line 52

def cms_maintenance_active?
  ActiveModel::Type::Boolean.new.cast(RubyCms::Settings.get(:maintenance_mode, default: false))
end

#cms_maintenance_messageObject



56
57
58
# File 'lib/generators/ruby_cms/templates/helpers/cms_application_helpers.rb', line 56

def cms_maintenance_message
  RubyCms::Settings.get(:maintenance_message, default: "").to_s
end

#cms_path(helper_name, *args) ⇒ Object

Resolve a route helper that may belong to an optional (uninstalled) module. Returns the path, or nil when the route helper is not defined — so core chrome can link to optional screens without crashing when those modules are absent.



9
10
11
12
13
# File 'lib/generators/ruby_cms/templates/helpers/cms_application_helpers.rb', line 9

def cms_path(helper_name, *args)
  return nil unless respond_to?(helper_name)

  public_send(helper_name, *args)
end

#ruby_cms_locale_display_name(locale) ⇒ Object



15
16
17
18
# File 'lib/generators/ruby_cms/templates/helpers/cms_application_helpers.rb', line 15

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

#ruby_cms_nav_entriesObject



29
30
31
32
33
34
# File 'lib/generators/ruby_cms/templates/helpers/cms_application_helpers.rb', line 29

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_nav_sidebar_rows(section: :main) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/generators/ruby_cms/templates/helpers/cms_application_helpers.rb', line 36

def ruby_cms_nav_sidebar_rows(section: :main)
  RubyCms.visible_nav_sidebar_rows(
    section: section,
    view_context: self,
    user: (current_user_cms if respond_to?(:current_user_cms))
  )
end

#ruby_cms_safe_svg_fragment(fragment) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/generators/ruby_cms/templates/helpers/cms_application_helpers.rb', line 60

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



20
21
22
23
24
25
26
27
# File 'lib/generators/ruby_cms/templates/helpers/cms_application_helpers.rb', line 20

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