From 4f741418a09516082210ea1138ee62495e9bda81 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 22 Mar 2012 01:51:16 +0800 Subject: [PATCH 1/3] Trying nokogiri --- Gemfile | 1 + Gemfile.lock | 4 + app/controllers/application_controller.rb | 2 +- app/controllers/pages_controller.rb | 2 + app/helpers/application_helper.rb | 47 ++++++++++ app/models/design/layout.rb | 8 +- app/models/meta.rb | 4 + app/views/layouts/page_layout.html.erb | 17 ++++ lib/parsers/parser_front_end.rb | 105 ++++++++++++++-------- lib/parsers/parser_layout.rb | 57 +++++------- 10 files changed, 172 insertions(+), 75 deletions(-) create mode 100644 app/views/layouts/page_layout.html.erb diff --git a/Gemfile b/Gemfile index 024f3449..d1afdb8c 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ gem 'kaminari', :git => 'git://github.com/amatsuda/kaminari.git' gem 'mini_magick' gem 'mongoid' gem "mongo_session_store-rails3" +gem 'nokogiri' gem 'radius' gem 'rake' gem 'ruby-debug19' diff --git a/Gemfile.lock b/Gemfile.lock index 1df648c4..71742974 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,7 @@ GEM archive-tar-minitar (0.5.2) arel (2.2.3) bcrypt-ruby (3.0.1) + bcrypt-ruby (3.0.1-x86-mingw32) brakeman (1.5.1) activesupport erubis (~> 2.6) @@ -115,6 +116,8 @@ GEM mongo (~> 1.3) tzinfo (~> 0.3.22) multi_json (1.1.0) + nokogiri (1.5.2) + nokogiri (1.5.2-x86-mingw32) orm_adapter (0.0.6) pdf-writer (1.1.8) color (>= 1.4.0) @@ -252,6 +255,7 @@ DEPENDENCIES mini_magick mongo_session_store-rails3 mongoid + nokogiri radius rails (>= 3.1.0, < 3.2.0) rake diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4b433777..fb82774e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -47,7 +47,7 @@ class ApplicationController < ActionController::Base # Render the page def render_page(id = nil) if @item - render :text => parse_page(@item, id) + render :text => process_page(@item, id), :layout => 'page_layout' else render :text => '404 Not Found' end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 8ea35391..4860ea2e 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,5 +1,7 @@ class PagesController < ApplicationController + include ApplicationHelper + before_filter :get_item, :only => [:index_from_link, :show_from_link] def index diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 50510e3c..9c03de3d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -107,4 +107,51 @@ module ApplicationHelper end end + + def process_page(page, id) + parse_page_noko(page, id) + end + + def page_metas(page) + metas = '' + @site.page_metas.each do |meta| + name, content = meta.get_name_content + metas << "\n" + end rescue nil + return metas + end + + def page_title(page) + "#{page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]}\n" + end + + def page_stylesheets(page) + stylesheets = '' + stylesheets << "\n" + stylesheets << "\n" + stylesheets << "\n" + stylesheets << "\n" if page.design.reset_css + stylesheets << "\n" if page.design.default_css + theme = page.design.themes.detect{ |d| d.id == page.theme_id } + stylesheets << "\n" if theme + stylesheets + end + + def page_javascripts(page) + javascripts = '' + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + javascripts << "\n" + page.design.javascripts.each do |js| + # javascripts << "" + end + javascripts + end + end diff --git a/app/models/design/layout.rb b/app/models/design/layout.rb index e13498f3..bf48415c 100644 --- a/app/models/design/layout.rb +++ b/app/models/design/layout.rb @@ -2,6 +2,8 @@ class Layout < DesignFile include ParserLayout attr_reader :content + + field :body embeds_one :menu embedded_in :design @@ -17,8 +19,10 @@ class Layout < DesignFile Layout.count > 0 end - def parse_layout - parse_layout_contents(self) + def parse_layout + html = Nokogiri::HTML(self.file.read) + self.body = html.at_css("body").inner_html + parse_body(self) end end diff --git a/app/models/meta.rb b/app/models/meta.rb index 411a4f0c..dbeac167 100644 --- a/app/models/meta.rb +++ b/app/models/meta.rb @@ -7,5 +7,9 @@ class Meta field :value, :default => nil has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy + + def get_name_content + [self.key, self.value ? self.value : self.i18n_variable[I18n.locale]] + end end diff --git a/app/views/layouts/page_layout.html.erb b/app/views/layouts/page_layout.html.erb new file mode 100644 index 00000000..8fb884b0 --- /dev/null +++ b/app/views/layouts/page_layout.html.erb @@ -0,0 +1,17 @@ + + + + + <%= page_title(@item).html_safe %> + <%= page_metas(@item).html_safe %> + <%= @metas %> + + <%= page_stylesheets(@item).html_safe %> + <%= page_javascripts(@item).html_safe %> + + + <%= yield %> + + diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 4b5a523f..8ea3840a 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -63,22 +63,6 @@ module ParserFrontEnd res << '>' end end - c.define_tag 'javascripts' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - res << "" - page.design.javascripts.each do |js| - # res << "" - end - res - end c.define_tag 'language_bar' do @site.in_use_locales.map{ |locale| lang = I18nVariable.first(:conditions => {:key => locale})[locale] @@ -101,38 +85,87 @@ module ParserFrontEnd menu = page.design.layout.menu menu_level(home, 0, menu) end - c.define_tag 'meta' do |tag| - res = '' - #res << "" - end - c.define_tag 'stylesheets' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" if page.design.reset_css - res << " " if page.design.default_css - theme = page.design.themes.detect{ |d| d.id == page.theme_id } - res << "" if theme - res - end - c.define_tag 'title' do |tag| - "#{page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]}" - end end end def parse_page(page, id = nil) if page._type == 'Page' - layout_content = page.design.layout.content.force_encoding('UTF-8') rescue '' context = parser_context(page, {}, id) parser = Radius::Parser.new(context, :tag_prefix => 'r') - parser.parse(parser.parse(layout_content)) + parser.parse(parser.parse(page.design.layout.body)) end end def self.included(base) base.send :helper_method, :parse_page if base.respond_to? :helper_method end + + + + require 'nokogiri' + + def parse_page_noko(page, id = nil) + body = Nokogiri::HTML(page.design.layout.body, nil, 'UTF-8') + + # page_contents + 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 + case part.kind + when 'text' + ret << part.i18n_variable[I18n.locale] rescue '' + when 'module_widget' + if part[:category] + ret << "
" + else + ret << "
" + end + when 'public_r_tag' + ret << "" + else + '' + end + 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 + + # page_menu + page_menu = body.css('.page_menu').first + home = get_homepage + menu = page.design.layout.menu + fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, 0, menu)) + page_menu.swap(fragment) + + # page_image + 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?(page_image['name']) } unless image + if image + res = "' + end + fragment = Nokogiri::HTML::DocumentFragment.new(body, res) + page_image.swap(fragment) + end + + body.to_html + end end diff --git a/lib/parsers/parser_layout.rb b/lib/parsers/parser_layout.rb index 063078df..01d681ef 100644 --- a/lib/parsers/parser_layout.rb +++ b/lib/parsers/parser_layout.rb @@ -1,44 +1,27 @@ module ParserLayout - require 'radius' - include ParserCommon + require 'nokogiri' - def parse_layout_contents(layout) - content = layout.content.force_encoding('UTF-8') - context = parser_layout_contents(layout) - parser = Radius::Parser.new(context, :tag_prefix => 'r') - parser.parse(content) - end - - def parser_layout_contents(layout) - Radius::Context.new do |c| - c.define_tag 'ad_banner' do |tag| - end - c.define_tag 'content' do |tag| - layout.layout_parts.new(:name => tag.attr['name']) - end - c.define_tag 'image' do |tag| - image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(tag.expand)) } - image.update_attributes(:name => tag.attr['name'], :html_id => tag.attr['id'], :html_class => tag.attr['class']) if image - end - c.define_tag 'javascripts' do |tag| - end - c.define_tag 'menu' do |tag| - layout.build_menu(:levels => 0, :values => {}) unless layout.menu - layout.menu.levels = i = tag.attr['level'].to_i - layout.menu.values.merge!({'home' => tag.attr['home']}) if i == 1 - layout.menu.values.merge!({"id_#{i}" => tag.attr['id'], "class_#{i}" => tag.attr['class'], "li_class_#{i}" => tag.attr['li_class'], "li_incremental_#{i}" => tag.attr['li_incremental']}) - tag.expand - end - c.define_tag 'meta' do |tag| - end - c.define_tag 'stylesheets' do |tag| - end - c.define_tag 'title' do |tag| - end + def parse_body(layout) + body = Nokogiri::HTML(layout.body) + body.css('.page_content').each do |content| + layout.layout_parts.build(:name => content['name']) end + + body.css('.page_image').each do |image| + image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(image.to_html)) } + image.update_attributes(:name => image['name'], :html_id => image['id'], :html_class => image['class']) if image + end + + body.css('.page_menu').each do |menu| + layout.build_menu(:levels => 0, :values => {}) unless layout.menu + layout.menu.levels = i = menu['level'].to_i + layout.menu.values.merge!({'home' => menu['home']}) if i == 1 + layout.menu.values.merge!({"id_#{i}" => menu['id'], "class_#{i}" => menu['class'], "li_class_#{i}" => menu['li_class'], "li_incremental_#{i}" => menu['li_incremental']}) + end + end - + def parse_html_image(html) html.scan(/(?<=\)/){ $1.gsub(' ','').scan(/(?<=src=\")(.*?)(?=\")/){ @@ -46,4 +29,6 @@ module ParserLayout } } end + + end From b109410a7aeb456f01bbd529e5eb1c6a2f2ef63f Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 22 Mar 2012 10:11:02 +0800 Subject: [PATCH 2/3] 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 From 48d1d45ced0f8481f25876fb847c9a713544ef11 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Tue, 27 Mar 2012 17:57:50 +0800 Subject: [PATCH 3/3] Nokogiri in parsers --- app/views/admin/pages/_show.html.erb | 6 +- lib/parsers/parser_back_end.rb | 190 ++++++++++----------------- lib/parsers/parser_common.rb | 52 ++++++++ lib/parsers/parser_front_end.rb | 183 +++++--------------------- 4 files changed, 162 insertions(+), 269 deletions(-) diff --git a/app/views/admin/pages/_show.html.erb b/app/views/admin/pages/_show.html.erb index 1937fe92..ba9bcf48 100644 --- a/app/views/admin/pages/_show.html.erb +++ b/app/views/admin/pages/_show.html.erb @@ -1,3 +1,7 @@ <%= flash_messages %> -<%= parse_page_edit(@item).html_safe %> \ No newline at end of file + +<%= page_stylesheets(@item).html_safe %> +<%= page_javascripts(@item).html_safe %> + +<%= parse_page_edit_noko(@item).html_safe %> \ No newline at end of file diff --git a/lib/parsers/parser_back_end.rb b/lib/parsers/parser_back_end.rb index 787f579b..3e641118 100644 --- a/lib/parsers/parser_back_end.rb +++ b/lib/parsers/parser_back_end.rb @@ -1,132 +1,86 @@ module ParserBackEnd - require 'radius' include ParserCommon - - def parse_page_edit(page) - if page._type == 'Page' - layout_content = page.design.layout.content.force_encoding('UTF-8') rescue '' - context = parser_context_edit(page) - parser = Radius::Parser.new(context, :tag_prefix => 'r') - parser.parse(parser.parse(layout_content)) + + require 'nokogiri' + + # c.define_tag 'language_bar' do + # @site.in_use_locales.map{ |locale| + # lang = I18nVariable.first(:conditions => {:key => locale})[locale] + # if I18n.locale.to_s.eql?(locale) + # lang + # else + # "#{lang}" + # end + # }.join(' | ') + # end + # c.define_tag 'link' do |tag| + # item = Item.first(:conditions => { :full_name => tag.attr['name'] }) + # ret = '' + # ret << "" + # ret << item.i18n_variable[I18n.locale] + # ret << "" + # end + + def parse_page_edit_noko(page, id = nil) + body = Nokogiri::HTML(page.design.layout.body) + parse_menu(body, page, true) + public_r_tags = parse_contents(body, page, id) + parse_images(body, page) + + public_r_tags.each do |tag| + send("parse_#{tag}s", body, page,id) end + + body.to_html end - - def parser_context_edit(page, attributes = {}) - Radius::Context.new do |c| - c.define_tag 'ad_banner' do |tag| - res = '' - ad_banner = AdBanner.find(tag.attr["id"]) rescue nil - if ad_banner - res << "" - res << "
" - ad_banner.ad_images.each do |ad_image| - res << "" - end - res << "
" - end - end - c.define_tag 'content' do |tag| - ret = '' - if (tag.attributes["main"] == "true" && !page.module_app.nil?) - ret << "
" - else - part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } - ret << "
" - ret << "' - case part.kind - when 'text' - ret << part.i18n_variable[I18n.locale] rescue '' - when 'module_widget' - if part[:category] - ret << "
" - else - ret << "
" - end - when 'public_r_tag' - ret << "" - else - '' - end - ret << '
' - end - end - c.define_tag 'image' do |tag| - # 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?(tag.attr['name']) } unless image - if image - res = "' - end - end - c.define_tag 'javascripts' do |tag| - res = '' - res << "" - res << "" - res << "" - res << "" - page.design.javascripts.each do |js| - res << "" - end - res - end - c.define_tag 'language_bar' do - @site.in_use_locales.map{ |locale| - lang = I18nVariable.first(:conditions => {:key => locale})[locale] - if I18n.locale.to_s.eql?(locale) - lang + + # page_contents + def parse_contents(body, page, id) + 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 + ret << "
" + ret << "' + case part.kind + when 'text' + ret << part.i18n_variable[I18n.locale] rescue '' + when 'module_widget' + if part[:category] + ret << "
" else - "#{lang}" + ret << "
" end - }.join(' | ') + when 'public_r_tag' + ret << "" + public_r_tags << part.public_r_tag + else + '' + end end - c.define_tag 'link' do |tag| - item = Item.first(:conditions => { :full_name => tag.attr['name'] }) - ret = '' - ret << "" - ret << item.i18n_variable[I18n.locale] - ret << "" - end - c.define_tag 'menu' do |tag| - home = get_homepage - menu = page.design.layout.menu - menu_level(home, 0, menu, true) - end - c.define_tag 'meta' do |tag| - "" - end - c.define_tag 'stylesheets' do |tag| - res = '' - res << "" if page.design.reset_css - res << "" if page.design.default_css - theme = page.design.themes.detect{ |d| d.id == page.theme_id } - res << "" if theme - res - end - c.define_tag 'title' do |tag| - "#{page.title ? page.title : page.i18n_variable[I18n.locale]}" + 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 - + + def self.included(base) - base.send :helper_method, :parse_page_edit if base.respond_to? :helper_method + base.send :helper_method, :parse_page_edit_noko if base.respond_to? :helper_method end end diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 8d43c070..96cbb4b9 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -44,4 +44,56 @@ module ParserCommon res << "" end + # ad_banners + def parse_ad_banners(body = nil, page = nil, id = nil) + 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 + end + + # page_images + def parse_images(body, page) + 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?(page_image['name']) } 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, 0, menu, true)) + page_menu.swap(fragment) + end + end diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 529802ff..c3ca1787 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -1,113 +1,42 @@ module ParserFrontEnd - require 'radius' include ParserCommon - - def parser_context(page, attributes = {}, id = nil) - Radius::Context.new do |c| - c.define_tag 'ad_banner' do |tag| - res = '' - ad_banner = AdBanner.find(tag.attr["id"]) rescue nil - if ad_banner && ad_banner.display? - res << "" - res << "
" - ad_banner.ad_images.each do |ad_image| - res << "" - end - res << "
" - end - res - end - c.define_tag 'content' do |tag| - ret = '' - if (tag.attributes["main"] == "true" && !page.module_app.nil?) - ret << "
" - else - part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil - case part.kind - when 'text' - ret << part.i18n_variable[I18n.locale] rescue '' - when 'module_widget' - if part[:category] - ret << "
" - else - ret << "
" - end - when 'public_r_tag' - ret << "" - else - '' - end - end - ret - end - c.define_tag 'image' do |tag| - # 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?(tag.attr['name']) } unless image - if image - res = "' - end - end - c.define_tag 'language_bar' do - @site.in_use_locales.map{ |locale| - lang = I18nVariable.first(:conditions => {:key => locale})[locale] - if I18n.locale.to_s.eql?(locale) - lang - else - "#{lang}" - end - }.join(' | ') - end - c.define_tag 'link' do |tag| - item = Item.first(:conditions => { :full_name => tag.attr['name'] }) - ret = '' - ret << "" - ret << item.i18n_variable[I18n.locale] - ret << '' - end - c.define_tag 'menu' do |tag| - home = get_homepage - menu = page.design.layout.menu - menu_level(home, 0, menu) - end - end - end - - def parse_page(page, id = nil) - if page._type == 'Page' - context = parser_context(page, {}, id) - parser = Radius::Parser.new(context, :tag_prefix => 'r') - parser.parse(parser.parse(page.design.layout.body)) - end - end - - def self.included(base) - base.send :helper_method, :parse_page if base.respond_to? :helper_method - end - - + # c.define_tag 'language_bar' do + # @site.in_use_locales.map{ |locale| + # lang = I18nVariable.first(:conditions => {:key => locale})[locale] + # if I18n.locale.to_s.eql?(locale) + # lang + # else + # "#{lang}" + # end + # }.join(' | ') + # end + # c.define_tag 'link' do |tag| + # item = Item.first(:conditions => { :full_name => tag.attr['name'] }) + # ret = '' + # ret << "" + # ret << item.i18n_variable[I18n.locale] + # ret << '' + # end + # end require 'nokogiri' def parse_page_noko(page, id = nil) body = Nokogiri::HTML(page.design.layout.body) + parse_menu(body, page) + public_r_tags = parse_contents(body, page, id) + parse_images(body, page) - # page_contents + public_r_tags.each do |tag| + send("parse_#{tag}s", body, page,id) + end + + body.to_html + end + + # page_contents + def parse_contents(body, page, id) + public_r_tags = [] body.css('.page_content').each do |content| ret = '' if (content["main"] == "true" && !page.module_app.nil?) @@ -129,6 +58,7 @@ module ParserFrontEnd end when 'public_r_tag' ret << "" + public_r_tags << part.public_r_tag else '' end @@ -141,54 +71,7 @@ module ParserFrontEnd fragment = Nokogiri::HTML::DocumentFragment.new(body, scope) content.swap(fragment) end - - # page_menu - page_menu = body.css('.page_menu').first - home = get_homepage - menu = page.design.layout.menu - fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, 0, menu)) - page_menu.swap(fragment) - - # page_image - 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?(page_image['name']) } unless image - if image - res = "' - end - fragment = Nokogiri::HTML::DocumentFragment.new(body, res) - 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 + public_r_tags.uniq end end