Module: MenuRenderer
- Defined in:
- app/models/menu_renderer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_child_disabled? ⇒ Boolean
- #add_child_link ⇒ Object
- #add_child_link_with_menu ⇒ Object
- #add_child_link_with_menu_hook ⇒ Object
- #add_child_menu ⇒ Object
- #add_child_option ⇒ Object
- #additional_menu_features? ⇒ Boolean
- #allowed_child_classes ⇒ Object
- #child_items ⇒ Object
- #default_child_item ⇒ Object
- #disabled_add_child_link ⇒ Object
- #excluded_class_names ⇒ Object
- #menu_items ⇒ Object
- #menu_list ⇒ Object
- #menu_renderer_module_name ⇒ Object
- #menu_renderer_modules ⇒ Object
- #remove_link ⇒ Object
- #remove_option ⇒ Object
- #separator_item ⇒ Object
- #view ⇒ Object
- #view=(val) ⇒ Object
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_names ⇒ Object
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
76 77 78 |
# File 'app/models/menu_renderer.rb', line 76 def add_child_disabled? allowed_child_classes.size == 0 end |
#add_child_link ⇒ Object
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 |
#add_child_link_with_menu ⇒ Object
96 97 98 |
# File 'app/models/menu_renderer.rb', line 96 def + end |
#add_child_link_with_menu_hook ⇒ Object
88 89 90 |
# File 'app/models/menu_renderer.rb', line 88 def view.link_to('<i class="fas fa-plus-circle"></i> Add Child'.html_safe, "#allowed_children_#{id}", class: 'action dropdown') end |
#add_child_menu ⇒ Object
92 93 94 |
# File 'app/models/menu_renderer.rb', line 92 def end |
#add_child_option ⇒ Object
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 end end end |
#additional_menu_features? ⇒ Boolean
23 24 25 |
# File 'app/models/menu_renderer.rb', line 23 def @additional_menu_features ||= ( != 'MenuRenderer' && Object.const_defined?()) end |
#allowed_child_classes ⇒ Object
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_items ⇒ Object
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| (child) end end |
#default_child_item ⇒ Object
46 47 48 |
# File 'app/models/menu_renderer.rb', line 46 def default_child_item (default_child) end |
#disabled_add_child_link ⇒ Object
80 81 82 |
# File 'app/models/menu_renderer.rb', line 80 def disabled_add_child_link view.content_tag :span, view.image('plus_disabled') + ' Add Child', class: 'action disabled' end |
#excluded_class_names ⇒ Object
8 9 10 |
# File 'app/models/menu_renderer.rb', line 8 def excluded_class_names MenuRenderer.instance_variable_get(:@excluded_class_names) end |
#menu_items ⇒ Object
60 61 62 |
# File 'app/models/menu_renderer.rb', line 60 def [default_child_item, separator_item] + child_items end |
#menu_list ⇒ Object
64 65 66 |
# File 'app/models/menu_renderer.rb', line 64 def view.content_tag :ul, .join.html_safe, class: 'menu', id: "allowed_children_#{id}" end |
#menu_renderer_module_name ⇒ Object
27 28 29 30 |
# File 'app/models/menu_renderer.rb', line 27 def simple_name = class_name.to_s.sub('Page', '') "#{simple_name}MenuRenderer" end |
#menu_renderer_modules ⇒ Object
32 33 34 |
# File 'app/models/menu_renderer.rb', line 32 def [Object.const_get()] end |
#remove_link ⇒ Object
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_option ⇒ Object
72 73 74 |
# File 'app/models/menu_renderer.rb', line 72 def remove_option remove_link end |
#separator_item ⇒ Object
50 51 52 |
# File 'app/models/menu_renderer.rb', line 50 def separator_item view.content_tag :li, '', class: 'separator' end |
#view ⇒ Object
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 |