Skip to content

Commit

Permalink
Adding a "most popular posts" sidebar plugin that will use the Articl…
Browse files Browse the repository at this point in the history
…e.bestof method.

This because I'm going to remove the Most Popular articles widget from the dashboard, as it's not really useful to manage a blog on a daily basis.
  • Loading branch information
Frédéric de Villamil committed Aug 10, 2013
1 parent cfbeafa commit 0f3a357
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/popular_sidebar/Rakefile
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the popular_sidebar plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the popular_sidebar plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'ArchivesSidebar'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
11 changes: 11 additions & 0 deletions lib/popular_sidebar/app/views/popular_sidebar/_content.html.erb
@@ -0,0 +1,11 @@
<h3 class="sidebar-title"><%= sidebar.title %></h3>
<ul class='popular_sidebar'>
<% if sidebar.popular.empty? || sidebar.popular.size == 0 %>
<li class='alert'><%= _("Nothing to show yet") %> !</li>
<% else %>
<% sidebar.popular.each do |article| %>
<%= sprintf("%s (%s)", link_to_permalink(article, article.title), _("%d comments", article.comment_count)) %>
<% end %>
<% end %>
</li>
</ul>
2 changes: 2 additions & 0 deletions lib/popular_sidebar/init.rb
@@ -0,0 +1,2 @@
require 'sidebar'
require 'popular_sidebar'
11 changes: 11 additions & 0 deletions lib/popular_sidebar/lib/popular_sidebar.rb
@@ -0,0 +1,11 @@
class PopularSidebar < Sidebar
description 'Displays the most popular posts'
setting :title, 'Most popular'
setting :count, 5, :label => 'Number articles'

attr_accessor :popular

def parse_request(contents, params)
@popular = Article.bestof.limit(5)
end
end
8 changes: 8 additions & 0 deletions lib/popular_sidebar/test/popular_sidebar_test.rb
@@ -0,0 +1,8 @@
require 'test/unit'
require File.dirname(__FILE__) + '/../../../../test/test_helper'

class PopularSidebarTest < Test::Unit::TestCase
def test_popular_is_available
assert Sidebar.available_sidebars.include?(PopularSidebar)
end
end

0 comments on commit 0f3a357

Please sign in to comment.