diff --git a/plugins/recent_content/README b/plugins/recent_content/README new file mode 100644 index 0000000..89d498e --- /dev/null +++ b/plugins/recent_content/README @@ -0,0 +1,69 @@ +README - RecentContent (RecentContent Plugin) +================================ + +RecentContent is a plugin that provides a blog which displays the content posted inside a blog choosen by the user. + +The RecentContent block will be available for all layout columns of communities, people, enterprises and environments. + +The articles posted from the choosen blog are displayed as a list with a link for the title and optionally the abstract/lead content. + +If the choosen blog has a cover image, the user can configure the block to show the same image displayed on that blog. + +Galleries and folders are not displayed in this block. + +INSTALL +======= + +Enable Plugin +------------- + +Also, you need to enable RecentContent Plugin at your Noosfero: + +cd +./script/noosfero-plugins enable recent_content + +Active Plugin +------------- + +As a Noosfero administrator user, go to administrator panel: + +- Click on "Enable/disable plugins" option +- Click on "Recent Content Plugin" check-box + +DEVELOPMENT +=========== + +Get the Recent Content (Noosfero with Recent Content Plugin) development repository: + +$ git clone https://github.com/fga-unb/noosfero/tree/AI2848-block_recent_articles + +Running RecentContent tests +-------------------- + +$ rake test:noosfero_plugins:recent_content + + +Get Involved +============ + +If you found any bug and/or want to collaborate, please send an e-mail to contato@valessiobrito.com.br + +LICENSE +======= + +Copyright (c) The Author developers. + +See Noosfero license. + + +AUTHORS +======= + David Carlos (ddavidcarlos1392 at gmail.com) + Gabriela Navarro (navarro1703 at gmail.com) + Marcos Ramos (ms.ramos at outlook.com) + Valessio Brito (contato at valessiobrito.com.br) + +ACKNOWLEDGMENTS +=============== + +The author have been supported by FGA - UnB and Lappis diff --git a/plugins/recent_content/features/add_recent_content.feature b/plugins/recent_content/features/add_recent_content.feature new file mode 100644 index 0000000..730bd3a --- /dev/null +++ b/plugins/recent_content/features/add_recent_content.feature @@ -0,0 +1,91 @@ +Feature: + As a logged user + I want to manage a recent content block + +Background: + Given the following users + | login | name | + | joaosilva | Joao Silva | + And the following plugin + | klass | + | RecentContent | + And plugin RecentContent is enabled on environment + And the following blocks + | owner | type | + | joaosilva | RecentContentBlock | + And the following articles + | owner | parent | name | body | abstract | + | joaosilva | JSilva blog | post #1 | Primeiro post do joao silva | Resumo 1 | + | joaosilva | JSilva blog | post #2 | Segundo post do joao silva | Resumo 2 | + | joaosilva | JSilva blog | post #3 | Terceiro post do joao silva | Resumo 3 | + | joaosilva | JSilva blog | post #4 | Quarto post do joao silva | Resumo 4 | + | joaosilva | JSilva blog | post #5 | Quinto post do joao silva | Resumo 5 | + | joaosilva | JSilva blog | post #6 | Sexto post do joao silva | Resumo 6 | + And I am logged in as "joaosilva" + Given I go to joaosilva's control panel + And I follow "Edit sideboxes" + And I follow "Add a block" + And I choose "Recent content" + And I press "Add" + + Scenario: the block is being displayed + Then I should see "This is the recent content block. Please edit it to show the content you want." + + Scenario: a user should be redirected to the post page when the link is clicked + When I follow "Edit" within ".recent-content-block" + And I select "JSilva blog" from "Choose which blog should be displayed" + And I select "Title only" from "Choose how the content should be displayed" + And I fill in "Choose how many items will be displayed" with "3" + And I press "Save" + And I follow "post #4" within ".recent-content-block" + Then I should be on /joaosilva/jsilva-blog/post-4 + + Scenario: a user should be redirected to the blog page when the "view all" is clicked + When I follow "Edit" within ".recent-content-block" + And I select "JSilva blog" from "Choose which blog should be displayed" + And I select "Title only" from "Choose how the content should be displayed" + And I fill in "Choose how many items will be displayed" with "2" + And I press "Save" + And I follow "View All" + Then I should be on /joaosilva/jsilva-blog + + Scenario: a user should see only titles if the block was configured for it + When I follow "Edit" within ".recent-content-block" + And I select "JSilva blog" from "Choose which blog should be displayed" + And I select "Title only" from "Choose how the content should be displayed" + And I fill in "Choose how many items will be displayed" with "3" + And I press "Save" + Then I should see "post #6" within ".recent-content-block" + + Scenario: a user should see titles and abstract if the block was configured for it + When I follow "Edit" within ".recent-content-block" + And I select "JSilva blog" from "Choose which blog should be displayed" + And I select "Title and abstract" from "Choose how the content should be displayed" + And I fill in "Choose how many items will be displayed" with "6" + And I press "Save" + Then I should see "Resumo 5" within ".recent-content-block" + + Scenario: a user should see full content if the block was configured for it + When I follow "Edit" within ".recent-content-block" + And I select "JSilva blog" from "Choose which blog should be displayed" + And I select "Full content" from "Choose how the content should be displayed" + And I fill in "Choose how many items will be displayed" with "6" + And I press "Save" + Then I should see "Quinto post do joao silva" within ".recent-content-block" + + # the step for attaching a file on the input only works with capybara 1.1.2, but it requires rails 1.9.3 + @selenium-fixme + Scenario: the user should see the blog cover image if configured and the image is available + Given I go to joaosilva's control panel + And I follow "Configure blog" + And I attach the file "public/images/rails.png" to "Uploaded data" + And I press "Save" + When I go to joaosilva's control panel + And I follow "Edit sideboxes" + And I follow "Edit" within ".recent-content-block" + And I select "JSilva blog" from "Choose which blog should be displayed" + And I select "Title only" from "Choose how the content should be displayed" + And I fill in "Choose how many items will be displayed" with "3" + And I check "Display blog cover image" + And I press "Save" + Then there should be a div with class "recent-content-cover" diff --git a/plugins/recent_content/lib/recent_content_block.rb b/plugins/recent_content/lib/recent_content_block.rb new file mode 100644 index 0000000..200a9ca --- /dev/null +++ b/plugins/recent_content/lib/recent_content_block.rb @@ -0,0 +1,58 @@ +class RecentContentBlock < Block + + settings_items :presentation_mode, :type => String, :default => 'title_only' + settings_items :total_items, :type => Integer, :default => 5 + settings_items :show_blog_picture, :type => :boolean, :default => false + settings_items :selected_folder, :type => Integer + + VALID_CONTENT = ['RawHTMLArticle', 'TextArticle', 'TextileArticle', 'TinyMceArticle'] + + def self.description + _('Recent content') + end + + def help + _('This block displays all articles inside the blog you choose. You can edit the block to select which of your blogs is going to be displayed in the block.') + end + + def articles_of_folder(folder, limit) + holder.articles.all(:conditions => {:type => VALID_CONTENT, :parent_id => folder.id}, + :order => 'created_at DESC', + :limit => limit ) + end + + def holder + return nil if self.box.nil? || self.box.owner.nil? + if self.box.owner.kind_of?(Environment) + return nil if self.box.owner.portal_community.nil? + self.box.owner.portal_community + else + self.box.owner + end + end + + def parents + selected = self.holder.articles.all(:conditions => {:type => 'Blog'}) + end + + def root + unless self.selected_folder.nil? + holder.articles.where(:id => self.selected_folder).first + end + end + + include ActionController::UrlWriter + include DatesHelper + + def content(args={}) + block = self + lambda do + render :file => 'blocks/recent_content_block', :locals => {:root => block.root, :block => block} + end + end + + def mode?(attr) + attr == self.presentation_mode + end + +end diff --git a/plugins/recent_content/lib/recent_content_plugin.rb b/plugins/recent_content/lib/recent_content_plugin.rb new file mode 100644 index 0000000..8c15399 --- /dev/null +++ b/plugins/recent_content/lib/recent_content_plugin.rb @@ -0,0 +1,27 @@ +require_dependency File.dirname(__FILE__) + '/recent_content_block' + +class RecentContentPlugin < Noosfero::Plugin + + def self.plugin_name + "Recent Content Plugin" + end + + def self.plugin_description + _("A plugin that adds a block where you can display the content of any of your blogs.") + end + + def self.extra_blocks + { + RecentContentBlock => {:position => ['1','2','3'] } + } + end + + def self.has_admin_url? + false + end + + def stylesheet? + true + end + +end diff --git a/plugins/recent_content/public/images/li-recent.gif b/plugins/recent_content/public/images/li-recent.gif new file mode 100644 index 0000000..a27fa90 Binary files /dev/null and b/plugins/recent_content/public/images/li-recent.gif differ diff --git a/plugins/recent_content/public/style.css b/plugins/recent_content/public/style.css new file mode 100644 index 0000000..aae258a --- /dev/null +++ b/plugins/recent_content/public/style.css @@ -0,0 +1,35 @@ +#content .recent-content-block { + padding: 10px 0px 10px 10px; + overflow: hidden; +} +.recent-content-block ul { + margin: 0px; + padding: 0px 0px 0px 20px; +} +.recent-content-block li { + margin: 0px; + padding: 0px; +} +.recent-content-block a { + text-decoration: none; +} +.recent-content-block .block-footer-content { + font-size: 10px; +} +.recent-content-block .block-footer-content a:hover { + text-decoration: underline; +} +.recent-content-block li { + list-style-image: url('images/li-recent.gif'); + padding: 5px 0px; +} +.recent-content-cover { + overflow: hidden; + display: block; + width: 100%; + max-height: 90px; +} +.recent-content-cover img { + width: 100%; +} + diff --git a/plugins/recent_content/test/test_helper.rb b/plugins/recent_content/test/test_helper.rb new file mode 100644 index 0000000..cca1fd3 --- /dev/null +++ b/plugins/recent_content/test/test_helper.rb @@ -0,0 +1 @@ +require File.dirname(__FILE__) + '/../../../test/test_helper' diff --git a/plugins/recent_content/test/unit/recent_content_block_test.rb b/plugins/recent_content/test/unit/recent_content_block_test.rb new file mode 100644 index 0000000..82cd5de --- /dev/null +++ b/plugins/recent_content/test/unit/recent_content_block_test.rb @@ -0,0 +1,75 @@ +require File.dirname(__FILE__) + '/../test_helper' +class RecentContentBlockTest < ActiveSupport::TestCase + + INVALID_KIND_OF_ARTICLE = [EnterpriseHomepage, RssFeed, UploadedFile, Gallery, Folder, Blog, Forum] + VALID_KIND_OF_ARTICLE = [RawHTMLArticle, TextArticle, TextileArticle, TinyMceArticle] + + should 'describe itself' do + assert_not_equal Block.description, RecentContentBlock.description + end + + should 'is editable' do + block = RecentContentBlock.new + assert block.editable? + end + + should 'blog_picture be false by default' do + block = RecentContentBlock.new + assert !block.show_blog_picture + end + + should 'blog_picture is being stored and restored from database as true' do + block = RecentContentBlock.new + block.show_blog_picture = true + block.save + block.reload + + assert block.show_blog_picture + end + + should 'blog_picture is being stored and restored from database as false' do + block = RecentContentBlock.new + block.show_blog_picture = false + block.save + block.reload + + assert !block.show_blog_picture + end + + should 'root be nil for new blocks' do + block = RecentContentBlock.new + + assert block.root.nil? + end + + should 'root be a Blog when it is configured for' do + profile = create_user('testuser').person + + root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id) + + block = RecentContentBlock.new + block.stubs(:holder).returns(profile) + block.selected_folder = root.id + + assert block.root.id == root.id + end + + should 'return last articles inside a folder' do + profile = create_user('testuser').person + + Article.delete_all + + root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id) + + a1 = fast_create(TextileArticle, :name => 'article #1', :profile_id => profile.id, :parent_id => root.id) + a2 = fast_create(TextileArticle, :name => 'article #2', :profile_id => profile.id, :parent_id => root.id) + a3 = fast_create(TextileArticle, :name => 'article #3', :profile_id => profile.id, :parent_id => root.id) + + block = RecentContentBlock.new + block.stubs(:holder).returns(profile) + + assert block.articles_of_folder(root,2) == [a3, a2] + assert block.articles_of_folder(root,3) == [a3, a2, a1] + end + +end diff --git a/plugins/recent_content/views/blocks/recent_content_block.rhtml b/plugins/recent_content/views/blocks/recent_content_block.rhtml new file mode 100644 index 0000000..4608cc6 --- /dev/null +++ b/plugins/recent_content/views/blocks/recent_content_block.rhtml @@ -0,0 +1,45 @@ +<% unless root.nil? %> +
+ <% children = block.articles_of_folder(root, block.total_items)%> +
+ <%= block_title(block.title.blank? ? _("Recent content") : block.title ) %> + <% if block.show_blog_picture and !root.image.nil? %> +
+ <%= image_tag(root.image.public_filename(:big)) %> +
+ <% end %> +
+ <% if block.mode?('title_only') %> +
+
    + <% childr"A plugin that adds a block where you can display the content of any of your blogs"en.each do |item| %> +
  • <%= link_to(h(item.title), item.url)%>
  • + <% end %> +
