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
3 4 5 6 |
# File 'app/models/menu_renderer.rb', line 3 def exclude(*type_names) @excluded_class_names ||= [] @excluded_class_names.concat(type_names).uniq! end |
.excluded_class_names ⇒ Object
9 10 11 |
# File 'app/models/menu_renderer.rb', line 9 def excluded_class_names MenuRenderer.instance_variable_get(:@excluded_class_names) end |
Instance Method Details
#add_child_disabled? ⇒ Boolean
78 79 80 |
# File 'app/models/menu_renderer.rb', line 78 def add_child_disabled? allowed_child_classes.size == 0 end |
#add_child_link ⇒ Object
86 87 88 |
# File 'app/models/menu_renderer.rb', line 86 def add_child_link view.link_to((view.image('plus') + ' Add Child'), view.new_admin_page_child_path(self, :page_class => default_child.name), :class => "action") end |
#add_child_link_with_menu ⇒ Object
98 99 100 |
# File 'app/models/menu_renderer.rb', line 98 def + end |
#add_child_link_with_menu_hook ⇒ Object
90 91 92 |
# File 'app/models/menu_renderer.rb', line 90 def view.link_to((view.image('plus') + ' Add Child'), "#allowed_children_#{id}", :class => "action dropdown") end |
#add_child_menu ⇒ Object
94 95 96 |
# File 'app/models/menu_renderer.rb', line 94 def end |
#add_child_option ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/menu_renderer.rb', line 102 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
24 25 26 |
# File 'app/models/menu_renderer.rb', line 24 def @additional_menu_features ||= ( != 'MenuRenderer' && Object.const_defined?()) end |
#allowed_child_classes ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/models/menu_renderer.rb', line 37 def allowed_child_classes (allowed_children_cache.to_s.split(',') - Array(excluded_class_names)).map do |name| begin name.constantize rescue LoadError, NameError => _ nil end end.compact end |
#child_items ⇒ Object
56 57 58 59 60 |
# File 'app/models/menu_renderer.rb', line 56 def child_items (allowed_child_classes - [self.class.default_child]).map do |child| (child) end end |
#default_child_item ⇒ Object
48 49 50 |
# File 'app/models/menu_renderer.rb', line 48 def default_child_item (default_child) end |
#disabled_add_child_link ⇒ Object
82 83 84 |
# File 'app/models/menu_renderer.rb', line 82 def disabled_add_child_link view.content_tag :span, view.image('plus_disabled') + ' Add Child', :class => 'action disabled' end |
#excluded_class_names ⇒ Object
9 10 11 |
# File 'app/models/menu_renderer.rb', line 9 def excluded_class_names MenuRenderer.instance_variable_get(:@excluded_class_names) end |
#menu_items ⇒ Object
62 63 64 |
# File 'app/models/menu_renderer.rb', line 62 def [default_child_item, separator_item] + child_items end |
#menu_list ⇒ Object
66 67 68 |
# File 'app/models/menu_renderer.rb', line 66 def view.content_tag :ul, .join.html_safe, :class => 'menu', :id => "allowed_children_#{id}" end |
#menu_renderer_module_name ⇒ Object
28 29 30 31 |
# File 'app/models/menu_renderer.rb', line 28 def simple_name = self.class_name.to_s.sub('Page','') "#{simple_name}MenuRenderer" end |
#menu_renderer_modules ⇒ Object
33 34 35 |
# File 'app/models/menu_renderer.rb', line 33 def [Object.const_get()] end |
#remove_link ⇒ Object
70 71 72 |
# File 'app/models/menu_renderer.rb', line 70 def remove_link view.link_to view.image('minus') + ' ' + I18n.t('remove'), view.remove_admin_page_url(self), :class => "action" end |
#remove_option ⇒ Object
74 75 76 |
# File 'app/models/menu_renderer.rb', line 74 def remove_option remove_link end |
#separator_item ⇒ Object
52 53 54 |
# File 'app/models/menu_renderer.rb', line 52 def separator_item view.content_tag :li, '', :class => 'separator' end |
#view ⇒ Object
20 21 22 |
# File 'app/models/menu_renderer.rb', line 20 def view @view end |
#view=(val) ⇒ Object
16 17 18 |
# File 'app/models/menu_renderer.rb', line 16 def view=(val) @view = val end |