Fix bugs in sub_menu
This commit is contained in:
parent
9ead6cafda
commit
909ca19456
|
@ -29,7 +29,7 @@ class Page < Item
|
||||||
def create_parts
|
def create_parts
|
||||||
page_design = self.design
|
page_design = self.design
|
||||||
parent = self.parent
|
parent = self.parent
|
||||||
menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)}
|
menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent
|
||||||
page_design.layout.layout_parts.each do |layout_part|
|
page_design.layout.layout_parts.each do |layout_part|
|
||||||
current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)}
|
current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)}
|
||||||
current_part = self.page_parts.build(:name => layout_part.name) unless current_part
|
current_part = self.page_parts.build(:name => layout_part.name) unless current_part
|
||||||
|
|
|
@ -111,19 +111,21 @@ module ParserCommon
|
||||||
# sub_menus
|
# sub_menus
|
||||||
def parse_sub_menus(body = nil, page = nil, id = nil, edit=nil)
|
def parse_sub_menus(body = nil, page = nil, id = nil, edit=nil)
|
||||||
body.css('sub_menu').each do |sub_menu|
|
body.css('sub_menu').each do |sub_menu|
|
||||||
menu_page = Page.find(sub_menu['id'])
|
menu_page = Page.find(sub_menu['id']) rescue nil
|
||||||
res = ''
|
res = ''
|
||||||
res << "<div class='category_list'>"
|
if menu_page && menu_page.ordered_and_visible_children.size > 0
|
||||||
res << "<h3 class='h3'>#{menu_page.i18n_variable[I18n.locale]}</h3>"
|
res << "<div class='category_list'>"
|
||||||
res << "<ul class='list'>"
|
res << "<h3 class='h3'>#{menu_page.i18n_variable[I18n.locale]}</h3>"
|
||||||
menu_page.ordered_and_visible_children.each do |child|
|
res << "<ul class='list'>"
|
||||||
res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>"
|
menu_page.ordered_and_visible_children.each do |child|
|
||||||
res << "<a href='#{edit ? admin_page_path(child.id) : child.full_name}'>#{child.i18n_variable[I18n.locale]}</a>"
|
res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>"
|
||||||
res << "</li>"
|
res << "<a href='/#{edit ? admin_page_path(child.id) : child.full_name}'>#{child.i18n_variable[I18n.locale]}</a>"
|
||||||
|
res << "</li>"
|
||||||
|
end
|
||||||
|
res << "</ul>"
|
||||||
|
res << "</h3>"
|
||||||
|
res << "</div>"
|
||||||
end
|
end
|
||||||
res << "</ul>"
|
|
||||||
res << "</h3>"
|
|
||||||
res << "</div>"
|
|
||||||
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
|
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
|
||||||
sub_menu.swap(fragment)
|
sub_menu.swap(fragment)
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue