From 4399cbfe667cdafd78b562c649bb6c296ecef1a2 Mon Sep 17 00:00:00 2001 From: Luciano Prestes Cavalcanti Date: Wed, 26 Nov 2014 08:57:05 -0200 Subject: [PATCH] Add repository block --- lib/download_block.rb | 2 +- lib/mpog_software_plugin.rb | 5 +++-- lib/repository_block.rb | 30 ++++++++++++++++++++++++++++++ test/unit/repository_block_test.rb | 28 ++++++++++++++++++++++++++++ views/blocks/repository.html.erb | 1 + views/box_organizer/_repository_block.html.erb | 3 +++ 6 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 lib/repository_block.rb create mode 100644 test/unit/repository_block_test.rb create mode 100644 views/blocks/repository.html.erb create mode 100644 views/box_organizer/_repository_block.html.erb diff --git a/lib/download_block.rb b/lib/download_block.rb index 567dd5c..ddd22e8 100644 --- a/lib/download_block.rb +++ b/lib/download_block.rb @@ -1,6 +1,6 @@ class DownloadBlock < Block - attr_accessible :name, :link, :software_description,:show_name, :version_news + attr_accessible :name, :link, :software_description, :show_name, :version_news settings_items :name, :type => :string, :default => '' settings_items :link, :type => :string, :default => '' diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index bd9b567..159307f 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -129,7 +129,8 @@ class MpogSoftwarePlugin < Noosfero::Plugin SoftwaresBlock => {:type => [Environment, Person] }, SoftwareInformationBlock => {:type => [Community] }, InstitutionsBlock => {:type => [Environment, Person]}, - DownloadBlock => {:type => [Community]} + DownloadBlock => {:type => [Community]}, + RepositoryBlock => {:type => [Community]} } end @@ -221,7 +222,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin required_list[:person_fields].each do |field| if person.send(field).blank? - empty_fields << field.sub("_"," ") + empty_fields << field.sub("_"," ") end end required_list[:user_fields].each do |field| diff --git a/lib/repository_block.rb b/lib/repository_block.rb new file mode 100644 index 0000000..59d1254 --- /dev/null +++ b/lib/repository_block.rb @@ -0,0 +1,30 @@ +class RepositoryBlock < Block + + attr_accessible :link, :show_name + + settings_items :link, :type => :string, :default => '' + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Repository Link') + end + + def help + _('This block displays the repository link of a software.') + end + + def content(args={}) + block = self + s = show_name + lambda do |object| + render( + :file => 'blocks/repository', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + false + end +end diff --git a/test/unit/repository_block_test.rb b/test/unit/repository_block_test.rb new file mode 100644 index 0000000..ccc6889 --- /dev/null +++ b/test/unit/repository_block_test.rb @@ -0,0 +1,28 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' + +class RepositoryBlockTest < ActiveSupport::TestCase + include PluginTestHelper + + should 'inherit from Block' do + assert_kind_of Block, RepositoryBlock.new + end + + should 'declare its default title' do + RepositoryBlock.any_instance.stubs(:profile_count).returns(0) + assert_equal Block.new.default_title, RepositoryBlock.new.default_title + end + + should 'describe itself' do + assert_not_equal Block.description, RepositoryBlock.description + end + + should 'have software info to repository it' do + + link = "gitlab.com/teste" + + block = RepositoryBlock.create(:link => link) + + assert_equal block.link, link, "Link should not be empty" + end +end diff --git a/views/blocks/repository.html.erb b/views/blocks/repository.html.erb new file mode 100644 index 0000000..47968b0 --- /dev/null +++ b/views/blocks/repository.html.erb @@ -0,0 +1 @@ +<%= link_to _("Repositorio") , block.link, :id => "bt_repositorio", :target => "_blank" %> \ No newline at end of file diff --git a/views/box_organizer/_repository_block.html.erb b/views/box_organizer/_repository_block.html.erb new file mode 100644 index 0000000..8562145 --- /dev/null +++ b/views/box_organizer/_repository_block.html.erb @@ -0,0 +1,3 @@ +
+ <%= labelled_form_field _('Link:'), text_field_tag('block[link]', @block.link) %> +
-- libgit2 0.21.2