Commit 70c00cdbfef5815dae4dc220dd80974ac7ab2ce5

Authored by Arthur Esposte
1 parent d1ab5571
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Create task to populate the main content

Showing 1 changed file with 104 additions and 0 deletions   Show diff stats
lib/tasks/main_data.rake 0 → 100644
... ... @@ -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
... ...