module ParserCommon include ActionView::Helpers::TagHelper def menu_level(page, current_page, current, menu, edit = false) res = '' if page.visible_children.size > 0 res << "" end res end def menu_li(page, current_page, current, menu, i, edit) res = "" end # ad_banners def parse_ad_banners(body = nil, page = nil, edit=nil) body.css('ad_banner').each do |banner| res = '' ad_banner = AdBanner.find(banner["id"]) rescue nil if ad_banner res << "" res << "" res << "
" 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 end end printable_ad_images.shuffle! printable_ad_images.each do |ad_image| #TODO Need Reflact res << "" end res << "
" end fragment = Nokogiri::HTML::DocumentFragment.new(body, res) banner.swap(fragment) end end # page_images def parse_images(body, page, edit=nil) 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 image = page.design.images.detect{|image| image.name.eql?(File.basename(page_image['src'])) } unless image if image 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 fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page, 1, menu, edit)) page_menu.swap(fragment) end # sub_menus def parse_sub_menus(body = nil, page = nil, edit=nil) body.css('sub_menu').each do |sub_menu| menu_page = Page.find(sub_menu['id']) rescue nil res = '' if menu_page && menu_page.visible_children.size > 0 res << "
" res << "

#{menu_page.i18n_variable[I18n.locale]}

" res << "" res << "" res << "
" end fragment = Nokogiri::HTML::DocumentFragment.new(body, res) sub_menu.swap(fragment) end end # page_footer def parse_footer(body, page) page_footer = body.css('.page_footer').first if page_footer res = "
" res << @site.footer[I18n.locale] rescue nil res << "
" 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) page_sub_menu = body.css('.page_sub_menu').first if page_sub_menu res = "
" res << @site.sub_menu[I18n.locale] rescue nil res << "
" fragment = Nokogiri::HTML::DocumentFragment.new(body ,res) page_sub_menu.swap(fragment) rescue nil else '' end end # page_contents def parse_contents(body, page, edit=nil) public_r_tags = [] body.css('.page_content').each do |content| ret = '' if (content["main"] == "true" && !page.module_app.nil?) ret << "
" else part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil part_title = part.title[I18n.locale] rescue nil if edit ret << "
" if part ret << "' end case part.kind when 'text' ret << part.i18n_variable[I18n.locale] rescue '' when 'module_widget' url = "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" options = "&category_id=#{!part[:category].blank? ? part[:category].blank? : params[:category_id]}&tag_id=#{!part[:tag].blank? ? part[:tag] : params[:tag_id]}&page=#{params[:page]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}" ret << "
" when 'public_r_tag' ret << "" public_r_tags << part.public_r_tag else '' end if part end scope = "<#{content.name}" content.attributes.each_pair do |key, value| scope << " #{key}='#{value}'" end scope << ">#{ret}" fragment = Nokogiri::HTML::DocumentFragment.new(body, scope) content.swap(fragment) end public_r_tags.uniq end end