| 
									
										
										
										
											2011-03-02 09:28:33 +00:00
										 |  |  | # 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 | 
					
						
							| 
									
										
										
										
											2011-03-02 09:28:33 +00:00
										 |  |  |    | 
					
						
							|  |  |  |     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) | 
					
						
							| 
									
										
										
										
											2011-08-22 05:45:21 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2011-11-19 06:33:26 +00:00
										 |  |  |     Site.create( :school => 'RulingDigital Universitry', :department => 'Computer Science', :valid_locales => [ 'en', 'zh_tw' ], :in_use_locales => [ 'zh_tw', 'en' ])  | 
					
						
							| 
									
										
										
										
											2011-03-02 09:28:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 02:07:42 +00:00
										 |  |  |     # I18n_variables | 
					
						
							| 
									
										
										
										
											2011-03-02 09:28:33 +00:00
										 |  |  |     I18nVariable.create!( :document_class => 'language', :key => 'en', :en => 'English', :zh_tw => '英文' ) | 
					
						
							|  |  |  |     I18nVariable.create!( :document_class => 'language', :key => 'zh_tw', :en => 'Chinese', :zh_tw => '中文' ) | 
					
						
							| 
									
										
										
										
											2011-12-10 10:12:39 +00:00
										 |  |  |     var_1 = I18nVariable.create!( :document_class => 'Role', :key => 'teacher', :en => 'Teacher', :zh_tw => '老師' ) | 
					
						
							| 
									
										
										
										
											2011-12-18 02:07:42 +00:00
										 |  |  |       var_1_1 = I18nVariable.create!( :document_class => 'SubRole', :key => 'good_teacher', :en => 'Good teacher', :zh_tw => '好老師', :parent_id => var_1.id ) | 
					
						
							|  |  |  |         var_1_1_1 = I18nVariable.create!( :document_class => 'Attribute', :key => 'field', :en => 'Field', :zh_tw => '領域', :parent_id => var_1_1.id ) | 
					
						
							|  |  |  |         var_1_1_2 = I18nVariable.create!( :document_class => 'Attribute', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_1_1.id ) | 
					
						
							|  |  |  |       var_1_2 = I18nVariable.create!( :document_class => 'SubRole', :key => 'bad_teacher', :en => 'Bad teacher', :zh_tw => '壞老師', :parent_id => var_1.id ) | 
					
						
							|  |  |  |         var_1_2_1 = I18nVariable.create!( :document_class => 'Attribute', :key => 'field', :en => 'Field', :zh_tw => '領域', :parent_id => var_1_2.id ) | 
					
						
							|  |  |  |         var_1_2_2 = I18nVariable.create!( :document_class => 'Attribute', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_1_2.id ) | 
					
						
							|  |  |  |         var_1_2_3 = I18nVariable.create!( :document_class => 'Attribute', :key => 'speciality', :en => 'Speciality', :zh_tw => '專業', :parent_id => var_1_2.id ) | 
					
						
							|  |  |  |     var_2 = I18nVariable.create!( :document_class => 'Role', :key => 'student', :en => 'Student', :zh_tw => '學生' ) | 
					
						
							|  |  |  |       var_2_1 = I18nVariable.create!( :document_class => 'SubRole', :key => 'undergraduate', :en => 'Undergraduate', :zh_tw => '大學部學生', :parent_id => var_2.id ) | 
					
						
							|  |  |  |         var_2_1_1 = I18nVariable.create!( :document_class => 'Attribute', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_2_1.id ) | 
					
						
							|  |  |  |         var_2_1_2 = I18nVariable.create!( :document_class => 'Attribute', :key => 'major', :en => 'Major', :zh_tw => '主修', :parent_id => var_2_1.id ) | 
					
						
							|  |  |  |       var_2_2 = I18nVariable.create!( :document_class => 'SubRole', :key => 'graduate', :en => 'Graduate', :zh_tw => '研究生', :parent_id => var_2.id ) | 
					
						
							|  |  |  |         var_2_2_1 = I18nVariable.create!( :document_class => 'Attribute', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_2_2.id ) | 
					
						
							|  |  |  |         var_2_2_2 = I18nVariable.create!( :document_class => 'Attribute', :key => 'major', :en => 'Major', :zh_tw => '主修', :parent_id => var_2_2.id ) | 
					
						
							|  |  |  |         var_2_2_3 = I18nVariable.create!( :document_class => 'Attribute', :key => 'thesis_subject', :en => 'Thesis subject', :zh_tw => '論文題目', :parent_id => var_2_2.id ) | 
					
						
							| 
									
										
										
										
											2011-12-10 10:12:39 +00:00
										 |  |  |     var_7 = I18nVariable.create!( :document_class => 'Info', :key => 'profile', :en => 'Profile', :zh_tw => '個人檔案' ) | 
					
						
							| 
									
										
										
										
											2011-12-18 02:07:42 +00:00
										 |  |  |       var_8 = I18nVariable.create!( :document_class => 'Attribute', :key => 'last_name', :en => 'Last name', :zh_tw => '姓氏', :parent_id => var_7.id ) | 
					
						
							|  |  |  |       var_9 = I18nVariable.create!( :document_class => 'Attribute', :key => 'first_name', :en => 'First name', :zh_tw => '名字', :parent_id => var_7.id ) | 
					
						
							| 
									
										
										
										
											2011-03-02 09:28:33 +00:00
										 |  |  |     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' ) | 
					
						
							| 
									
										
										
										
											2011-05-27 03:27:54 +00:00
										 |  |  |     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-12-18 02:07:42 +00:00
										 |  |  |     # User roles | 
					
						
							|  |  |  |     r_1 = Role.new( :key => 'teacher', :i18n_variable => var_1, :built_in => true ) | 
					
						
							|  |  |  |       sr_1_1 = r_1.sub_roles.build( :key => 'good_teacher', :i18n_variable => var_1_1, :built_in => true ) | 
					
						
							|  |  |  |         sr_1_1.attribute_fields.build( :key => 'field', :locale => true, :i18n_variable => var_1_1_1, :markup => 'text_field', :list_options => [], :built_in => true ) | 
					
						
							|  |  |  |         sr_1_1.attribute_fields.build( :key => 'department', :locale => true, :i18n_variable => var_1_1_2, :markup => 'text_field', :list_options => [], :built_in => true ) | 
					
						
							| 
									
										
										
										
											2011-12-20 06:35:28 +00:00
										 |  |  |       sr_1_2 = r_1.sub_roles.build( :key => 'bad_teacher', :i18n_variable => var_1_2 ) | 
					
						
							| 
									
										
										
										
											2011-12-18 02:07:42 +00:00
										 |  |  |         sr_1_2.attribute_fields.build( :key => 'field', :locale => true, :i18n_variable => var_1_2_1, :markup => 'text_field', :list_options => [] ) | 
					
						
							|  |  |  |         sr_1_2.attribute_fields.build( :key => 'department', :locale => true, :i18n_variable => var_1_2_2, :markup => 'text_field', :list_options => [] ) | 
					
						
							|  |  |  |         sr_1_2.attribute_fields.build( :key => 'speciality', :locale => true, :i18n_variable => var_1_2_3, :markup => 'text_field', :list_options => [] ) | 
					
						
							|  |  |  |     r_1.save! | 
					
						
							|  |  |  |     r_2 = Role.new( :key => 'student', :i18n_variable => var_2 ) | 
					
						
							|  |  |  |       sr_2_1 = r_2.sub_roles.build( :key => 'undergraduate', :i18n_variable => var_2_1 ) | 
					
						
							|  |  |  |         sr_2_1.attribute_fields.build( :key => 'department', :locale => true, :i18n_variable => var_2_1_1, :markup => 'text_field', :list_options => [] ) | 
					
						
							|  |  |  |         sr_2_1.attribute_fields.build( :key => 'major', :locale => true, :i18n_variable => var_2_1_2, :markup => 'text_field', :list_options => [] ) | 
					
						
							|  |  |  |       sr_2_2 = r_2.sub_roles.build( :key => 'graduate', :i18n_variable => var_2_2 ) | 
					
						
							|  |  |  |         sr_2_2.attribute_fields.build( :key => 'department', :locale => true, :i18n_variable => var_2_2_1, :markup => 'text_field', :list_options => [] ) | 
					
						
							|  |  |  |         sr_2_2.attribute_fields.build( :key => 'major', :locale => true, :i18n_variable => var_2_2_2, :markup => 'text_field', :list_options => [] ) | 
					
						
							|  |  |  |         sr_2_2.attribute_fields.build( :key => 'thesis_subject', :locale => true, :i18n_variable => var_2_2_3, :markup => 'text_field', :list_options => [] )  | 
					
						
							|  |  |  |     r_2.save! | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     # User info | 
					
						
							|  |  |  |     i_1 = Info.new( :key => 'profile', :i18n_variable => var_7, :built_in => true ) | 
					
						
							|  |  |  |     i_1.attribute_fields.build( :key => 'last_name', :locale => true, :i18n_variable => var_8, :markup => 'text_field', :list_options => [], :built_in => true ) | 
					
						
							|  |  |  |     i_1.attribute_fields.build( :key => 'first_name', :locale => true, :i18n_variable => var_9, :markup => 'text_field', :list_options => [], :built_in => true ) | 
					
						
							|  |  |  |     i_1.save!  | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2011-05-18 02:00:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-22 05:45:21 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     design = Design.new(:title => "Fraisier", :author => "Paul", :intro => "Strawberry cake") | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2012-10-24 10:40:38 +00:00
										 |  |  |     design.build_css_default(:file => File.open("#{Rails.root}/lib/fraisier/default.css")) | 
					
						
							| 
									
										
										
										
											2011-08-22 05:45:21 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     # 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")) | 
					
						
							|  |  |  |     #  | 
					
						
							| 
									
										
										
										
											2011-08-23 18:06:27 +00:00
										 |  |  |     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")) | 
					
						
							| 
									
										
										
										
											2011-08-22 05:45:21 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     design.build_layout | 
					
						
							|  |  |  |     design.layout.file = File.open("#{Rails.root}/lib/fraisier/layout.html") | 
					
						
							| 
									
										
										
										
											2011-05-18 02:00:00 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2011-08-22 05:45:21 +00:00
										 |  |  |     design.save | 
					
						
							| 
									
										
										
										
											2011-03-02 09:28:33 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2011-08-23 18:06:27 +00:00
										 |  |  |      | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     design_1 = Design.new(:title => "Bob", :author => "Me", :intro => "Moran") | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2012-10-24 10:40:38 +00:00
										 |  |  |     design_1.build_css_default(:file => File.open("#{Rails.root}/lib/fraisier/default.css")) | 
					
						
							| 
									
										
										
										
											2011-08-23 18:06:27 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     # 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.save | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2011-03-02 09:28:33 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2012-02-16 11:14:16 +00:00
										 |  |  |     home = Page.create( :i18n_variable => var_10, :design => design_1, :name => 'home', :is_published => true, :theme_id => theme.id ) | 
					
						
							| 
									
										
										
										
											2012-01-30 10:12:18 +00:00
										 |  |  |     ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/new_blog/new_blog.json").read).save | 
					
						
							|  |  |  |     ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/announcement/announcement.json").read).save | 
					
						
							| 
									
										
										
										
											2012-02-16 05:28:51 +00:00
										 |  |  |     ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/web_resource/web_resource.json").read).save | 
					
						
							| 
									
										
										
										
											2011-10-20 07:29:54 +00:00
										 |  |  |     Post.create(:title=>"1st post",:body=>"Long long time ago.....") | 
					
						
							|  |  |  |     Post.create(:title=>"2ec post",:body=>"And?.....") | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2011-11-19 19:16:35 +00:00
										 |  |  |      | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2011-12-20 06:35:28 +00:00
										 |  |  |     user = User.create( :email => 'chris@rulingcom.com', :password => 'password', :password_confirmation => 'password', :admin => true, :role_id => r_1.id, :sub_role_ids => [sr_1_2.id] ) | 
					
						
							| 
									
										
										
										
											2011-12-18 02:07:42 +00:00
										 |  |  |     AttributeValue.create( :user => user, :attribute_field => i_1.attribute_fields[0], :key => 'first_name', :en => 'Christophe', :zh_tw => '順發' ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => i_1.attribute_fields[1].id, :key => 'last_name', :en => 'Vilayphiou', :zh_tw => '林' ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => sr_1_2.attribute_fields[0].id, :key => 'field', :en => 'Computer Architecture', :zh_tw => '計算機系統結構' ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => sr_1_2.attribute_fields[1].id, :key => 'department', :en => 'Computer Science', :zh_tw => '計算機科學' ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => sr_1_2.attribute_fields[2].id, :key => 'speciality', :en => 'HSR', :zh_tw => '高鐵' ) | 
					
						
							| 
									
										
										
										
											2011-11-19 19:16:35 +00:00
										 |  |  |      | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2011-12-20 06:35:28 +00:00
										 |  |  |     user = User.create( :email => 'matt@rulingcom.com', :password => 'password', :password_confirmation => 'password', :admin => true, :role_id => r_2.id, :sub_role_ids => [sr_2_1.id ] ) | 
					
						
							| 
									
										
										
										
											2011-12-18 02:07:42 +00:00
										 |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => i_1.attribute_fields[0].id, :key => 'first_name', :en => 'Matt', :zh_tw => '儒淵' ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => i_1.attribute_fields[1].id, :key => 'last_name', :en => 'Fu', :zh_tw => '傅' ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => sr_2_1.attribute_fields[0].id, :key => 'major', :en => 'Information management', :zh_tw => '信息化管理' ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => sr_2_1.attribute_fields[1].id, :key => 'department', :en => 'Computer Science', :zh_tw => '計算機科學' ) | 
					
						
							| 
									
										
										
										
											2012-02-15 10:20:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     user = User.create( :email => 'manager@rulingcom.com', :password => 'password', :password_confirmation => 'password', :admin => false, :role_id => r_2.id, :sub_role_ids => [sr_2_1.id ] ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => i_1.attribute_fields[0].id, :key => 'first_name', :en => 'Manager', :zh_tw => '管理員' ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => i_1.attribute_fields[1].id, :key => 'last_name', :en => 'Chen', :zh_tw => '陳' ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => sr_2_1.attribute_fields[0].id, :key => 'major', :en => 'Information management', :zh_tw => '信息化管理' ) | 
					
						
							|  |  |  |     AttributeValue.create( :user_id => user.id, :attribute_field_id => sr_2_1.attribute_fields[1].id, :key => 'department', :en => 'Computer Science', :zh_tw => '計算機科學' ) | 
					
						
							| 
									
										
										
										
											2011-11-19 19:16:35 +00:00
										 |  |  |      | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2012-02-03 10:02:27 +00:00
										 |  |  |     ad_banner = AdBanner.new(:title => 'banner_1',:post_date => Date.today,:context=> "context",:ad_fx=>'zoom',:direct_to_after_click=>true) | 
					
						
							|  |  |  |     ad_banner.ad_images.build(:time_to_next=>2,:picture_intro=>'Banner1',:out_link=>'http://www.rulingcom.com/main.php',:file => File.open("#{Rails.root}/lib/ad_banner/ad_banner1.jpg",:link_open=>'new_window')) | 
					
						
							|  |  |  |     ad_banner.ad_images.build(:time_to_next=>5,:picture_intro=>'Banner2',:out_link=>'http://www.google.com',:file => File.open("#{Rails.root}/lib/ad_banner/ad_banner2.jpg",:link_open=>'local')) | 
					
						
							|  |  |  |     ad_banner.save!   | 
					
						
							| 
									
										
										
										
											2010-01-18 08:23:33 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  | end |