Module: Panda::CMS::ApplicationHelper

Included in:
Panda::CMS::Admin::BaseController, ApplicationController
Defined in:
app/helpers/panda/cms/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#active_link?(path, match: :starts_with) ⇒ Boolean

Returns:

  • (Boolean)


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

def active_link?(path, match: :starts_with)
  if match == :starts_with
    return request.path.starts_with?(path)
  elsif match == :exact
    return request.path == path
  end

  false
end


41
42
43
44
# File 'app/helpers/panda/cms/application_helper.rb', line 41

def block_link_to(name = nil, options = nil, html_options = {}, &)
  html_options[:class] = "block-link"
  link_to(name, options, html_options, &)
end

#component(name) ⇒ Object

Helper method to render a component



8
9
10
11
# File 'app/helpers/panda/cms/application_helper.rb', line 8

def component(name, *, **, &)
  component = name.to_s.camelize.constantize::Component
  render(component.new(*, **), &)
end

#level_indent(level) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/helpers/panda/cms/application_helper.rb', line 82

def level_indent(level)
  case level
  when 0
    "ml-0"
  when 1
    "ml-4"
  when 2
    "ml-8"
  when 3
    "ml-12"
  when 4
    "ml-16"
  when 5
    "ml-20"
  when 6
    "ml-24"
  when 7
    "ml-28"
  when 8
    "ml-32"
  when 9
    "ml-36"
  when 10
    "ml-40" # We can go to 72...
  else
    "ml-48"
  end
end


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/helpers/panda/cms/application_helper.rb', line 115

def menu_indent(item_with_level_attribute, indent_with: "pl-")
  case item_with_level_attribute.level
  when 0
    "#{indent_with}0"
  when 1
    "#{indent_with}4"
  when 2
    "#{indent_with}8"
  when 3
    "#{indent_with}12"
  when 4
    "#{indent_with}16"
  else
    "#{indent_with}20"
  end
end


66
67
68
69
70
71
72
# File 'app/helpers/panda/cms/application_helper.rb', line 66

def nav_class(mode)
  if mode == "mobile"
    "-mx-3 block rounded-lg px-3 py-2 font-semibold leading-6 text-white hover:text-white hover:underline focus:underline"
  else
    "font-semibold leading-6 text-white hover:text-white hover:underline focus:underline"
  end
end


78
79
80
# File 'app/helpers/panda/cms/application_helper.rb', line 78

def nav_highlight_colour_classes(request)
  "text-white hover:bg-mid/60 transition-all group flex gap-x-3 py-3 px-2 mb-2 rounded-md text-base leading-6 font-normal "
end

#panda_cms_collection(slug, include_unpublished: false) ⇒ Object



46
47
48
49
# File 'app/helpers/panda/cms/application_helper.rb', line 46

def panda_cms_collection(slug, include_unpublished: false)
  Panda::CMS::Features.require!(:collections)
  Panda::CMS::Collections.fetch(slug, include_unpublished: include_unpublished)
end

#panda_cms_collection_items(slug, include_unpublished: false) ⇒ Object



51
52
53
54
# File 'app/helpers/panda/cms/application_helper.rb', line 51

def panda_cms_collection_items(slug, include_unpublished: false)
  Panda::CMS::Features.require!(:collections)
  Panda::CMS::Collections.items(slug, include_unpublished: include_unpublished)
end

#panda_cms_editorObject



25
26
27
28
29
# File 'app/helpers/panda/cms/application_helper.rb', line 25

def panda_cms_editor
  if Panda::Core::Current.user&.admin
    (:a, "🐼", href: edit_admin_cms_page_url(Panda::CMS::Current.page), class: "text-3xl inline absolute right-2 top-2")
  end
end

#panda_cms_feature_enabled?(name) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/helpers/panda/cms/application_helper.rb', line 56

def panda_cms_feature_enabled?(name)
  Panda::CMS::Features.enabled?(name)
end

#panda_cms_form_with(**options) ⇒ Object



60
61
62
63
64
# File 'app/helpers/panda/cms/application_helper.rb', line 60

def panda_cms_form_with(**options, &)
  options[:builder] = Panda::Core::FormBuilder
  options[:class] = ["block visible px-4 sm:px-6 pt-4", options[:class]].compact.join(" ")
  form_with(**options, &)
end

#selected_nav_highlight_colour_classes(request) ⇒ Object



74
75
76
# File 'app/helpers/panda/cms/application_helper.rb', line 74

def selected_nav_highlight_colour_classes(request)
  "bg-mid text-white relative flex transition-all py-3 px-2 mb-2 rounded-md group flex gap-x-3 rounded-md text-base leading-6 font-normal "
end

#table_indent(item_with_level_attribute) ⇒ Object



111
112
113
# File 'app/helpers/panda/cms/application_helper.rb', line 111

def table_indent(item_with_level_attribute)
  level_indent(item_with_level_attribute.level)
end

#title_tagObject

TODO: Expose this elsewhere later, or you have to include helpers in the calling application



15
16
17
18
19
20
21
22
23
# File 'app/helpers/panda/cms/application_helper.rb', line 15

def title_tag
  if @breadcrumbs.present?
    "#{@breadcrumbs.last&.name} · #{Panda::CMS.config.title}".html_safe
  elsif @title.present?
    "#{@title} · #{Panda::CMS.config.title}".html_safe
  else
    Panda::CMS.config.title
  end
end