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 << "" if part
          ret << "
'
        end
        case part.kind
        when 'text'
          ret << part.content 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? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&part_id=#{part.id}"
          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}#{content.name}>"
      fragment = Nokogiri::HTML::DocumentFragment.new(body, scope)
      content.swap(fragment)
    end
    public_r_tags.uniq
  end
end