Add ad_banner to nokogiri

This commit is contained in:
Christophe Vilayphiou 2012-03-22 10:11:02 +08:00
parent f5fd3dec7a
commit 7efaddf57c
1 changed files with 24 additions and 1 deletions

View File

@ -105,7 +105,7 @@ module ParserFrontEnd
require 'nokogiri' require 'nokogiri'
def parse_page_noko(page, id = nil) 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 # page_contents
body.css('.page_content').each do |content| body.css('.page_content').each do |content|
@ -165,6 +165,29 @@ module ParserFrontEnd
page_image.swap(fragment) page_image.swap(fragment)
end 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 << "<script type='text/javascript'>
$(document).ready(function(){ $('#slideshow-#{ad_banner.title.dehumanize}').cycle({delay: -1000, fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}', timeoutFn: getTimeout }); });
</script>"
res << "<div id='slideshow-#{ad_banner.title.dehumanize}'>"
ad_banner.ad_images.each do |ad_image|
res << "<img src='#{ad_image.file}' "
res << "alt='#{ad_image.picture_intro || ' '}' "
res << "time_to_next='#{ad_image.get_delay_time}' "
res << "link_open='#{ad_image.link_open}' "
res << "link_url='#{(ad_banner.direct_to_after_click?? ad_image.out_link : ad_banner.context) || ' '}' "
res << "/>"
end
res << "</div>"
end
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
banner.swap(fragment)
end
body.to_html body.to_html
end end