aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJoe Sak <joe@joesak.com>2010-11-18 10:52:10 -0600
committerJoe Sak <joe@joesak.com>2010-11-18 10:52:10 -0600
commitdc3cbaa0918c5194ae0f1e80024611c614be612f (patch)
tree148ec2e27b58295bfbfda2be12863d398d026713 /app
parentc610fee93b9e20e083c68d99ee941c6b4f507cf0 (diff)
downloadrefinerycms-blog-dc3cbaa0918c5194ae0f1e80024611c614be612f.tar.gz
refinerycms-blog-dc3cbaa0918c5194ae0f1e80024611c614be612f.tar.bz2
refinerycms-blog-dc3cbaa0918c5194ae0f1e80024611c614be612f.zip
Archive listing, views, helpers
@page added to PostsController TODO: language file stuff -- I left comments in the view files where these belong. I don't know how to test them from here
Diffstat (limited to 'app')
-rw-r--r--app/controllers/blog/posts_controller.rb18
-rw-r--r--app/helpers/blog_posts_helper.rb22
-rw-r--r--app/models/blog_post.rb14
-rw-r--r--app/views/blog/posts/archive.html.erb19
-rw-r--r--app/views/blog/posts/index.html.erb3
-rw-r--r--app/views/blog/posts/show.html.erb1
6 files changed, 75 insertions, 2 deletions
diff --git a/app/controllers/blog/posts_controller.rb b/app/controllers/blog/posts_controller.rb
index 1d8a0b5..071bc68 100644
--- a/app/controllers/blog/posts_controller.rb
+++ b/app/controllers/blog/posts_controller.rb
@@ -1,6 +1,7 @@
class Blog::PostsController < BlogController
-
- before_filter :find_all_blog_posts
+
+ before_filter :find_page
+ before_filter :find_all_blog_posts, :except => [:archive]
before_filter :find_blog_post, :only => [:show, :comment]
def index
@@ -41,6 +42,15 @@ class Blog::PostsController < BlogController
render :action => 'show'
end
end
+
+ def archive
+ date = "#{params[:month]}/#{params[:year]}"
+ @archive_date = Time.parse(date)
+ @blog_posts = BlogPost.live.by_archive(@archive_date).paginate({
+ :page => params[:page],
+ :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
+ })
+ end
protected
@@ -54,5 +64,9 @@ protected
:per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
})
end
+
+ def find_page
+ @page = Page.find_by_link_url('/blog')
+ end
end
diff --git a/app/helpers/blog_posts_helper.rb b/app/helpers/blog_posts_helper.rb
new file mode 100644
index 0000000..fb90e94
--- /dev/null
+++ b/app/helpers/blog_posts_helper.rb
@@ -0,0 +1,22 @@
+module BlogPostsHelper
+ def blog_archive_list
+ posts = BlogPost.select('published_at').all_previous
+ return nil if posts.blank?
+ html = '<section id="blog_archive_list"><h1>Archives</h1><nav>'
+ links = []
+
+ posts.each do |e|
+ links << e.published_at.strftime('%m/%Y')
+ end
+ links.uniq!
+ links.each do |l|
+ year = l.split('/')[1]
+ month = l.split('/')[0]
+ count = BlogPost.by_archive(Time.parse(l)).size
+ text = "#{Date::MONTHNAMES[month.to_i]} #{year} (#{count})"
+ html += link_to(text, archive_blog_posts_path(:year => year, :month => month))
+ end
+ html += '</nav></section>'
+ html.html_safe
+ end
+end
diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb
index 659ef48..562a9b9 100644
--- a/app/models/blog_post.rb
+++ b/app/models/blog_post.rb
@@ -11,6 +11,20 @@ class BlogPost < ActiveRecord::Base
has_friendly_id :title, :use_slug => true
default_scope :order => "published_at DESC"
+
+ if Rails.version < '3.0.0'
+ named_scope :by_archive, lambda { |archive_date| {:conditions => ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]} }
+ else
+ scope :by_archive, lambda { |archive_date|
+ where ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]
+ }
+ end
+
+ if Rails.version < '3.0.0'
+ named_scope :all_previous, :conditions => ['published_at <= ?', Time.now.beginning_of_month]
+ else
+ scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month])
+ end
if Rails.version < '3.0.0'
named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false]} }
diff --git a/app/views/blog/posts/archive.html.erb b/app/views/blog/posts/archive.html.erb
new file mode 100644
index 0000000..d0855fa
--- /dev/null
+++ b/app/views/blog/posts/archive.html.erb
@@ -0,0 +1,19 @@
+<% content_for :body_content_left do %>
+ <%= @page[Page.default_parts.first.to_sym] %>
+ <h1>News Archive for <%= @archive_date.strftime('%B %Y') %></h1>
+ <section id="blog_posts">
+ <%= render :partial => "/blog/shared/post", :collection => @blog_posts %>
+ </section>
+ <%= "There are no blog articles posted for #{@archive_date.strftime('%B %Y')}. Stay tuned." unless @blog_posts.any? %>
+ <%# TODO: Add locale logic here - hubble is a n00b at that %>
+<% end %>
+
+<% content_for :body_content_right do %>
+ <%= @page[Page.default_parts.second.to_sym] %>
+ <%= render :partial => "/blog/shared/categories" %>
+ <%= render :partial => "/blog/shared/rss_feed" %>
+ <%= blog_archive_list %>
+<% end %>
+
+<%= render :partial => "/shared/content_page" %>
+<% content_for :head, stylesheet_link_tag('refinerycms-blog') %> \ No newline at end of file
diff --git a/app/views/blog/posts/index.html.erb b/app/views/blog/posts/index.html.erb
index a90ff2c..9e63ac2 100644
--- a/app/views/blog/posts/index.html.erb
+++ b/app/views/blog/posts/index.html.erb
@@ -4,6 +4,8 @@
<section id="blog_posts">
<%= render :partial => "/blog/shared/post", :collection => @blog_posts %>
</section>
+ <%= "<p>There are no blog articles posted yet. Stay tuned.</p>".html_safe unless @blog_posts.any? %>
+ <%# TODO: Add locale logic here - hubble is a n00b at that %>
<% end %>
<% content_for :body_content_right do %>
@@ -11,6 +13,7 @@
<%= render :partial => "/blog/shared/categories" %>
<%= render :partial => "/blog/shared/rss_feed" %>
+ <%= blog_archive_list %>
<% end %>
<%= render :partial => "/shared/content_page" %>
diff --git a/app/views/blog/posts/show.html.erb b/app/views/blog/posts/show.html.erb
index 3b7b9b5..2c0cfec 100644
--- a/app/views/blog/posts/show.html.erb
+++ b/app/views/blog/posts/show.html.erb
@@ -88,6 +88,7 @@
<%= render :partial => "/blog/shared/categories" %>
<%= render :partial => "/blog/shared/posts" %>
<%= render :partial => "/blog/shared/rss_feed" %>
+ <%= blog_archive_list %>
<% end %>
<%= render :partial => "/shared/content_page" %>