From 3beed406a71b1243548608e8d7873ffd4ddc6afe Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 20 Nov 2012 12:00:18 +0800 Subject: [PATCH] Fix Nokogiri when '.first' returns nothing --- lib/parsers/parser_common.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 32b4405c..6364691e 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -112,10 +112,14 @@ module ParserCommon # page_menu def parse_menu(body, page, edit=nil) page_menu = body.css('.page_menu').first - home = get_homepage - menu = page.design.layout.menu - fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page, 1, menu, edit)) - page_menu.swap(fragment) + if page_menu + home = get_homepage + menu = page.design.layout.menu + fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page, 1, menu, edit)) + page_menu.swap(fragment) + else + '' + end end # sub_menus @@ -173,10 +177,14 @@ module ParserCommon # sitemap def parse_sitemaps(body = nil, page = nil, edit=nil) sitemap = body.css('sitemap').first - url = admin_site_sitemap_frontend_path(@site) - options = "?inner=true" - fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") - sitemap.swap(fragment) + if sitemap + url = admin_site_sitemap_frontend_path(@site) + options = "?inner=true" + fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") + sitemap.swap(fragment) + else + '' + end end # page_contents