-i = 0

-@articles.each do |a|

  -@parent = nil
  -i+= 1
  %div
    =i
    %p=raw a["title"]
    
    -repertoire = a["repertoire"].to_s
    
    =repertoire.to_s+"/"+a["name"]+".php"
    
    -if a["repertoire"].to_s != "" and a["repertoire"].to_s != "aucun" 
    
      
    
      -@parent = MenuItem.find_by_slug(@repertoires[repertoire.to_i].to_s)
      
      %h1 IL Y A UN REPERTOIRE
      =debug @parent
    
      -file_path = Rails.root.join("pages", @repertoires[repertoire.to_i],a["name"]+".php" )
    
    -else
      - file_path = Rails.root.join("pages",a["name"]+".php" )
      
    
    
  
    
 
  -repertoir_string = @parent ? @parent.slug.to_s+"/" : ""


  -@menu_item= MenuItem.new(:enabled => true, :visible => true,:menu_id => 1, :menu_content_type => "Page",:name => HTMLEntities.new.decode(a["title"]), :slug => a["name"], :section_id => a["section"])
  -content = Page.new(:title => HTMLEntities.new.decode(a["title"]), :description => HTMLEntities.new.decode(a["description"]), :keywords => HTMLEntities.new.decode(a["keywords"]))
  
  
  
  -@menu_item.menu_content = content
  -@menu_item.parent_id = @parent.id if @parent
  

  -@menu_item.created_at = @dates[repertoir_string+a["name"]]

  
  -if @menu_item.save
    -content = ""
    -begin
      =content = File.open(file_path).read
      =@menu_item.menu_content.blocks[0].portlets << Portlet.new(:content => HtmlContent.new(:content_type => "html", :content => content))
    -rescue
      %h1 
        ALERT
        =file_path
  
  
-MenuItem.all.each do |mi|

  -if mi.created_at.year < 1980
    -mi.created_at = "2010-08-01"
    -mi.save 
  -mi.set_permalink
  
%hr

      
      
%hr
-MenuItem.where(:section_id => 19).each do |menu_item|
  %p
    Création article : 
    =menu_item.name
  
  -article = Article.new(:enabled => true, :title => menu_item.slug.to_s+" | "+menu_item.name.to_s, :slug => menu_item.slug, :tags_cache => "archive, témoignage", :created_at => menu_item.created_at,:published_at => menu_item.created_at, :description => menu_item.menu_content.description, :keywords => menu_item.menu_content.keywords)
  
  -if article.save
    -article.block = menu_item.menu_content.blocks[0]
    -article.save
    
    =menu_item.destroy
    
  -else
    %h2
      Alert article 
      %br
      =menu_item.name
      %br
      =menu_item.slug
      %br
      =debug menu_item.parent
       
      
%hr
-MenuItem.where(:section_id => 18).each do |menu_item|
  %p
    Création article : 
    =menu_item.name
  
  -article = Article.new(:enabled => true, :title => menu_item.slug.to_s+" | "+menu_item.name.to_s, :slug => menu_item.slug, :tags_cache => "archive, traduction", :created_at => menu_item.created_at,:published_at => menu_item.created_at, :description => menu_item.menu_content.description, :keywords => menu_item.menu_content.keywords)
  
  -if article.save
    -article.block = menu_item.menu_content.blocks[0]
    -article.save
    
    =menu_item.destroy
    
  -else
    %h2
      Alert article 
      %br
      =menu_item.name
      %br
      =menu_item.slug
      %br
      =debug menu_item.parent
      
      



%hr
NEWSLETTER
-MenuItem.where(:section_id => 25).each do |menu_item|
  %p
    Création newsletter : 
    =menu_item.name
  %p
    SLUG :
    =menu_item.slug
  
  -article = Newsletter.new(:enabled => true, :title => menu_item.slug.to_s+" | "+menu_item.name.to_s, :tags_cache => "" , :slug => menu_item.slug, :created_at => menu_item.created_at,:published_at => menu_item.created_at, :description => menu_item.menu_content.description, :keywords => menu_item.menu_content.keywords)
  
  -if article.save
    -article.block = menu_item.menu_content.blocks[0]
    -article.save
    
    =menu_item.destroy
    
  -else
    %h2
      Alert newsletter 
      %br
      =menu_item.name
      %br
      =menu_item.slug
      %br
      =debug menu_item.parent
      
      

