Commit 70c00cdbfef5815dae4dc220dd80974ac7ab2ce5
1 parent
d1ab5571
Exists in
master
and in
5 other branches
Create task to populate the main content
Showing
1 changed file
with
104 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,104 @@ |
| 1 | +#!/bin/env ruby | |
| 2 | +# encoding: utf-8 | |
| 3 | + | |
| 4 | +namespace :main_data do | |
| 5 | + desc "Create the main community and its contents" | |
| 6 | + task :all => :environment do | |
| 7 | + Rake::Task["main_data:community"].invoke | |
| 8 | + end | |
| 9 | + | |
| 10 | + desc "Create the main community" | |
| 11 | + task :community => :environment do | |
| 12 | + Environment.all.each do |env| | |
| 13 | + if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin") | |
| 14 | + community = Community.create!(:name => "SPB", :identifier => "spb") | |
| 15 | + community.layout_template = "leftbar" | |
| 16 | + | |
| 17 | + box1 = community.boxes.where(:position => 1).first | |
| 18 | + box2 = community.boxes.where(:position => 2).first | |
| 19 | + box3 = community.boxes.where(:position => 3).first | |
| 20 | + | |
| 21 | + box1.blocks.destroy_all | |
| 22 | + box2.blocks.destroy_all | |
| 23 | + box3.blocks.destroy_all | |
| 24 | + | |
| 25 | + community.save! | |
| 26 | + puts "SPB succesfully created!" | |
| 27 | + | |
| 28 | + main_block = MainBlock.new | |
| 29 | + main_block.position = 1 | |
| 30 | + main_block.save! | |
| 31 | + box1.blocks << main_block | |
| 32 | + box1.save! | |
| 33 | + puts "MainBlock successfully added to SPB!" | |
| 34 | + | |
| 35 | + first_link_list_block = LinkListBlock.new | |
| 36 | + first_link_list_block.position = 3 | |
| 37 | + first_link_list_block.display = "always" | |
| 38 | + first_link_list_block.title = "Portal do SPB" | |
| 39 | + first_link_list_block.save! | |
| 40 | + | |
| 41 | + first_link_list_block.links << {:icon => "no-icon", :name => "Sobre o Portal", :address => "/{profile}/sobre-o-portal", :target => "_self"} | |
| 42 | + first_link_list_block.links << {:icon => "no-icon", :name => "Notícias", :address => "/{profile}/noticias", :target => "_self"} | |
| 43 | + first_link_list_block.save! | |
| 44 | + box2.blocks << first_link_list_block | |
| 45 | + box2.save! | |
| 46 | + puts "First LinkListBlock successfully added to software!" | |
| 47 | + | |
| 48 | + second_link_list_block = LinkListBlock.new | |
| 49 | + second_link_list_block.position = 2 | |
| 50 | + second_link_list_block.display = "always" | |
| 51 | + second_link_list_block.title = "Software Público" | |
| 52 | + second_link_list_block.save! | |
| 53 | + | |
| 54 | + second_link_list_block.links << {:icon => "no-icon", :name => "Entenda o que é", :address => "/{profile}/entenda-o-que-e", :target => "_self"} | |
| 55 | + second_link_list_block.links << {:icon => "no-icon", :name => "Inicie um projeto", :address => "/{profile}/inicie-um-projeto", :target => "_self"} | |
| 56 | + second_link_list_block.links << {:icon => "no-icon", :name => "Publique seu software", :address => "/{profile}/publique-seu-software", :target => "_self"} | |
| 57 | + second_link_list_block.save! | |
| 58 | + box2.blocks << second_link_list_block | |
| 59 | + box2.save! | |
| 60 | + puts "Second LinkListBlock successfully added to software!" | |
| 61 | + | |
| 62 | + third_link_list_block = LinkListBlock.new | |
| 63 | + third_link_list_block.position = 1 | |
| 64 | + third_link_list_block.display = "always" | |
| 65 | + third_link_list_block.title = "" | |
| 66 | + third_link_list_block.save! | |
| 67 | + | |
| 68 | + third_link_list_block.links << {:icon => "no-icon", :name => "Catálogo de Software Público", :address => "#", :target => "_self"} | |
| 69 | + third_link_list_block.links << {:icon => "no-icon", :name => "Comunidades", :address => "/search/communities", :target => "_self"} | |
| 70 | + | |
| 71 | + third_link_list_block.save! | |
| 72 | + box2.blocks << third_link_list_block | |
| 73 | + box2.save! | |
| 74 | + puts "Third LinkListBlock successfully added to software!" | |
| 75 | + end | |
| 76 | + end | |
| 77 | + end | |
| 78 | + | |
| 79 | + desc "Destroy all main content created by this namespace" | |
| 80 | + task :destroy => :environment do | |
| 81 | + Environment.all.each do |env| | |
| 82 | + if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin") | |
| 83 | + Community["spb"].destroy unless Community["spb"].nil? | |
| 84 | + puts "Main Community destoyed with success!" | |
| 85 | + end | |
| 86 | + end | |
| 87 | + end | |
| 88 | + | |
| 89 | + private | |
| 90 | + | |
| 91 | + def generate_article(software, klass, params, home_page = false) | |
| 92 | + article = klass.new(params) | |
| 93 | + article.body = params[:body] | |
| 94 | + | |
| 95 | + software.articles << article | |
| 96 | + if home_page | |
| 97 | + software.home_page = article | |
| 98 | + end | |
| 99 | + | |
| 100 | + software.save! | |
| 101 | + | |
| 102 | + puts "#{params[:name]} #{klass} successfully created!" | |
| 103 | + end | |
| 104 | +end | ... | ... |