diff --git a/plugins/context_content/lib/context_content_block.rb b/plugins/context_content/lib/context_content_block.rb deleted file mode 100644 index 6a37366..0000000 --- a/plugins/context_content/lib/context_content_block.rb +++ /dev/null @@ -1,96 +0,0 @@ -class ContextContentBlock < Block - - settings_items :show_name, :type => :boolean, :default => true - settings_items :show_image, :type => :boolean, :default => true - settings_items :show_parent_content, :type => :boolean, :default => true - settings_items :types, :type => Array, :default => ['UploadedFile'] - settings_items :limit, :type => :integer, :default => 6 - - alias :profile :owner - - include Noosfero::Plugin::HotSpot - - def self.description - _('Display context content') - end - - def help - _('This block displays content based on context.') - end - - def available_content_types - @available_content_types ||= [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) - checked_types = types.map {|t| t.constantize} - checked_types + (@available_content_types - checked_types) - end - - def first_content_types - available_content_types.first(first_types_count) - end - - def more_content_types - available_content_types.drop(first_types_count) - end - - def first_types_count - [2, types.length].max - end - - def types=(new_types) - settings[:types] = new_types.reject(&:blank?) - end - - def content_image(content) - block = self - lambda do - if content.image? - image_tag(content.public_filename(:thumb)) - else - extra_class = content.uploaded_file? ? "extension-#{content.extension}" : '' - klasses = [content.icon_name].flatten.map{|name| 'icon-'+name}.join(' ') - content_tag 'div', '', :class => "context-icon #{klasses} #{extra_class}" - end - end - end - - def contents(page, p=1) - return @children unless @children.blank? - if page - @children = page.children.with_types(types).paginate(:per_page => limit, :page => p) - (@children.blank? && show_parent_content) ? contents(page.parent, p) : @children - else - nil - end - end - - def footer - block = self - lambda do - contents = block.contents(@page) - if contents - content_tag('div', - render(:partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => @page.id}), :id => "context_content_more_#{block.id}", :class => "more_button") - else - '' - end - end - end - - def content(args={}) - block = self - lambda do - contents = block.contents(@page) - if !contents.blank? - block_title(block.title) + content_tag('div', - render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents}), :class => 'contents', :id => "context_content_#{block.id}") - else - '' - end - end - end - - def cacheable? - false - end - -end diff --git a/plugins/context_content/lib/context_content_plugin.rb b/plugins/context_content/lib/context_content_plugin.rb index c5c16d1..ad30d33 100644 --- a/plugins/context_content/lib/context_content_plugin.rb +++ b/plugins/context_content/lib/context_content_plugin.rb @@ -9,8 +9,8 @@ class ContextContentPlugin < Noosfero::Plugin end def self.extra_blocks - { - ContextContentBlock => { :type => [Person, Community, Enterprise] } + { + ContextContentPlugin::ContextContentBlock => { :type => [Person, Community, Enterprise] } } end diff --git a/plugins/context_content/lib/context_content_plugin/context_content_block.rb b/plugins/context_content/lib/context_content_plugin/context_content_block.rb new file mode 100644 index 0000000..bf3d081 --- /dev/null +++ b/plugins/context_content/lib/context_content_plugin/context_content_block.rb @@ -0,0 +1,96 @@ +class ContextContentPlugin::ContextContentBlock < Block + + settings_items :show_name, :type => :boolean, :default => true + settings_items :show_image, :type => :boolean, :default => true + settings_items :show_parent_content, :type => :boolean, :default => true + settings_items :types, :type => Array, :default => ['UploadedFile'] + settings_items :limit, :type => :integer, :default => 6 + + alias :profile :owner + + include Noosfero::Plugin::HotSpot + + def self.description + _('Display context content') + end + + def help + _('This block displays content based on context.') + end + + def available_content_types + @available_content_types ||= [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) + checked_types = types.map {|t| t.constantize} + checked_types + (@available_content_types - checked_types) + end + + def first_content_types + available_content_types.first(first_types_count) + end + + def more_content_types + available_content_types.drop(first_types_count) + end + + def first_types_count + [2, types.length].max + end + + def types=(new_types) + settings[:types] = new_types.reject(&:blank?) + end + + def content_image(content) + block = self + lambda do + if content.image? + image_tag(content.public_filename(:thumb)) + else + extra_class = content.uploaded_file? ? "extension-#{content.extension}" : '' + klasses = [content.icon_name].flatten.map{|name| 'icon-'+name}.join(' ') + content_tag 'div', '', :class => "context-icon #{klasses} #{extra_class}" + end + end + end + + def contents(page, p=1) + return @children unless @children.blank? + if page + @children = page.children.with_types(types).paginate(:per_page => limit, :page => p) + (@children.blank? && show_parent_content) ? contents(page.parent, p) : @children + else + nil + end + end + + def footer + block = self + lambda do + contents = block.contents(@page) + if contents + content_tag('div', + render(:partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => @page.id}), :id => "context_content_more_#{block.id}", :class => "more_button") + else + '' + end + end + end + + def content(args={}) + block = self + lambda do + contents = block.contents(@page) + if !contents.blank? + block_title(block.title) + content_tag('div', + render(:file => 'blocks/context_content', :locals => {:block => block, :contents => contents}), :class => 'contents', :id => "context_content_#{block.id}") + else + '' + end + end + end + + def cacheable? + false + end + +end diff --git a/plugins/context_content/test/functional/content_viewer_controller_test.rb b/plugins/context_content/test/functional/content_viewer_controller_test.rb index 5487a86..d3f8d75 100644 --- a/plugins/context_content/test/functional/content_viewer_controller_test.rb +++ b/plugins/context_content/test/functional/content_viewer_controller_test.rb @@ -14,7 +14,7 @@ class ContentViewerControllerTest < ActionController::TestCase @page = fast_create(Folder, :profile_id => @profile.id) box = Box.create!(:owner => @profile) - @block = ContextContentBlock.new(:box => box) + @block = ContextContentPlugin::ContextContentBlock.new(:box => box) @block.types = ['TinyMceArticle'] @block.limit = 1 @block.save! diff --git a/plugins/context_content/test/functional/context_content_plugin_profile_controller_test.rb b/plugins/context_content/test/functional/context_content_plugin_profile_controller_test.rb index 43509be..b55ae73 100644 --- a/plugins/context_content/test/functional/context_content_plugin_profile_controller_test.rb +++ b/plugins/context_content/test/functional/context_content_plugin_profile_controller_test.rb @@ -6,7 +6,7 @@ class ContextContentPluginProfileControllerTest < ActionController::TestCase def setup @profile = fast_create(Community) - @block = ContextContentBlock.new + @block = ContextContentPlugin::ContextContentBlock.new @block.types = ['TinyMceArticle'] @block.limit = 1 @block.save! diff --git a/plugins/context_content/test/functional/profile_design_controller_test.rb b/plugins/context_content/test/functional/profile_design_controller_test.rb index 15225d1..2f7810e 100644 --- a/plugins/context_content/test/functional/profile_design_controller_test.rb +++ b/plugins/context_content/test/functional/profile_design_controller_test.rb @@ -19,7 +19,7 @@ class ProfileDesignControllerTest < ActionController::TestCase @page = fast_create(Folder, :profile_id => @profile.id) box = Box.create!(:owner => @profile) - @block = ContextContentBlock.new(:box => box) + @block = ContextContentPlugin::ContextContentBlock.new(:box => box) @block.types = ['TinyMceArticle'] @block.limit = 1 @block.save! diff --git a/plugins/context_content/test/unit/context_content_block_test.rb b/plugins/context_content/test/unit/context_content_block_test.rb index 2d3cb06..e8551ea 100644 --- a/plugins/context_content/test/unit/context_content_block_test.rb +++ b/plugins/context_content/test/unit/context_content_block_test.rb @@ -4,12 +4,12 @@ class ContextContentBlockTest < ActiveSupport::TestCase def setup Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) - @block = ContextContentBlock.create! + @block = ContextContentPlugin::ContextContentBlock.create! @block.types = ['TinyMceArticle'] end should 'describe itself' do - assert_not_equal Block.description, ContextContentBlock.description + assert_not_equal Block.description, ContextContentPlugin::ContextContentBlock.description end should 'has a help' do @@ -170,7 +170,7 @@ class ContextContentBlockTest < ActiveSupport::TestCase should 'return box owner on profile method call' do profile = fast_create(Community) box = Box.create(:owner_type => 'Profile', :owner_id => profile.id) - block = ContextContentBlock.create!(:box => box) + block = ContextContentPlugin::ContextContentBlock.create!(:box => box) assert_equal profile, block.profile end diff --git a/plugins/context_content/test/unit/context_content_plugin_test.rb b/plugins/context_content/test/unit/context_content_plugin_test.rb index 5c55b41..88e8b2b 100644 --- a/plugins/context_content/test/unit/context_content_plugin_test.rb +++ b/plugins/context_content/test/unit/context_content_plugin_test.rb @@ -20,7 +20,7 @@ class ContextContentPluginTest < ActiveSupport::TestCase end should 'return ContextContentBlock in extra_blocks class method' do - assert ContextContentPlugin.extra_blocks.keys.include?(ContextContentBlock) + assert ContextContentPlugin.extra_blocks.keys.include?(ContextContentPlugin::ContextContentBlock) end should 'return false for class method has_admin_url?' do @@ -28,11 +28,11 @@ class ContextContentPluginTest < ActiveSupport::TestCase end should 'ContextContentBlock not available for environment' do - assert_not_includes plugins.dispatch(:extra_blocks, :type => Environment), ContextContentBlock + assert_not_includes plugins.dispatch(:extra_blocks, :type => Environment), ContextContentPlugin::ContextContentBlock end should 'ContextContentBlock available for community' do - assert_includes plugins.dispatch(:extra_blocks, :type => Community), ContextContentBlock + assert_includes plugins.dispatch(:extra_blocks, :type => Community), ContextContentPlugin::ContextContentBlock end should 'has stylesheet' do @@ -41,7 +41,7 @@ class ContextContentPluginTest < ActiveSupport::TestCase [Person, Community, Enterprise].each do |klass| should "ContextContentBlock be available for #{klass.name}" do - assert_includes plugins.dispatch(:extra_blocks, :type => klass), ContextContentBlock + assert_includes plugins.dispatch(:extra_blocks, :type => klass), ContextContentPlugin::ContextContentBlock end end diff --git a/plugins/context_content/views/box_organizer/_context_content_block.rhtml b/plugins/context_content/views/box_organizer/_context_content_block.rhtml deleted file mode 100644 index 5c98787..0000000 --- a/plugins/context_content/views/box_organizer/_context_content_block.rhtml +++ /dev/null @@ -1,23 +0,0 @@ -
- <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %> - <%= labelled_form_field check_box(:block, :show_name) + _('Show content name'), '' %> - <%= labelled_form_field check_box(:block, :show_image) + _('Show content image'), '' %> - <%= labelled_form_field check_box(:block, :show_parent_content) + _('Show parent content when children is empty'), '' %> - -
- <%= label :block, :types, _('Display content types:'), :class => 'formlabel' %> -
- <% @block.first_content_types.each do |type| %> - <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> - <% end %> - <% if !@block.more_content_types.empty? %> - <%= _('more') %> - <% end %> - -
-
-
diff --git a/plugins/context_content/views/box_organizer/context_content_plugin/_context_content_block.rhtml b/plugins/context_content/views/box_organizer/context_content_plugin/_context_content_block.rhtml new file mode 100644 index 0000000..29fa941 --- /dev/null +++ b/plugins/context_content/views/box_organizer/context_content_plugin/_context_content_block.rhtml @@ -0,0 +1,23 @@ +
+ <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %> + <%= labelled_form_field check_box(:block, :show_name) + _('Show content name'), '' %> + <%= labelled_form_field check_box(:block, :show_image) + _('Show content image'), '' %> + <%= labelled_form_field check_box(:block, :show_parent_content) + _('Show parent content when children is empty'), '' %> + +
+ <%= label :block, :types, _('Display content types:'), :class => 'formlabel' %> +
+ <% @block.first_content_types.each do |type| %> + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> + <% end %> + <% if !@block.more_content_types.empty? %> + <%= _('more') %> + <% end %> + +
+
+
diff --git a/plugins/context_content/views/profile_design b/plugins/context_content/views/profile_design deleted file mode 120000 index a75d184..0000000 --- a/plugins/context_content/views/profile_design +++ /dev/null @@ -1 +0,0 @@ -box_organizer \ No newline at end of file diff --git a/plugins/context_content/views/profile_design/context_content_plugin b/plugins/context_content/views/profile_design/context_content_plugin new file mode 120000 index 0000000..721663b --- /dev/null +++ b/plugins/context_content/views/profile_design/context_content_plugin @@ -0,0 +1 @@ +../box_organizer/context_content_plugin/ \ No newline at end of file -- libgit2 0.21.2