# encoding: utf-8 

namespace :pages do
  
  task :build => :environment do
  
    Item.delete_all


    var_10 = I18nVariable.create!( :document_class => 'Home', :key => 'home', :en => 'Homepage', :zh_tw => '首頁')
    var_13 = I18nVariable.create!( :document_class => 'PagePart', :key => 'main_content', :en => 'This is the homepage', :zh_tw => '這是首頁', :parent_id => var_10.id ) 
    
    
    design = Design.new(:title => "Fraisier", :author => "Paul", :intro => "Strawberry cake")
    
    design.build_default_css(:file => File.open("#{Rails.root}/lib/fraisier/default.css"))
    
    # image = design.images.build(:file => File.open("#{Rails.root}/lib/fraisier/img/buttons.gif"))
    # 
    # js = design.javascripts.build(:file => File.open("#{Rails.root}/lib/fraisier/inettuts.js"))
    # 
    theme = design.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/themes/default.css"))
    theme_1 = design.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/themes/red.css"))
    
    design.build_layout
    design.layout.file = File.open("#{Rails.root}/lib/fraisier/layout.html")
    
    design.layout.save
    theme.save
    theme_1.save
    # image.save
    # js.save
    
    design.save
    
    
    
    design_1 = Design.new(:title => "Bob", :author => "Me", :intro => "Moran")
    
    design_1.build_default_css(:file => File.open("#{Rails.root}/lib/fraisier/default.css"))
    
    # image = design.images.build(:file => File.open("#{Rails.root}/lib/fraisier/img/buttons.gif"))
    # 
    # js = design.javascripts.build(:file => File.open("#{Rails.root}/lib/fraisier/inettuts.js"))
    # 
    theme = design_1.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/themes/default.css"))
    theme_1 = design_1.themes.build(:file => File.open("#{Rails.root}/lib/fraisier/themes/red.css"))
    
    design_1.build_layout
    design_1.layout.file = File.open("#{Rails.root}/lib/fraisier/layout.html")
    
    design_1.layout.save
    theme.save
    theme_1.save
    # image.save
    # js.save
    
    design_1.save
    
    
    home = Page.create!( :i18n_variable_id => var_10.id, :design_id => design_1.id, :name => 'home', :is_published => true, :theme_id => theme.id )
    home.page_parts.create!( :name => 'content_1', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id )
            
  end
  
end
