Class: DcBigMenuRenderer
- Inherits:
-
Object
- Object
- DcBigMenuRenderer
- Includes:
- CmsCommonHelper, DcApplicationHelper
- Defined in:
- app/renderers/dc_big_menu_renderer.rb
Overview
dc_big_menu is experimental menu system which can be used as alternative to dc_menu when sub menu menu level is larger than two levels. Idea is to have top two levels of menu displayed on standard top of page position with other sub levels displayed vertically on left or right part of page. Renderer also provides path method, which can be used to show menu path of currently displayed page.
Instance Attribute Summary
Attributes included from DcApplicationHelper
#design, #form, #ids, #json_ld, #menu, #menu_item, #options, #page, #page_title, #part, #parts, #record, #record_footer, #site, #tables
Instance Method Summary collapse
-
#default ⇒ Object
Default methods renders top two levels of menu on top of page.
-
#find_selected ⇒ Object
Find out which top level menu currently displayed page belongs to.
-
#initialize(parent, opts) ⇒ DcBigMenuRenderer
constructor
Object initialization.
-
#left_menu ⇒ Object
Renderer for menu part displayed on left position of page.
-
#link_4edit ⇒ Object
Creates edit link if in edit mode.
-
#link_4menu(item) ⇒ Object
Returns html code for single link on a menu.
-
#path ⇒ Object
Renders menu path for currently selected page.
-
#render_css ⇒ Object
Return CSS part of code.
-
#render_html ⇒ Object
Renderer dispatcher.
Methods included from CmsCommonHelper
#dc_choices4_field, #dc_choices_for_field, dc_choices_for_field, #dc_date_time, #dc_format_date_time, dc_format_date_time, #dc_format_number, dc_format_number, #dc_help_body, #dc_help_button, #dc_help_fields, #dc_help_for_tab, #dc_icon4_boolean, #dc_icon_for_boolean, #dc_name4_id, #dc_name4_value, #dc_name_for_id, #dc_name_for_value, dc_name_for_value, #dc_steps_menu_get, #t, t, #t_label_for_column, #t_label_for_field, #t_tablename
Methods included from DcApplicationHelper
#_origin, #dc_add2_record_cookie, #dc_add_json_ld, #dc_add_meta_tag, #dc_big_table, #dc_big_table_name_for_value, #dc_choices4, #dc_choices4_all_collections, #dc_choices4_folders_list, #dc_choices4_menu, #dc_choices4_site_policies, #dc_cms_menu, #dc_deprecate, #dc_document_path, #dc_dont?, #dc_edit_mode?, #dc_edit_title, #dc_error_messages_for, #dc_flash_messages, #dc_get_json_ld, #dc_get_link_canonical_tag, #dc_get_seo_meta_tags, #dc_get_site, #dc_icon_for_link, #dc_iframe_edit, #dc_img_alt, #dc_img_alt_tag, #dc_internal_var, #dc_limit_string, #dc_link_for_create, #dc_link_for_edit, #dc_link_for_edit1, #dc_link_menu_tag, #dc_link_to, #dc_menu_class, #dc_new_title, #dc_page_bottom, #dc_page_class, #dc_page_edit_menu, #dc_page_top, #dc_render, #dc_render_design, #dc_render_design_part, #dc_render_from_site, #dc_render_partial, #dc_replace_in_design, #dc_submit_tag, #dc_table_title, #dc_user_can_view, #dc_user_has_role, #dc_warning_messages_for, #decamelize_type
Constructor Details
#initialize(parent, opts) ⇒ DcBigMenuRenderer
Object initialization.
38 39 40 41 42 43 |
# File 'app/renderers/dc_big_menu_renderer.rb', line 38 def initialize( parent, opts ) #:nodoc: @parent = parent @site = parent.dc_get_site @opts = opts self end |
Instance Method Details
#default ⇒ Object
Default methods renders top two levels of menu on top of page.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/renderers/dc_big_menu_renderer.rb', line 139 def default html = '<div class="menu0-div"><ul>' @selected = find_selected level_0 = DcBigMenu.where(dc_site_id: @site._id, parent: nil, active: true).sort(order: 1).to_a level_0.each do |item| # menu can be hidden from user can_view, msg = dc_user_can_view(@parent, item) next unless can_view klas = item.id == @selected.id ? "menu0-selected" : "menu0-item" html << "<li class='#{klas}'>#{ (item) }</li>\n" end html << "</ul></div>" # submenu level_1 = DcBigMenu.where(dc_site_id: @site._id, parent: @selected.id, active: true).sort(order: 1).to_a html << "<div class='menu1-div'><ul>\n" level_1.each do |item1| can_view, msg = dc_user_can_view(@parent, item1) next unless can_view html << " <li class='menu1-item'>#{(item1)}</li>\n" end html << '</ul></div>' end |
#find_selected ⇒ Object
Find out which top level menu currently displayed page belongs to. Subroutine of default method.
48 49 50 51 52 53 54 |
# File 'app/renderers/dc_big_menu_renderer.rb', line 48 def find_selected #:nodoc: ret = DcBigMenu.find( @parent.page. ) if @parent.page. while ret and ret.parent != nil ret = DcBigMenu.find( ret.parent ) end ret || DcBigMenu.where(dc_site_id: @site._id, parent: nil, active: true).limit(1).first end |
#left_menu ⇒ Object
Renderer for menu part displayed on left position of page.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/renderers/dc_big_menu_renderer.rb', line 89 def html = '' = DcBigMenu.find( @parent.page. ) # Show menu on same level if selected has no children if DcBigMenu.where( parent: @parent.page. ).limit(1).to_a.size == 0 = DcBigMenu.find( m.parent ) end html << "<div class='menu-left-item-top'>#{.}</div>" DcBigMenu.where( parent: .id ).order(order: 1).each do |item| html << (item._id == @parent.page. ? '<div class="menu-left-item-selected">' : '<div class="menu-left-item">') html << (item) html << '</div>' end html << "<div class='menu-left-item-bottom'>" if .parent parent = DcBigMenu.find( .parent ) html << "▲ #{(parent)}" end html << ' </div>' end |
#link_4edit ⇒ Object
Creates edit link if in edit mode.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/renderers/dc_big_menu_renderer.rb', line 59 def link_4edit #:nodoc: html = '' return html unless @opts[:edit_mode] > 1 @opts[:editparams].merge!( { table: 'dc_big_menu', controller: 'cmsedit', action: 'edit' } ) title = "#{t('drgcms.edit')}: " @opts[:editparams].merge!( { id: @menu.id, title: "#{title}#{@menu.name}" } ) if @menu title << t('helpers.label.dc_big_menu.tabletitle') @opts[:editparams].merge!( { action: 'index', title: title }) if @menu.nil? html << dc_link_for_edit( @opts[:editparams] ) end |
#link_4menu(item) ⇒ Object
Returns html code for single link on a menu.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/renderers/dc_big_menu_renderer.rb', line 74 def (item) #:nodoc: html = '' link = item.link link = "/#{@site.route_name}/#{item.page_id}" #if link.blank? html << @parent.link_to(item.picture, link) unless item.picture.blank? html << if !item..blank? # TODO Translation @parent.link_to(item., link) end end |
#path ⇒ Object
Renders menu path for currently selected page.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/renderers/dc_big_menu_renderer.rb', line 115 def path html = '' a = [] m = DcBigMenu.find( @parent.page. ) a << m while m.parent m = DcBigMenu.find( m.parent ) a << m end (a.size - 1).downto(0) do |i| html << "<span id=menu-path-#{a.size - 1 - i}>" html << (a[i]) html << (i > 0 ? ' » ' : '') #›➔ html << '</span>' end # Save level to parents params object @parent.params[:menu_level] = a.size html end |
#render_css ⇒ Object
Return CSS part of code.
175 176 177 |
# File 'app/renderers/dc_big_menu_renderer.rb', line 175 def render_css @menu ? "#{@menu.css}\n #{@selected ? @selected.css : ''}\n" : '' end |
#render_html ⇒ Object
Renderer dispatcher. Method returns HTML part of code.
167 168 169 170 |
# File 'app/renderers/dc_big_menu_renderer.rb', line 167 def render_html method = @opts[:method] || 'default' respond_to?(method) ? send(method) : "Error DcBigMenu: Method #{method} doesn't exist!" end |