+
+ <% elsif block.mode?('title_and_abstract') %> +
+ <% children.each do |item| %> +

<%= link_to(item.title,item.url, :class => 'post-title')%>

+ +
<%=item.lead%>
+

<%= link_to(_('Read more'), item.url) %>

+ <% end %> +
+ <% else %> +
+ <% children.each do |item| %> +

<%= link_to(item.title,item.url, :class => 'post-title')%>

+ +
<%=item.body%>
+

<%= link_to(_('Read more'), item.url) %>

+ <% end %> +
+ <% end %> + <%= link_to _('View All'), :profile => profile.identifier, :controller => 'content_viewer', :action => 'view_page', :page => block.root.path %> +
+<% else %> + + <%= _('This is the recent content block. Please edit it to show the content you want.') %> + +<% end %> diff --git a/plugins/recent_content/views/box_organizer/_recent_content_block.rhtml b/plugins/recent_content/views/box_organizer/_recent_content_block.rhtml new file mode 100644 index 0000000..1b59e22 --- /dev/null +++ b/plugins/recent_content/views/box_organizer/_recent_content_block.rhtml @@ -0,0 +1,33 @@ +<% blogs = @block.parents %> +<% if blogs.empty? %> +

<%= _('No blogs found. Please add a blog in order to configure this block.') %>

