Commit b3c2cadd41d4e191887701cc90c1c689ba6338e6
1 parent
8ac1c994
Exists in
master
and in
5 other branches
Add software template creation and it boxes
Showing
1 changed file
with
137 additions
and
1 deletions
Show diff stats
lib/tasks/templates.rake
| 1 | +#!/bin/env ruby | ||
| 2 | +# encoding: utf-8 | ||
| 3 | + | ||
| 1 | namespace :templates do | 4 | namespace :templates do |
| 2 | namespace :create do | 5 | namespace :create do |
| 3 | 6 | ||
| @@ -13,7 +16,137 @@ namespace :templates do | @@ -13,7 +16,137 @@ namespace :templates do | ||
| 13 | task :software => :environment do | 16 | task :software => :environment do |
| 14 | Environment.all.each do |env| | 17 | Environment.all.each do |env| |
| 15 | if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin") | 18 | if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin") |
| 19 | + software = Community["software"] | ||
| 20 | + | ||
| 21 | + if software.nil? | ||
| 22 | + software = Community.create!(:name => "Software", :identifier => "software") | ||
| 23 | + end | ||
| 24 | + | ||
| 25 | + software.layout_template = "default" | ||
| 26 | + software.is_template = true | ||
| 27 | + | ||
| 28 | + box1 = software.boxes.where(:position => 1).first | ||
| 29 | + box1.blocks.destroy_all | ||
| 30 | + software.save! | ||
| 31 | + | ||
| 32 | + #This box is going to be used for fixed blocks | ||
| 33 | + box2 = software.boxes.where(:position => 2).first | ||
| 34 | + box2.blocks.destroy_all | ||
| 35 | + software.save! | ||
| 36 | + | ||
| 37 | + box3 = software.boxes.where(:position => 3).first | ||
| 38 | + box3.blocks.destroy_all | ||
| 39 | + software.save! | ||
| 16 | puts "Software successfully created!" | 40 | puts "Software successfully created!" |
| 41 | + | ||
| 42 | + categories_block = CategoriesAndTagsBlock.new | ||
| 43 | + categories_block.position = 4 | ||
| 44 | + categories_block.display = "home_page_only" | ||
| 45 | + categories_block.save! | ||
| 46 | + box1.blocks << categories_block | ||
| 47 | + box1.save! | ||
| 48 | + puts "CategoriesAndTagsBlock successfully added to software!" | ||
| 49 | + | ||
| 50 | + main_block = MainBlock.new | ||
| 51 | + main_block.position = 3 | ||
| 52 | + main_block.save! | ||
| 53 | + box1.blocks << main_block | ||
| 54 | + box1.save! | ||
| 55 | + | ||
| 56 | + download_block = DownloadBlock.new | ||
| 57 | + download_block.position = 2 | ||
| 58 | + download_block.name = "Versão X.Y" | ||
| 59 | + download_block.link = "#" | ||
| 60 | + download_block.software_description = "(Windows X, Ubuntu Y, Debian Z)" | ||
| 61 | + download_block.version_news = "#" | ||
| 62 | + download_block.display = "home_page_only" | ||
| 63 | + download_block.save! | ||
| 64 | + box1.blocks << download_block | ||
| 65 | + box1.save! | ||
| 66 | + puts "DownloadBlock successfully added to software!" | ||
| 67 | + | ||
| 68 | + software_information_block = SoftwareInformationBlock.new | ||
| 69 | + software_information_block.position = 1 | ||
| 70 | + software_information_block.display = "home_page_only" | ||
| 71 | + software_information_block.save! | ||
| 72 | + box1.blocks << software_information_block | ||
| 73 | + box1.save! | ||
| 74 | + puts "SoftwareInformation successfully added to software!" | ||
| 75 | + | ||
| 76 | + puts "Software Main Box successfully created!" | ||
| 77 | + | ||
| 78 | + | ||
| 79 | + members_block = MembersBlock.new | ||
| 80 | + members_block.position = 6 | ||
| 81 | + members_block.display = "except_home_page" | ||
| 82 | + members_block.name = "" | ||
| 83 | + members_block.address = "" | ||
| 84 | + members_block.visible_role = "" | ||
| 85 | + members_block.limit = 6 | ||
| 86 | + members_block.prioritize_profiles_with_image = true | ||
| 87 | + members_block.show_join_leave_button = false | ||
| 88 | + members_block.title = "Equipe" | ||
| 89 | + | ||
| 90 | + members_block.save! | ||
| 91 | + box3.blocks << members_block | ||
| 92 | + box3.save! | ||
| 93 | + | ||
| 94 | + another_link_list_block = LinkListBlock.new | ||
| 95 | + another_link_list_block.position = 5 | ||
| 96 | + another_link_list_block.display = "always" | ||
| 97 | + another_link_list_block.title = "Participe" | ||
| 98 | + links = [{"icon"=>"", "name"=>"Lista de E-mails", "address"=>"http://beta.softwarepublico.gov.br/archives/thread/", "target"=>"_self"}, {"icon"=>"no-icon", "name"=>"Comunidade", "address"=>"/profile/{profile}", "target"=>"_self"}, {"icon"=>"", "name"=>"Blog", "address"=>"/{profile}/blog", "target"=>"_self"}, {"icon"=>"no-icon", "name"=>"Fórum", "address"=>"/{profile}/forum-de-duvidas-e-discussao", "target"=>"_self"}, {"icon"=>"", "name"=>"Convide Amigos", "address"=>"/profile/{profile}/invite/friends", "target"=>"_self"}] | ||
| 99 | + | ||
| 100 | + another_link_list_block.save! | ||
| 101 | + box3.blocks << another_link_list_block | ||
| 102 | + another_link_list_block.update_attributes(:links => links) | ||
| 103 | + box3.save! | ||
| 104 | + puts "LinkListBlock successfully added to software!" | ||
| 105 | + | ||
| 106 | + | ||
| 107 | + repository_block = RepositoryBlock.new | ||
| 108 | + repository_block.position = 4 | ||
| 109 | + repository_block.display = "always" | ||
| 110 | + repository_block.title = "" | ||
| 111 | + | ||
| 112 | + repository_block.save! | ||
| 113 | + box3.blocks << repository_block | ||
| 114 | + box3.save! | ||
| 115 | + puts "RepositoryBlock successfully added to software!" | ||
| 116 | + | ||
| 117 | + link_list_block = LinkListBlock.new | ||
| 118 | + link_list_block.position = 3 | ||
| 119 | + link_list_block.display = "always" | ||
| 120 | + link_list_block.title = "Ajuda" | ||
| 121 | + link_list_block.links = [{"icon"=>"no-icon", "name"=>"Download de Versões", "address"=>"/{profile}/versoes", "target"=>"_self"}, {"icon"=>"", "name"=>"Pergutas Frequentes", "address"=>"/{profile}/perguntas-frequentes", "target"=>"_self"}, {"icon"=>"no-icon", "name"=>"README", "address"=>"/{profile}/versoes-estaveis", "target"=>"_self"}, {"icon"=>"", "name"=>"Como Instalar", "address"=>"/{profile}/tutorial-de-instalacao", "target"=>"_self"}, {"icon"=>"", "name"=>"Manuais", "address"=>"/{profile}/manuais-de-usuario", "target"=>"_self"}] | ||
| 122 | + | ||
| 123 | + link_list_block.save! | ||
| 124 | + box3.blocks << link_list_block | ||
| 125 | + link_list_block.update_attributes(:links => links) | ||
| 126 | + box3.save! | ||
| 127 | + puts "LinkListBlock successfully added to software!" | ||
| 128 | + | ||
| 129 | + profile_image_block = ProfileImageBlock.new | ||
| 130 | + profile_image_block.position = 2 | ||
| 131 | + profile_image_block.display = "except_home_page" | ||
| 132 | + profile_image_block.show_name = false | ||
| 133 | + profile_image_block.save! | ||
| 134 | + | ||
| 135 | + box3.blocks << profile_image_block | ||
| 136 | + box3.save! | ||
| 137 | + puts "ProfileImageBlock successfully added to software!" | ||
| 138 | + | ||
| 139 | + statistics_block = StatisticsBlock.new | ||
| 140 | + statistics_block.position = 1 | ||
| 141 | + statistics_block.display = "home_page_only" | ||
| 142 | + statistics_block.save! | ||
| 143 | + box3.blocks << statistics_block | ||
| 144 | + box3.save! | ||
| 145 | + puts "StatisticsBlock successfully added to software!" | ||
| 146 | + puts "MembersBlock successfully added to software!" | ||
| 147 | + puts "Software Box 3 successfully created!" | ||
| 148 | + | ||
| 149 | + puts "Software Template successfully created!" | ||
| 17 | end | 150 | end |
| 18 | end | 151 | end |
| 19 | end | 152 | end |
| @@ -126,9 +259,12 @@ namespace :templates do | @@ -126,9 +259,12 @@ namespace :templates do | ||
| 126 | task :destroy => :environment do | 259 | task :destroy => :environment do |
| 127 | Environment.all.each do |env| | 260 | Environment.all.each do |env| |
| 128 | if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin") | 261 | if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin") |
| 129 | - Community["institution"].destroy | 262 | + Community["institution"].destroy unless Community["institution"].nil? |
| 130 | puts "Institution template destoyed with success!" | 263 | puts "Institution template destoyed with success!" |
| 131 | 264 | ||
| 265 | + Community["software"].destroy unless Community["software"].nil? | ||
| 266 | + puts "Software template destoyed with success!" | ||
| 267 | + | ||
| 132 | user = User["people"] | 268 | user = User["people"] |
| 133 | if !user.nil? | 269 | if !user.nil? |
| 134 | user.person.destroy | 270 | user.person.destroy |