module ParserFrontEnd require 'nokogiri' def parse_page_noko(page, site) i18n = {} Site.first.valid_locales.each do |locale| body = Nokogiri::HTML(page.design.layout.body) parse_contents(body, page, locale) parse_footer(body, page, site) parse_images(body, page) parse_menu(body, page) parse_sub_menu(body, page, site) i18n.merge!({locale => body.to_html}) end i18n end def parse_page_content(page) category = params[:category_id].blank? ? page[:category] : params[:category_id] tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id] body = Nokogiri::HTML(page.content) body.css('orbit_front').each do |front| ret = '' part = PagePart.find(front['part_id']) if front['part_id'] ret << eval("\"#{front['path']}\"") rescue '' fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") front.swap(fragment) end body.to_html end # page_footer def parse_footer(body, page, site) page_footer = body.css('.page_footer').first if page_footer res = " " fragment = Nokogiri::HTML::DocumentFragment.new(body, res) page_footer.swap(fragment) rescue nil else '' end end # page_images def parse_images(body, page, edit=nil) body.css('.page_image').each do |page_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) page_menu = body.css('.page_menu').first if page_menu fragment = Nokogiri::HTML::DocumentFragment.new(body, "") page_menu.swap(fragment) else '' end end # page_sub_menu def parse_sub_menu(body, page, site) page_sub_menu = body.css('.page_sub_menu').first if page_sub_menu res = " " fragment = Nokogiri::HTML::DocumentFragment.new(body, res) page_sub_menu.swap(fragment) else '' end end # page_contents def parse_contents(body, page, edit=nil, locale) public_r_tags = [] body.css('.page_content').each do |content| ret = '' if (content["main"] == "true" && !page.module_app.nil?) url = "/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}\#{(\"/\" + params[:id]) if params[:id] && !params[:id].eql?(page.id.to_s)}?inner=true" options = "&page_id=#{page.id}&category_id=\#{category}&tag_id=\#{tag}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&name=\#{params[:name]}" ret << "