Module: MenuRenderer

Defined in:
app/models/menu_renderer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exclude(*type_names) ⇒ Object



2
3
4
5
# File 'app/models/menu_renderer.rb', line 2

def exclude(*type_names)
  @excluded_class_names ||= []
  @excluded_class_names.concat(type_names).uniq!
end

.excluded_class_namesObject



8
9
10
# File 'app/models/menu_renderer.rb', line 8

def excluded_class_names
  MenuRenderer.instance_variable_get(:@excluded_class_names)
end

Instance Method Details

#add_child_disabled?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/models/menu_renderer.rb', line 76

def add_child_disabled?
  allowed_child_classes.size == 0
end


84
85
86
# File 'app/models/menu_renderer.rb', line 84

def add_child_link
  view.link_to('<i class="fas fa-plus-circle"></i> Add Child'.html_safe, view.new_admin_page_child_path(self, page_class: default_child.name), class: 'action')
end


96
97
98
# File 'app/models/menu_renderer.rb', line 96

def add_child_link_with_menu
  add_child_link_with_menu_hook + add_child_menu
end


88
89
90
# File 'app/models/menu_renderer.rb', line 88

def add_child_link_with_menu_hook
  view.link_to('<i class="fas fa-plus-circle"></i> Add Child'.html_safe, "#allowed_children_#{id}", class: 'action dropdown')
end

#add_child_menuObject



92
93
94
# File 'app/models/menu_renderer.rb', line 92

def add_child_menu
  menu_list
end

#add_child_optionObject



100
101
102
103
104
105
106
107
108
109
110
# File 'app/models/menu_renderer.rb', line 100

def add_child_option
  if add_child_disabled?
    disabled_add_child_link
  else
    if allowed_child_classes.size == 1
      add_child_link
    else
      add_child_link_with_menu
    end
  end
end

#additional_menu_features?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/menu_renderer.rb', line 23

def additional_menu_features?
  @additional_menu_features ||= (menu_renderer_module_name != 'MenuRenderer' && Object.const_defined?(menu_renderer_module_name))
end

#allowed_child_classesObject



36
37
38
39
40
41
42
43
44
# File 'app/models/menu_renderer.rb', line 36

def allowed_child_classes
  (allowed_children_cache.to_s.split(',') - Array(excluded_class_names)).map do |name|
    begin
      name.constantize
    rescue LoadError, NameError => _e
      nil
    end
  end.compact
end

#child_itemsObject



54
55
56
57
58
# File 'app/models/menu_renderer.rb', line 54

def child_items
  (allowed_child_classes - [self.class.default_child]).map do |child|
    menu_item(child)
  end
end

#default_child_itemObject



46
47
48
# File 'app/models/menu_renderer.rb', line 46

def default_child_item
  menu_item(default_child)
end


80
81
82
# File 'app/models/menu_renderer.rb', line 80

def disabled_add_child_link
  view. :span, view.image('plus_disabled') + ' Add Child', class: 'action disabled'
end

#excluded_class_namesObject



8
9
10
# File 'app/models/menu_renderer.rb', line 8

def excluded_class_names
  MenuRenderer.instance_variable_get(:@excluded_class_names)
end


60
61
62
# File 'app/models/menu_renderer.rb', line 60

def menu_items
  [default_child_item, separator_item] + child_items
end


64
65
66
# File 'app/models/menu_renderer.rb', line 64

def menu_list
  view. :ul, menu_items.join.html_safe, class: 'menu', id: "allowed_children_#{id}"
end


27
28
29
30
# File 'app/models/menu_renderer.rb', line 27

def menu_renderer_module_name
  simple_name = class_name.to_s.sub('Page', '')
  "#{simple_name}MenuRenderer"
end


32
33
34
# File 'app/models/menu_renderer.rb', line 32

def menu_renderer_modules
  [Object.const_get(menu_renderer_module_name)]
end


68
69
70
# File 'app/models/menu_renderer.rb', line 68

def remove_link
  view.link_to('<i class="fas fa-minus-circle"></i> '.html_safe + I18n.t('remove'), view.remove_admin_page_url(self), class: 'action')
end

#remove_optionObject



72
73
74
# File 'app/models/menu_renderer.rb', line 72

def remove_option
  remove_link
end

#separator_itemObject



50
51
52
# File 'app/models/menu_renderer.rb', line 50

def separator_item
  view. :li, '', class: 'separator'
end

#viewObject



19
20
21
# File 'app/models/menu_renderer.rb', line 19

def view
  @view
end

#view=(val) ⇒ Object



15
16
17
# File 'app/models/menu_renderer.rb', line 15

def view=(val)
  @view = val
end