main_data.rake
5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/env ruby
# encoding: utf-8
namespace :main_data do
desc "Create the main community and its contents"
task :populate => :environment do
Rake::Task["main_data:community"].invoke
Rake::Task["templates:create:all"].invoke
end
desc "Create the main community and its contents"
task :all => :environment do
Rake::Task["main_data:destroy"].invoke
Rake::Task["templates:destroy"].invoke
Rake::Task["software:create_categories"].invoke
Rake::Task["main_data:populate"].invoke
end
desc "Create the main community"
task :community => :environment do
Environment.all.each do |env|
if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin")
identifier = "spb"
community = Community.create!(:name => "SPB", :identifier => identifier)
community.layout_template = "leftbar"
box1 = community.boxes.where(:position => 1).first
box2 = community.boxes.where(:position => 2).first
box3 = community.boxes.where(:position => 3).first
box1.blocks.destroy_all
box2.blocks.destroy_all
box3.blocks.destroy_all
community.save!
puts "SPB succesfully created!"
main_block = MainBlock.new
main_block.position = 1
main_block.save!
box1.blocks << main_block
box1.save!
puts "MainBlock successfully added to SPB!"
generate_fixed_blocks(community)
generate_article(community, Blog, {name: "Notícias", slug: "noticias", published: true, accept_comments: true, notify_comments: true, license_id: 1, body: "", accept_comments: false, posts_per_page: 5}, true)
generate_article(community, TinyMceArticle, {name: "Sobre o Portal", slug: "sobre-o-portal", published: true, accept_comments: false, notify_comments: true, license_id: 1, body: "", accept_comments: false})
generate_article(community, TinyMceArticle, {name: "Publique seu software", slug: "publique-seu-software", published: true, accept_comments: false, notify_comments: true, license_id: 1, body: "", accept_comments: false})
generate_article(community, TinyMceArticle, {name: "Inicie um projeto", slug: "inicie-um-projeto", published: true, accept_comments: false, notify_comments: true, license_id: 1, body: "", accept_comments: false})
generate_article(community, TinyMceArticle, {name: "Entenda o que é", slug: "entenda-o-que-e", published: true, accept_comments: false, notify_comments: true, license_id: 1, body: "", accept_comments: false})
end
end
end
desc "Destroy all main content created by this namespace"
task :destroy => :environment do
Environment.all.each do |env|
if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin")
Community["spb"].destroy unless Community["spb"].nil?
puts "Main Community destoyed with success!"
end
end
end
private
def generate_article(software, klass, params, home_page = false)
article = klass.new(params)
article.body = params[:body]
software.articles << article
if home_page
software.home_page = article
end
software.save!
puts "#{params[:name]} #{klass} successfully created!"
end
def generate_fixed_blocks(profile)
identifier = "spb"
box2 = profile.boxes.where(:position => 2).first
first_link_list_block = LinkListBlock.new
first_link_list_block.position = 3
first_link_list_block.display = "always"
first_link_list_block.title = "Portal do SPB"
first_link_list_block.fixed = true
first_link_list_block.save!
first_link_list_block.links << {:icon => "no-icon", :name => "Sobre o Portal", :address => "/#{identifier}/sobre-o-portal", :target => "_self"}
first_link_list_block.links << {:icon => "no-icon", :name => "Notícias", :address => "/#{identifier}/noticias", :target => "_self"}
first_link_list_block.save!
box2.blocks << first_link_list_block
box2.save!
puts "First LinkListBlock successfully added to software!"
second_link_list_block = LinkListBlock.new
second_link_list_block.position = 2
second_link_list_block.display = "always"
second_link_list_block.title = "Software Público"
second_link_list_block.fixed = true
second_link_list_block.save!
second_link_list_block.links << {:icon => "no-icon", :name => "Entenda o que é", :address => "/#{identifier}/entenda-o-que-e", :target => "_self"}
second_link_list_block.links << {:icon => "no-icon", :name => "Inicie um projeto", :address => "/#{identifier}/inicie-um-projeto", :target => "_self"}
second_link_list_block.links << {:icon => "no-icon", :name => "Publique seu software", :address => "/#{identifier}/publique-seu-software", :target => "_self"}
second_link_list_block.save!
box2.blocks << second_link_list_block
box2.save!
puts "Second LinkListBlock successfully added to software!"
third_link_list_block = LinkListBlock.new
third_link_list_block.position = 1
third_link_list_block.display = "always"
third_link_list_block.title = ""
third_link_list_block.fixed = true
third_link_list_block.save!
third_link_list_block.links << {:icon => "no-icon", :name => "Catálogo de Software Público", :address => "/search/software_infos", :target => "_self"}
third_link_list_block.links << {:icon => "no-icon", :name => "Comunidades", :address => "/search/communities", :target => "_self"}
third_link_list_block.save!
box2.blocks << third_link_list_block
box2.save!
puts "Third LinkListBlock successfully added to software!"
end
end