From f81b2eafb36b724aa17a3454da91e4803f694d04 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Mon, 1 Dec 2014 17:36:04 +0000 Subject: [PATCH] Add categories software block for home page --- README.md | 7 +++++++ lib/categories_software_block.rb | 29 +++++++++++++++++++++++++++++ lib/ext/category.rb | 11 +++++++++++ lib/mpog_software_plugin.rb | 3 ++- test/unit/categories_software_block_test.rb | 19 +++++++++++++++++++ views/blocks/categories_software.html.erb | 24 ++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 lib/categories_software_block.rb create mode 100644 lib/ext/category.rb create mode 100644 test/unit/categories_software_block_test.rb create mode 100644 views/blocks/categories_software.html.erb diff --git a/README.md b/README.md index dbec7e1..28d86a2 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,13 @@ Schedule Institutions Update ./plugins/mpog_software/script/schedule_institution_update.sh +Create Categories +------------------- + +To create the categories that a software can have run + +rake software:create_categories + Running MPOG Software tests -------------------- $ ruby plugins/mpog_software/test/unit/name_of_file.rb diff --git a/lib/categories_software_block.rb b/lib/categories_software_block.rb new file mode 100644 index 0000000..854150c --- /dev/null +++ b/lib/categories_software_block.rb @@ -0,0 +1,29 @@ +class CategoriesSoftwareBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Categories Softwares') + end + + def help + _('This block displays the categories and the amount of softwares for each categorie.') + end + + def content(args={}) + block = self + s = show_name + lambda do |object| + render( + :file => 'blocks/categories_software', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + false + end +end diff --git a/lib/ext/category.rb b/lib/ext/category.rb new file mode 100644 index 0000000..286990a --- /dev/null +++ b/lib/ext/category.rb @@ -0,0 +1,11 @@ +require_dependency 'category' + +class Category + + def software_infos + software_list = self.communities + software_list.collect{|x| software_list.delete(x) unless x.software? } + software_list + end + +end diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index c3fb09b..947ac73 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -126,7 +126,8 @@ class MpogSoftwarePlugin < Noosfero::Plugin InstitutionsBlock => {:type => [Environment, Person]}, DownloadBlock => {:type => [Community]}, RepositoryBlock => {:type => [Community]}, - CategoriesAndTagsBlock => {:type => [Community]} + CategoriesAndTagsBlock => {:type => [Community]}, + CategoriesSoftwareBlock => {:type => [Environment]} } end diff --git a/test/unit/categories_software_block_test.rb b/test/unit/categories_software_block_test.rb new file mode 100644 index 0000000..b02f9b4 --- /dev/null +++ b/test/unit/categories_software_block_test.rb @@ -0,0 +1,19 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' + +class CategoriesSoftwareBlockTest < ActiveSupport::TestCase + include PluginTestHelper + should 'inherit from Block' do + assert_kind_of Block, CategoriesSoftwareBlock.new + end + + should 'declare its default title' do + CategoriesSoftwareBlock.any_instance.stubs(:profile_count).returns(0) + assert_equal Block.new.default_title, CategoriesSoftwareBlock.new.default_title + end + + should 'describe itself' do + assert_not_equal Block.description, CategoriesSoftwareBlock.description + end + +end diff --git a/views/blocks/categories_software.html.erb b/views/blocks/categories_software.html.erb new file mode 100644 index 0000000..62857cd --- /dev/null +++ b/views/blocks/categories_software.html.erb @@ -0,0 +1,24 @@ +
+ + +
+

<%= _("Categories:") %>

+
    + + <% Category.all.each do |category| %> + <% if category.name != "Software" %> +
  • <%= link_to category.name + " (#{category.software_infos.count})", "#" %>
  • + <% end %> + <% end %> +
+
+
\ No newline at end of file -- libgit2 0.21.2