29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/helpers/effective_menus_helper.rb', line 29
def (items, options = {}, &block)
if options[:form].present? && options[:form].kind_of?(ActionView::Helpers::FormBuilder) == false
raise 'Expecting ActionView::Helpers::FormBuilder object for :form => option'
end
html = ''
if options[:form]
html << "<ul class='nav navbar-nav effective-menu #{options[:class]}'"
html << " data-effective-menu-id='#{options[:menu_id] || 0}'"
html << " data-effective-menu-expand-html=\"#{render(:partial => 'admin/menu_items/expand').gsub('"', "'").gsub("\n", '').gsub(' ', '')}\""
html << " data-effective-menu-new-html=\"#{render(:partial => 'admin/menu_items/new', :locals => { :item => Effective::MenuItem.new(), :form => options[:form] }).gsub('"', "'").gsub("\n", '').gsub(' ', '').gsub('[0]', '[:new]').gsub('_0_', '_:new_')}\""
maxdepth = ((options[:maxdepth].presence || EffectivePages.[:maxdepth].presence).to_i rescue 0)
html << " data-effective-menu-maxdepth='#{maxdepth}'" if maxdepth > 0
html << ">"
else
html << "<ul class='nav navbar-nav#{' ' + options[:class].to_s if options[:class].present?}'>"
end
stack = [items.to_a.first] skip_to_lft = 0
items.each_with_index do |item, index|
next if index == 0
next if item.lft < skip_to_lft
if options[:form].blank? && !item.visible_for?(defined?(current_user) ? current_user : nil)
skip_to_lft = item.rgt + 1
next
end
if stack.size > 1
html << "<ul class='dropdown-menu'>" if (item.rgt < stack.last.rgt)
while item.rgt > stack.last.rgt stack.pop
html << "</ul></li>" if (item.rgt > stack.last.rgt)
end
end
html << (item, stack.size == 1, options)
stack.push(item)
end
while stack.size > 0
item = stack.pop
if stack.size == 0 html << render(:partial => 'admin/menu_items/actions') if options[:form]
html << (capture(&block) || '') if block_given? && !options[:form]
html << '</ul>'
elsif item.leaf? == false
html << '</ul></li>'
end
end
html.html_safe
end
|