From 7efaddf57cb78c3f9203de59e456c548f9147fa3 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 22 Mar 2012 10:11:02 +0800 Subject: [PATCH] Add ad_banner to nokogiri --- lib/parsers/parser_front_end.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 8ea3840a..529802ff 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -105,7 +105,7 @@ module ParserFrontEnd require 'nokogiri' def parse_page_noko(page, id = nil) - body = Nokogiri::HTML(page.design.layout.body, nil, 'UTF-8') + body = Nokogiri::HTML(page.design.layout.body) # page_contents body.css('.page_content').each do |content| @@ -165,6 +165,29 @@ module ParserFrontEnd page_image.swap(fragment) end + # ad_banner + body.css('ad_banner').each do |banner| + res = '' + ad_banner = AdBanner.find(banner["id"]) rescue nil + if ad_banner && ad_banner.display? + res << "" + res << "
" + ad_banner.ad_images.each do |ad_image| + res << "" + end + res << "
" + end + fragment = Nokogiri::HTML::DocumentFragment.new(body, res) + banner.swap(fragment) + end + body.to_html end