Skip to content

Commit

Permalink
adding community block plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
maljunior committed Nov 1, 2013
1 parent ce0d03a commit 5acb61d
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugins/community_block/lib/community_block.rb
@@ -0,0 +1,19 @@
class CommunityBlock < Block

def self.description
"Community block"
end

def help
"Help for Community Description Block."
end

def content(arg={})
block = self

lambda do
render :file => 'community_block', :locals => { :block => block }
end
end

end
27 changes: 27 additions & 0 deletions plugins/community_block/lib/community_block_plugin.rb
@@ -0,0 +1,27 @@
require_dependency File.dirname(__FILE__) + '/community_block'

class CommunityBlockPlugin < Noosfero::Plugin

def self.plugin_name
"Community Block Plugin"
end

def self.plugin_description
"A plugin that adds a block to show community description"
end

def self.extra_blocks
{
CommunityBlock => {:type => Community}
}
end

def self.has_admin_url?
false
end

def stylesheet?
true
end

end
43 changes: 43 additions & 0 deletions plugins/community_block/public/style.css
@@ -0,0 +1,43 @@
#content .box-1 .community-block {
//border: 1px solid #F00;
display: table;
width: 100%;
}

#content .box-1 .community-block .community-block-logo {
//border: 1px solid #00F;
float: left;
width: 150px;
height: 150px;
padding: 5px;
}

#content .box-1 .community-block-info {
//border: 1px solid #000;
float: left;
padding: 5px;
width: 360px;
margin-left: 2px;
}

#content .box-1 .community-block .community-block-title {
//border: 1px solid #00F;
font-variant: small-caps;
color: #555753;
text-align: left;
padding-left: 10px;
margin: 0px;
}

#content .box-1 .community-block .community-block-description {
//border: 1px solid #0F0;
font-style: italic;
color: black;
padding: 10px;
}

#content .box-1 .community-block .community-block-buttons {
//border: 1px solid #F00;
text-align: right;
}

@@ -0,0 +1,66 @@
require File.dirname(__FILE__) + '/../test_helper'

# Re-raise errors caught by the controller.
class ProfileController
append_view_path File.join(File.dirname(__FILE__) + '/../../views')
def rescue_action(e)
raise e
end
end

class ProfileControllerTest < ActionController::TestCase

def setup
@controller = ProfileController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

#user = create_user('testinguser')
#login_as(user.login)

@community = fast_create(Community, :environment_id => Environment.default)

@environment = @community.environment
@environment.enabled_plugins = ['CommunityBlock']
@environment.save!

CommunityBlock.delete_all
@box1 = Box.create!(:owner => @community)
@community.boxes = [@box1]

@block = CommunityBlock.new
@block.box = @box1
@block.save!

@community.blocks<<@block
@community.save!
end

attr_accessor :profile, :block, :community

should 'display community-block-logo class in community block' do
get :index, :profile => community.identifier
assert_tag :div, :attributes => {:class => 'community-block-logo'}
end

should 'display community-block-info class in community block' do
get :index, :profile => community.identifier
assert_tag :div, :attributes => {:class => 'community-block-info'}
end

should 'display community-block-title class in community block' do
get :index, :profile => community.identifier
assert_tag :h1, :attributes => {:class => 'community-block-title'}
end

should 'display community-block-description class in community block' do
get :index, :profile => community.identifier
assert_tag :div, :attributes => {:class => 'community-block-description'}
end

should 'display community-block-buttons class in community block' do
get :index, :profile => community.identifier
assert_tag :div, :attributes => {:class => 'community-block-buttons'}
end

end
1 change: 1 addition & 0 deletions plugins/community_block/test/test_helper.rb
@@ -0,0 +1 @@
require File.dirname(__FILE__) + '/../../../test/test_helper'
33 changes: 33 additions & 0 deletions plugins/community_block/test/unit/commmunity_block_plugin_test.rb
@@ -0,0 +1,33 @@
require File.dirname(__FILE__) + '/../test_helper'

class CommunityBlockPluginTest < ActiveSupport::TestCase

def setup
@plugin = CommunityBlockPlugin.new
end

should 'be a noosfero plugin' do
assert_kind_of Noosfero::Plugin, @plugin
end

should 'have name' do
assert_equal 'Community Block Plugin', CommunityBlockPlugin.plugin_name
end

should 'have description' do
assert_equal "A plugin that adds a block to show community description", CommunityBlockPlugin.plugin_description
end

should 'have stylesheet' do
assert @plugin.stylesheet?
end

should "return CommunityBlock in extra_blocks class method" do
assert CommunityBlockPlugin.extra_blocks.keys.include?(CommunityBlock)
end

should "return false for class method has_admin_url?" do
assert !CommunityBlockPlugin.has_admin_url?
end

end
11 changes: 11 additions & 0 deletions plugins/community_block/test/unit/commmunity_block_test.rb
@@ -0,0 +1,11 @@
require File.dirname(__FILE__) + '/../test_helper'

class CommunityBlockTest < ActiveSupport::TestCase

should "display community block" do
block = CommunityBlock.new
self.expects(:render).with(:file => 'community_block', :locals => { :block => block })
instance_eval(& block.content)
end

end
38 changes: 38 additions & 0 deletions plugins/community_block/views/community_block.rhtml
@@ -0,0 +1,38 @@
<div class="community-block">
<div class="community-block-logo">
<%= link_to profile_image(profile, :big), profile.url %>
</div>
<div class="community-block-info">
<h1 class="community-block-title"><%=profile.name%></h1>
<div class="community-block-description"><%= profile.description %></div>
<div class="community-block-buttons">
<% if logged_in? %>
<% if profile.members.include?(user) %>
<%= button(:delete, content_tag('span', __('Leave community')), profile.leave_url,
:class => 'leave-community',
:title => _("Leave community"),
:style => 'position: relative;') %>
<%= button(:add, content_tag('span', __('Join')), profile.join_url,
:class => 'join-community',
:title => _("Join community"),
:style => 'position: relative; display: none;') %>
<% else %>
<% unless profile.already_request_membership?(user) %>
<%= button(:delete, content_tag('span', __('Leave community')), profile.leave_url,
:class => 'leave-community',
:title => _("Leave community"),
:style => 'position: relative; display: none;') %>
<%= button(:add, content_tag('span', __('Join')), profile.join_url,
:class => 'join-community',
:title => _("Join community"),
:style => 'position: relative;') %>
<% end %>
<% end %>
<% else %>
<%= link_to content_tag('span', _('Join')), profile.join_not_logged_url, :class => 'button with-text icon-add', :title => _("Join comunity") %>
<% end %>
</div>
</div>
<div style="clear:both"></div>
</div>

0 comments on commit 5acb61d

Please sign in to comment.