Module: AdministrateTailwindTheme::ViewHelper

Defined in:
lib/administrate_tailwind_theme/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#dashboard(resource) ⇒ Object



44
45
46
47
48
# File 'lib/administrate_tailwind_theme/view_helper.rb', line 44

def dashboard(resource)
  "#{resource.classify}Dashboard".constantize.new
rescue ::NameError
  nil
end

#flash_types(key) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/administrate_tailwind_theme/view_helper.rb', line 5

def flash_types(key)
  case key.to_sym
  when :notice
    'Notice'
  when :alert
    'Alert'
  when :error
    'Error'
  else
    key.to_s.humanize
  end
end

#flowbite?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/administrate_tailwind_theme/view_helper.rb', line 22

def flowbite?
  AdministrateTailwindTheme::Configuration.flowbite
end

#group(resource) ⇒ Object



40
41
42
# File 'lib/administrate_tailwind_theme/view_helper.rb', line 40

def group(resource)
  dashboard(resource).try(:group) || :main
end

#grouped_resourcesObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/administrate_tailwind_theme/view_helper.rb', line 26

def grouped_resources
  resources = Administrate::Namespace.new(namespace).resources_with_index_route.map do |resource|
    [group(resource), resource]
  end

  resources = resources.group_by { |group, _resource| group }
  resources.map do |group_name, g_resources|
    [
      group_name,
      g_resources.map(&:last)
    ]
  end
end

#icon?(resource) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/administrate_tailwind_theme/view_helper.rb', line 18

def icon?(resource)
  lookup_context.find_all("administrate/navigation/icons/_#{resource}").any?
end