diff --git a/app/helpers/box_organizer_helper.rb b/app/helpers/box_organizer_helper.rb
index 86e2c0d..ca86132 100644
--- a/app/helpers/box_organizer_helper.rb
+++ b/app/helpers/box_organizer_helper.rb
@@ -4,6 +4,34 @@ module BoxOrganizerHelper
7
end
+ #FIXME make this test
+ def display_icon(block)
+
+ image_path = nil
+ plugin = @plugins.fetch_first_plugin(:has_block?, block)
+
+ theme = Theme.new(environment.theme) # remove this
+ if File.exists?(File.join(theme.filesystem_path, 'images', block.icon_path))
+ image_path = File.join(theme.public_path, 'images', block.icon_path)
+ elsif plugin && File.exists?(File.join(Rails.root, 'public', plugin.public_path, 'images', block.icon_path))
+ image_path = File.join('/', plugin.public_path, 'images', block.icon_path)
+ elsif File.exists?(File.join(Rails.root, 'public', 'images', block.icon_path))
+ image_path = block.icon_path
+ else
+ image_path = block.default_icon_path
+ end
+
+ image_tag(image_path, height: '48', width: '48', class: 'block-type-icon', alt: '' )
+ end
+
+ def display_previews(block)
+# def self.previews_path
+# previews = Dir.glob(File.join(images_filesystem_path, 'previews/*')).map do |path|
+# File.join(images_base_url_path, 'previews', File.basename(path))
+# end
+ ''
+ end
+
def icon_selector(icon = 'no-ico')
render :partial => 'icon_selector', :locals => { :icon => icon }
end
diff --git a/app/models/block.rb b/app/models/block.rb
index a189d41..ff6797d 100644
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -116,7 +116,7 @@ class Block < ActiveRecord::Base
# Must be redefined in subclasses to match the description of each block
# type.
def self.description
- '(dummy)'
+ _('nothing')
end
# returns a short description of the block, used when the user sees a list of
@@ -125,20 +125,32 @@ class Block < ActiveRecord::Base
# Must be redefined in subclasses to match the short description of each block
# type.
def self.short_description
- _('(dummy)')
+ self.pretty_name
end
- def self.default_preview
- "/images/block_preview.png"
+ def self.pretty_name
+ self.name.gsub('Block','')
end
- def self.previews
- []
+ #FIXME make this test
+ def self.default_preview
+ "/images/block_preview.png"
end
- def self.icon
- "/images/icon_block.png"
- end
+# #FIXME remove this code
+# def self.previews_path
+# previews = Dir.glob(File.join(images_filesystem_path, 'previews/*')).map do |path|
+# File.join(images_base_url_path, 'previews', File.basename(path))
+# end
+# end
+
+# #FIXME remove this code
+# def self.icon_path
+# icon_path = File.join(images_base_url_path, 'icon.png')
+#puts File.join(images_filesystem_path, 'icon.png').inspect
+##"/plugins/container_block/images/handle_e.png"
+# File.exists?(File.join(images_filesystem_path, 'icon.png')) ? icon_path : default_icon_path
+# end
# Returns the content to be used for this block.
#
@@ -255,4 +267,21 @@ class Block < ActiveRecord::Base
duplicated_block
end
+ #FIXME make this test
+ def self.previews_path
+ base_name = self.name.split('::').last.underscore
+ Dir.glob(File.join('blocks', base_name,'previews/*'))
+ end
+
+ #FIXME make this test
+ def self.icon_path
+ basename = self.name.split('::').last.underscore
+ File.join('blocks', basename, 'icon.png')
+ end
+
+ #FIXME make this test
+ def self.default_icon_path
+ 'icon_block.png'
+ end
+
end
diff --git a/app/models/communities_block.rb b/app/models/communities_block.rb
index b5257b1..bdb1795 100644
--- a/app/models/communities_block.rb
+++ b/app/models/communities_block.rb
@@ -3,9 +3,18 @@ class CommunitiesBlock < ProfileListBlock
attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type
def self.description
+ _("
Display all of your communities.
You could choose the amount of communities will be displayed and you could priorize that profiles with images.
The view all button is always present in the block.
")
+ end
+
+
+ def self.short_description
_('Communities')
end
+ def self.pretty_name
+ _('Communities Block')
+ end
+
def default_title
n_('{#} community', '{#} communities', profile_count)
end
diff --git a/app/models/theme.rb b/app/models/theme.rb
index 6a24801..b87be2f 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -13,8 +13,14 @@ class Theme
Rails.root.join('public', 'user_themes')
end
+ #FIXME make this test changed
def system_themes_dir
- Rails.root.join('public', 'designs', 'themes')
+ Rails.root.join('public', relative_themes_dir)
+ end
+
+ #FIXME make this test
+ def relative_themes_dir
+ File.join('designs', 'themes')
end
def create(id, attributes = {})
@@ -93,6 +99,16 @@ class Theme
config['public'] = value
end
+ #FIXME make this test
+ def public_path
+ File.join('/', self.class.relative_themes_dir, self.id)
+ end
+
+ #FIXME make this test
+ def filesystem_path
+ File.join(self.class.system_themes_dir, self.id)
+ end
+
def ==(other)
other.is_a?(self.class) && (other.id == self.id)
end
diff --git a/app/views/box_organizer/index.html.erb b/app/views/box_organizer/index.html.erb
index 09f40c7..bf7afbc 100644
--- a/app/views/box_organizer/index.html.erb
+++ b/app/views/box_organizer/index.html.erb
@@ -30,9 +30,9 @@
- <%= image_tag(block.icon, height: '48', width: '48', class: 'block-type-icon', alt: '' ) %>
+ <%= display_icon(block) %>
- <%= _(block.description) %>
+ <%= _(block.short_description) %>
<%= draggable_element("block-#{block.name}", :revert => true) %>
diff --git a/app/views/box_organizer/show_block_type_info.html.erb b/app/views/box_organizer/show_block_type_info.html.erb
index e1833df..4674e10 100644
--- a/app/views/box_organizer/show_block_type_info.html.erb
+++ b/app/views/box_organizer/show_block_type_info.html.erb
@@ -1,19 +1,19 @@
- <% if @block.previews.empty? %>
+ <% if @block.previews_path.empty? %>
<% for i in 0..2 %>
<%= image_tag(@block.default_preview, height: '240', width: '384', alt: '') %>
<% end %>
<% else %>
- <% @block.previews.each do |preview| %>
+ <% @block.previews_path.each do |preview| %>
<%= image_tag(preview, height: '240', width: '384', alt: '') %>
<% end %>
<% end %>
diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb
index bbe776d..f5c47af 100644
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -116,7 +116,7 @@ class Noosfero::Plugin
def available_plugin_names
available_plugins.map { |f| File.basename(f).camelize }
end
-
+
def all
@all ||= available_plugins.map{ |dir| (File.basename(dir) + "_plugin").camelize }
end
@@ -154,6 +154,13 @@ class Noosfero::Plugin
File.exists?(File.join(root_path, 'controllers', "#{name.underscore}_admin_controller.rb"))
end
end
+
+
+ #FIXME make this test
+ def has_block?(block)
+ self.class.extra_blocks.keys.include?(block)
+ end
+
def expanded_template(file_path, locals = {})
views_path = Rails.root.join('plugins', "#{self.class.public_name}", 'views')
diff --git a/plugins/breadcrumbs/public/images/blocks/communities_block/icon.png b/plugins/breadcrumbs/public/images/blocks/communities_block/icon.png
new file mode 100644
index 0000000..0802548
Binary files /dev/null and b/plugins/breadcrumbs/public/images/blocks/communities_block/icon.png differ
diff --git a/plugins/breadcrumbs/public/images/blocks/communities_block/previews/edit_block.png b/plugins/breadcrumbs/public/images/blocks/communities_block/previews/edit_block.png
new file mode 100644
index 0000000..3269d95
Binary files /dev/null and b/plugins/breadcrumbs/public/images/blocks/communities_block/previews/edit_block.png differ
diff --git a/plugins/breadcrumbs/public/images/blocks/communities_block/previews/view_block.png b/plugins/breadcrumbs/public/images/blocks/communities_block/previews/view_block.png
new file mode 100644
index 0000000..dd8a959
Binary files /dev/null and b/plugins/breadcrumbs/public/images/blocks/communities_block/previews/view_block.png differ
diff --git a/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/icon.png b/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/icon.png
new file mode 100644
index 0000000..0802548
Binary files /dev/null and b/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/icon.png differ
diff --git a/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/icon2.png b/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/icon2.png
new file mode 100644
index 0000000..ccb0e19
Binary files /dev/null and b/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/icon2.png differ
diff --git a/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/previews/edit_block.png b/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/previews/edit_block.png
new file mode 100644
index 0000000..3269d95
Binary files /dev/null and b/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/previews/edit_block.png differ
diff --git a/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/previews/view_block.png b/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/previews/view_block.png
new file mode 100644
index 0000000..dd8a959
Binary files /dev/null and b/plugins/breadcrumbs/public/images/blocks/content_breadcrumbs_block/previews/view_block.png differ
diff --git a/public/designs/themes/noosfero/images/blocks/communities_block/icon.png b/public/designs/themes/noosfero/images/blocks/communities_block/icon.png
new file mode 100644
index 0000000..986c762
Binary files /dev/null and b/public/designs/themes/noosfero/images/blocks/communities_block/icon.png differ
diff --git a/public/designs/themes/noosfero/images/blocks/communities_block/previews/edit_block.png b/public/designs/themes/noosfero/images/blocks/communities_block/previews/edit_block.png
new file mode 100644
index 0000000..71a1df8
Binary files /dev/null and b/public/designs/themes/noosfero/images/blocks/communities_block/previews/edit_block.png differ
diff --git a/public/designs/themes/noosfero/images/blocks/communities_block/previews/view_block.png b/public/designs/themes/noosfero/images/blocks/communities_block/previews/view_block.png
new file mode 100644
index 0000000..8acb6f8
Binary files /dev/null and b/public/designs/themes/noosfero/images/blocks/communities_block/previews/view_block.png differ
diff --git a/public/images/blocks/communities_block/icon.png b/public/images/blocks/communities_block/icon.png
new file mode 100644
index 0000000..de9bcf0
Binary files /dev/null and b/public/images/blocks/communities_block/icon.png differ
diff --git a/public/images/blocks/communities_block/icon.svg b/public/images/blocks/communities_block/icon.svg
new file mode 100644
index 0000000..c96626f
--- /dev/null
+++ b/public/images/blocks/communities_block/icon.svg
@@ -0,0 +1,643 @@
+
+
+
+
diff --git a/public/images/blocks/communities_block/previews/edit_block.png b/public/images/blocks/communities_block/previews/edit_block.png
new file mode 100644
index 0000000..c5a5dc6
Binary files /dev/null and b/public/images/blocks/communities_block/previews/edit_block.png differ
diff --git a/public/images/blocks/communities_block/previews/view_block.png b/public/images/blocks/communities_block/previews/view_block.png
new file mode 100644
index 0000000..2838908
Binary files /dev/null and b/public/images/blocks/communities_block/previews/view_block.png differ
diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb
index bcf1186..d9a5a6f 100644
--- a/test/unit/block_test.rb
+++ b/test/unit/block_test.rb
@@ -7,6 +7,10 @@ class BlockTest < ActiveSupport::TestCase
assert_kind_of String, Block.description
end
+ should 'describe shotly itself' do
+ assert_kind_of String, Block.short_description
+ end
+
should 'access owner through box' do
user = create_user('testinguser').person
@@ -284,4 +288,80 @@ class BlockTest < ActiveSupport::TestCase
assert_equal block.cache_key('en'), block.cache_key('en', person)
end
+ should 'pretty_name method defined' do
+ assert Block.respond_to?(:pretty_name)
+ end
+
+ should 'previews_path return the array of preview images' do
+ class NewBlock < Block; end
+ Dir.stubs(:glob).returns(['/path/1', 'path/2'])
+ expected = ['blocks/block_test/new_block/previews/1', 'blocks/block_test/new_block/previews/2']
+ assert_equivalent expected, NewBlock.previews_path
+ end
+
+ should 'return the icon block path' do
+ class NewBlock < Block; end
+ File.expects(:exists?).returns(true)
+ expected_path = 'path/icon.png'
+ File.stubs(:join).returns(expected_path)
+ assert_equal expected_path, NewBlock.icon_path
+ end
+
+ should 'return the icon block path for plugin blocks' do
+ module SomeContext class SomeContext::CustomBlock1 < Block; end;;end
+# class SomeContext::CustomBlock2 < Block; end;
+#BreadcrumbsPlugin::ContentBreadcrumbsBlock
+ class Plugin1 < Noosfero::Plugin
+ def self.extra_blocks
+ {
+ CustomBlock1 => {},
+ CustomBlock2 => {}
+ }
+ end
+ end
+
+#Block.stubs(:images_filesystem_path).returns('/path')
+#CustomBlock1.stubs(:images_filesystem_path).returns('/path')
+File.stubs(:exists?).with('/home/81665687568/Owncloud/projetos/noosfero/public/images/blocks/block_test/custom_block1/icon.pn').returns(true)
+# File.exists?(File.join(images_filesystem_path, 'icon.png')) ? icon_path : default_icon_path
+
+
+# def self.images_filesystem_path
+# Rails.root.join('public', 'images', images_base_url_path)
+# end
+#
+# def self.images_base_url_path
+# File.join('blocks', self.name.underscore)
+# end
+
+
+ Environment.destroy_all
+ e = fast_create(Environment, :is_default => true)
+
+# Noosfero::Plugin.stubs(:all).returns(['ProfileTest::Plugin1', 'ProfileTest::Plugin2'])
+ e.enable_plugin(Plugin1)
+
+# class NewBlock < Block; end
+# Dir.stubs(:glob).returns(['/path/1', 'path/2'])
+# expected = ['blocks/block_test/new_block/previews/1', 'blocks/block_test/new_block/previews/2']
+# class NewBlock < Block; end
+# File.expects(:exists?).returns(true)
+# expected_path = 'path/icon.png'
+# File.stubs(:join).returns(expected_path)
+#/plugins/container_block/images/handle_e.png
+ assert_equal '', SomeContext::CustomBlock1.icon_path
+ end
+
+
+ should 'return the default icon for blocks without icon' do
+ class NewBlock < Block; end
+ File.expects(:exists?).returns(false)
+ assert_equal 'icon_block.png', NewBlock.icon_path
+ end
+
+ should 'previews_path return an empty array if there is no preview image' do
+ class NewBlock < Block; end
+ assert_equivalent [], NewBlock.previews_path
+ end
+
end
diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb
index 472199f..5e2043b 100644
--- a/test/unit/communities_block_test.rb
+++ b/test/unit/communities_block_test.rb
@@ -15,6 +15,15 @@ class CommunitiesBlockTest < ActiveSupport::TestCase
assert_not_equal ProfileListBlock.description, CommunitiesBlock.description
end
+ should 'describe shortly itself' do
+ assert_not_equal Block.short_description, CommunitiesBlock.short_description
+ end
+
+ should 'have a pretty name defined' do
+ pretty_name = CommunitiesBlock.name.gsub('Block','')
+ assert_not_equal pretty_name, CommunitiesBlock.pretty_name
+ end
+
should 'list owner communities' do
block = CommunitiesBlock.new
--
libgit2 0.21.2