2011-12-23 10:34:21 +00:00
|
|
|
module ParserCommon
|
2012-05-07 05:33:29 +00:00
|
|
|
include ActionView::Helpers::TagHelper
|
|
|
|
|
2012-05-08 13:46:24 +00:00
|
|
|
def menu_level(page, current_page_id, current, menu, edit = false)
|
2012-01-24 03:38:53 +00:00
|
|
|
res = ''
|
2012-05-08 02:50:09 +00:00
|
|
|
if page.ordered_and_visible_children.size > 0
|
2012-05-07 07:11:43 +00:00
|
|
|
res << "<ul class='"
|
|
|
|
res << menu.values["class_#{current}"] rescue nil
|
|
|
|
res << "'>"
|
|
|
|
i = nil
|
|
|
|
i = 1 if menu.values["li_incremental_#{current}"]
|
|
|
|
if menu.values['home'] && current == 1
|
2012-05-08 13:46:24 +00:00
|
|
|
res << menu_li(page, current_page_id, current, menu, i, edit)
|
2011-12-23 10:34:21 +00:00
|
|
|
end
|
2012-05-07 07:11:43 +00:00
|
|
|
page.ordered_and_visible_children.each do |child|
|
2012-05-08 13:46:24 +00:00
|
|
|
res << menu_li(child, current_page_id, current, menu, i, edit)
|
2012-05-07 07:11:43 +00:00
|
|
|
i += 1 if i
|
|
|
|
end
|
|
|
|
res << "</ul>"
|
2011-12-23 10:34:21 +00:00
|
|
|
end
|
2012-04-27 03:02:56 +00:00
|
|
|
res
|
2011-12-23 10:34:21 +00:00
|
|
|
end
|
|
|
|
|
2012-05-08 13:46:24 +00:00
|
|
|
def menu_li(page, current_page_id, current, menu, i, edit)
|
|
|
|
res = "<li class='"
|
2012-05-07 07:11:43 +00:00
|
|
|
res << menu.values["li_class_#{current}"] rescue nil
|
2011-12-23 10:34:21 +00:00
|
|
|
res << "_#{i}" if i
|
2012-05-08 13:46:24 +00:00
|
|
|
res << " active" if page.id.eql?(current_page_id)
|
|
|
|
res << "'>"
|
2012-05-07 07:11:43 +00:00
|
|
|
res << "<a href='#{edit ? admin_page_path(page.id) : page.full_name}'><span>#{page.i18n_variable[I18n.locale]}</span></a>"
|
|
|
|
if page.ordered_and_visible_children.size > 0 && current <= menu.levels
|
|
|
|
res << "<span class='dot'></span>"
|
2012-05-08 13:46:24 +00:00
|
|
|
res << menu_level(page, current_page_id, current + 1, menu, edit)
|
2012-05-07 07:11:43 +00:00
|
|
|
end unless (page.is_home? rescue nil)
|
2011-12-23 10:34:21 +00:00
|
|
|
res << "</li>"
|
|
|
|
end
|
|
|
|
|
2012-03-27 09:57:50 +00:00
|
|
|
# ad_banners
|
2012-05-08 20:15:45 +00:00
|
|
|
def parse_ad_banners(body = nil, page = nil, id = nil, edit=nil)
|
2012-03-27 09:57:50 +00:00
|
|
|
body.css('ad_banner').each do |banner|
|
|
|
|
res = ''
|
|
|
|
ad_banner = AdBanner.find(banner["id"]) rescue nil
|
2012-04-02 02:54:48 +00:00
|
|
|
if ad_banner
|
2012-03-27 09:57:50 +00:00
|
|
|
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}'>"
|
2012-04-01 15:39:49 +00:00
|
|
|
printable_ad_images = []
|
|
|
|
ad_banner.ad_images.each do |ad_image|
|
|
|
|
if ad_image.display?
|
|
|
|
ad_image.weight.times do
|
|
|
|
printable_ad_images << ad_image
|
|
|
|
end
|
2012-03-27 09:57:50 +00:00
|
|
|
end
|
2012-04-01 15:39:49 +00:00
|
|
|
end
|
|
|
|
printable_ad_images.shuffle!
|
|
|
|
printable_ad_images.each do |ad_image| #TODO Need Reflact
|
|
|
|
res << "<img src='#{ad_image.file}' "
|
|
|
|
res << "alt='#{ad_image.title || ' '}' "
|
2012-04-25 10:03:30 +00:00
|
|
|
res << "time_to_next='#{ad_banner.transition_msec}' "
|
2012-04-01 15:39:49 +00:00
|
|
|
res << "link_open='#{ad_image.link_open}' "
|
|
|
|
# res << "link_url='#{(ad_image.direct_to_after_click?? ad_image.out_link : ad_banner.context) || ' '}' "
|
|
|
|
res << "link_url='#{(ad_image.out_link || ad_banner.context || ' ')}' "
|
|
|
|
res << "/>"
|
|
|
|
end
|
2012-03-27 09:57:50 +00:00
|
|
|
res << "</div>"
|
|
|
|
end
|
|
|
|
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
|
|
|
|
banner.swap(fragment)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# page_images
|
2012-05-08 20:15:45 +00:00
|
|
|
def parse_images(body, page, id = nil, edit=nil)
|
2012-03-27 09:57:50 +00:00
|
|
|
body.css('.page_image').each do |page_image|
|
|
|
|
# image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) }
|
|
|
|
# image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
|
2012-04-06 09:31:22 +00:00
|
|
|
image = page.design.images.detect{|image| image.name.eql?(File.basename(page_image['src'])) } unless image
|
2012-03-27 09:57:50 +00:00
|
|
|
if image
|
|
|
|
res = "<img src=#{image.file.url} "
|
|
|
|
page_image.attributes.each do |l|
|
|
|
|
res << "#{l[0]}='#{l[1]}' "
|
|
|
|
end
|
|
|
|
res << '>'
|
|
|
|
end
|
|
|
|
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
|
|
|
|
page_image.swap(fragment)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# page_menu
|
|
|
|
def parse_menu(body, page, edit=nil)
|
|
|
|
page_menu = body.css('.page_menu').first
|
|
|
|
home = get_homepage
|
|
|
|
menu = page.design.layout.menu
|
2012-05-08 13:46:24 +00:00
|
|
|
fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page.id, 1, menu, edit))
|
2012-03-27 09:57:50 +00:00
|
|
|
page_menu.swap(fragment)
|
|
|
|
end
|
|
|
|
|
2012-04-23 18:30:40 +00:00
|
|
|
# sub_menus
|
2012-05-08 20:15:45 +00:00
|
|
|
def parse_sub_menus(body = nil, page = nil, id = nil, edit=nil)
|
2012-04-23 18:30:40 +00:00
|
|
|
body.css('sub_menu').each do |sub_menu|
|
2012-05-08 20:15:45 +00:00
|
|
|
menu_page = Page.find(sub_menu['id'])
|
2012-04-23 18:30:40 +00:00
|
|
|
res = ''
|
2012-04-24 03:26:36 +00:00
|
|
|
res << "<div class='category_list'>"
|
2012-05-08 20:15:45 +00:00
|
|
|
res << "<h3 class='h3'>#{menu_page.i18n_variable[I18n.locale]}</h3>"
|
2012-04-24 03:26:36 +00:00
|
|
|
res << "<ul class='list'>"
|
2012-05-08 20:15:45 +00:00
|
|
|
menu_page.ordered_and_visible_children.each do |child|
|
|
|
|
res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>"
|
|
|
|
res << "<a href='#{edit ? admin_page_path(child.id) : child.full_name}'>#{child.i18n_variable[I18n.locale]}</a>"
|
2012-04-23 18:30:40 +00:00
|
|
|
res << "</li>"
|
|
|
|
end
|
|
|
|
res << "</ul>"
|
2012-04-24 03:26:36 +00:00
|
|
|
res << "</h3>"
|
|
|
|
res << "</div>"
|
2012-04-23 18:30:40 +00:00
|
|
|
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
|
|
|
|
sub_menu.swap(fragment)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-08 09:27:02 +00:00
|
|
|
# page_footer
|
2012-05-07 05:33:29 +00:00
|
|
|
def parse_footer(body, page, edit=nil)
|
|
|
|
page_footer = body.css('.page_footer').first
|
2012-05-08 09:27:02 +00:00
|
|
|
if page_footer
|
|
|
|
res = "<div id='#{page_footer['id']}', class='#{page_footer['class']}'>"
|
|
|
|
res << @site.footer[I18n.locale] rescue nil
|
|
|
|
res << "</div>"
|
|
|
|
fragment = Nokogiri::HTML::DocumentFragment.new(body ,res)
|
|
|
|
page_footer.swap(fragment) rescue nil
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# page_sub_menu
|
|
|
|
def parse_sub_menu(body, page, edit=nil)
|
|
|
|
page_sub_menu = body.css('.page_sub_menu').first
|
|
|
|
if page_sub_menu
|
|
|
|
res = "<div id='#{page_sub_menu['id']}', class='#{page_sub_menu['class']}'>"
|
|
|
|
res << @site.sub_menu[I18n.locale] rescue nil
|
|
|
|
res << "</div>"
|
|
|
|
fragment = Nokogiri::HTML::DocumentFragment.new(body ,res)
|
|
|
|
page_sub_menu.swap(fragment) rescue nil
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
2012-05-07 05:33:29 +00:00
|
|
|
end
|
|
|
|
|
2011-12-23 10:34:21 +00:00
|
|
|
end
|