+<% end %> +<%= +labelled_form_field(_('Choose which blog should be displayed'), + select_tag( + 'block[selected_folder]', + options_for_select(blogs.map {|node| [node.title, node.id]}, @block.selected_folder) + ) +) +%> +<%= +labelled_form_field(_('Choose how the content should be displayed'), + select_tag( + 'block[presentation_mode]', + options_for_select( + { + _("Title only") => "title_only", + _("Title and abstract") => "title_and_abstract", + _("Full content") => "full_content" + }, + @block.presentation_mode + ) + ) +) +%> +<%= labelled_form_field(_('Choose how many items will be displayed'), + text_field_tag('block[total_items]', + @block.total_items, :size => 3, :maxlength => 5) + ) +%> +<%= labelled_check_box _('Display blog cover image'), 'block[show_blog_picture]', true, @block.show_blog_picture %> diff --git a/plugins/recent_content/views/environment_design b/plugins/recent_content/views/environment_design new file mode 120000 index 0000000..1b8d625 --- /dev/null +++ b/plugins/recent_content/views/environment_design @@ -0,0 +1 @@ +box_organizer/ \ No newline at end of file diff --git a/plugins/recent_content/views/profile_design b/plugins/recent_content/views/profile_design new file mode 120000 index 0000000..1b8d625 --- /dev/null +++ b/plugins/recent_content/views/profile_design @@ -0,0 +1 @@ +box_organizer/ \ No newline at end of file -- libgit2 0.21.2