orbit-basic/lib/tasks/dev.rake

123 lines
7.7 KiB
Ruby
Raw Normal View History

# encoding: utf-8
2011-01-28 06:44:08 +00:00
2010-01-18 08:23:33 +00:00
namespace :dev do
task :build => :environment do
puts 'Empty the MongoDB database, exclude System stuff'
Mongoid.master.collections.select do |collection|
include = collection.name !~ /system/
puts 'Dropping ' + collection.name if include
include
end.each(&:drop)
Site.create( :school => 'The Best School', :department => 'Awesome', :valid_locales => [ 'en', 'zh_tw' ], :in_use_locales => [ 'zh_tw', 'en' ])
user = User.new( :email => 'chris@rulingcom.com', :password => 'password', :password_confirmation => 'password', :admin => true, :active_roles => ['teacher'])
user.user_roles.build(:key => 'teacher', :discipline_en => 'Database', :discipline_zh_tw => '資料庫' )
user.save!
I18nVariable.create!( :document_class => 'language', :key => 'en', :en => 'English', :zh_tw => '英文' )
I18nVariable.create!( :document_class => 'language', :key => 'zh_tw', :en => 'Chinese', :zh_tw => '中文' )
var_1 = I18nVariable.create!( :document_class => 'UserRoleModel', :key => 'teacher', :en => 'Teacher', :zh_tw => '老師' )
var_2 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'discipline', :en => 'Discipline', :zh_tw => '學科', :parent_id => var_1.id )
var_3 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_1.id )
var_4 = I18nVariable.create!( :document_class => 'UserRoleModel', :key => 'student', :en => 'Student', :zh_tw => '學生' )
var_5 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_4.id )
var_6 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'major', :en => 'Major', :zh_tw => '主修', :parent_id => var_4.id )
var_7 = I18nVariable.create!( :document_class => 'UserInfoModel', :key => 'profile', :en => 'Profile', :zh_tw => '個人檔案' )
var_8 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'family_name', :en => 'Family name', :zh_tw => '姓氏', :parent_id => var_7.id )
var_9 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'first_name', :en => 'First name', :zh_tw => '名字', :parent_id => var_7.id )
var_10 = I18nVariable.create!( :document_class => 'Home', :key => 'home', :en => 'Homepage', :zh_tw => '首頁')
var_11 = I18nVariable.create!( :document_class => 'Page', :key => 'about', :en => 'About', :zh_tw => '關於我們' )
var_12 = I18nVariable.create!( :document_class => 'Link', :key => 'google', :en => 'Google', :zh_tw => 'Google' )
var_13 = I18nVariable.create!( :document_class => 'PagePart', :key => 'main_content', :en => 'This is the homepage', :zh_tw => '這是首頁', :parent_id => var_10.id )
var_14 = I18nVariable.create!( :document_class => 'PagePart', :key => 'main_content', :en => 'This is about', :zh_tw => '這是關於', :parent_id => var_11.id )
2011-01-28 06:44:08 +00:00
2011-05-18 02:00:00 +00:00
# TODO: modify for the new model
2011-05-02 04:07:31 +00:00
urm_1 = UserRoleModel.new( :key => 'teacher', :i18n_variable_id => var_1.id, :built_in => true )
urm_1.attribute_models.build( :key => 'discipline', :locale => true, :i18n_variable_id => var_2.id, :markup => 'text_field', :list_options => [], :built_in => true )
urm_1.attribute_models.build( :key => 'department', :locale => true, :i18n_variable_id => var_3.id, :markup => 'text_field', :list_options => [], :built_in => true )
urm_1.save!
urm_2 = UserRoleModel.new( :key => 'student', :i18n_variable_id => var_4.id )
urm_2.attribute_models.build( :key => 'department', :locale => true, :i18n_variable_id => var_5.id, :markup => 'text_field', :list_options => [] )
urm_2.attribute_models.build( :key => 'major', :locale => true, :i18n_variable_id => var_6.id, :markup => 'text_field', :list_options => [] )
urm_2.save!
2011-05-02 04:07:31 +00:00
uim_1 = UserInfoModel.new( :key => 'profile', :i18n_variable_id => var_7.id, :built_in => true )
uim_1.attribute_models.build( :key => 'family_name', :locale => true, :i18n_variable_id => var_8.id, :markup => 'text_field', :list_options => [], :built_in => true )
uim_1.attribute_models.build( :key => 'first_name', :locale => true, :i18n_variable_id => var_9.id, :markup => 'text_field', :list_options => [], :built_in => true )
uim_1.save!
2011-01-28 06:44:08 +00:00
# layout = Layout.create!( :name => 'root', :description => 'root', :content => File.open("#{Rails.root}/lib/template/root.layout").read )
# layout.layout_parts.create!( :name => 'header', :content => File.open("#{Rails.root}/lib/template/nav.snippet").read )
# layout.layout_parts.create!( :name => 'main_content', :editable => true )
# layout.layout_parts.create!( :name => 'footer', :content => File.open("#{Rails.root}/lib/template/footer.snippet").read )
#
# home = Page.create!( :i18n_variable_id => var_10.id, :layout_id => layout.id, :name => 'home', :is_published => true )
# home.page_parts.create!( :name => 'main_content', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id )
#
# about = Page.create!( :i18n_variable_id => var_11.id, :layout_id => layout.id, :name => 'about', :is_published => true, :parent_id => home.id )
# about.page_parts.create!( :name => 'main_content', :content => File.open("#{Rails.root}/lib/template/about.page").read, :kind => 'text', :i18n_variable_id => var_14.id )
# Link.create!( :i18n_variable_id => var_12.id, :name => 'google', :is_published => true, :parent_id => home.id, :url => 'www.google.com' )
#
# ["nav", "footer"].each do |page_name|
# Snippet.create!( :name => page_name, :parent_id => home.id, :content => File.open("#{Rails.root}/lib/template/#{page_name}.snippet").read )
# end
design = Design.new(:title => "Fraisier", :author => "Paul", :intro => "Strawberry cake")
design.default_css = 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")
2011-05-18 02:00:00 +00:00
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.default_css = 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 )
2010-01-18 08:23:33 +00:00
end
end