Fix Nokogiri when '.first' returns nothing
This commit is contained in:
parent
747b0d4620
commit
3beed406a7
|
@ -112,10 +112,14 @@ module ParserCommon
|
||||||
# page_menu
|
# page_menu
|
||||||
def parse_menu(body, page, edit=nil)
|
def parse_menu(body, page, edit=nil)
|
||||||
page_menu = body.css('.page_menu').first
|
page_menu = body.css('.page_menu').first
|
||||||
|
if page_menu
|
||||||
home = get_homepage
|
home = get_homepage
|
||||||
menu = page.design.layout.menu
|
menu = page.design.layout.menu
|
||||||
fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page, 1, menu, edit))
|
fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page, 1, menu, edit))
|
||||||
page_menu.swap(fragment)
|
page_menu.swap(fragment)
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# sub_menus
|
# sub_menus
|
||||||
|
@ -173,10 +177,14 @@ module ParserCommon
|
||||||
# sitemap
|
# sitemap
|
||||||
def parse_sitemaps(body = nil, page = nil, edit=nil)
|
def parse_sitemaps(body = nil, page = nil, edit=nil)
|
||||||
sitemap = body.css('sitemap').first
|
sitemap = body.css('sitemap').first
|
||||||
|
if sitemap
|
||||||
url = admin_site_sitemap_frontend_path(@site)
|
url = admin_site_sitemap_frontend_path(@site)
|
||||||
options = "?inner=true"
|
options = "?inner=true"
|
||||||
fragment = Nokogiri::HTML::DocumentFragment.new(body, "<div class='dymanic_load' path='#{url + options}'></div>")
|
fragment = Nokogiri::HTML::DocumentFragment.new(body, "<div class='dymanic_load' path='#{url + options}'></div>")
|
||||||
sitemap.swap(fragment)
|
sitemap.swap(fragment)
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# page_contents
|
# page_contents
|
||||||
|
|
Loading…
Reference in New Issue