Closes GH-29. Blog posts act as taggable. rspec & cukes passing

This commit is contained in:
Joe Sak 2011-03-11 14:23:44 -06:00
parent b3f95341c3
commit 3748c1d9ef
11 changed files with 77 additions and 10 deletions

View file

@ -2,6 +2,7 @@ class Blog::PostsController < BlogController
before_filter :find_all_blog_posts, :except => [:archive]
before_filter :find_blog_post, :only => [:show, :comment, :update_nav]
before_filter :find_tags
respond_to :html, :js, :rss
@ -65,6 +66,14 @@ class Blog::PostsController < BlogController
respond_with (@blog_posts)
end
def tagged
@tag_name = params[:tag_name]
@blog_posts = BlogPost.tagged_with(@tag_name.titleize).paginate({
:page => params[:page],
:per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
})
end
protected
def find_blog_post
@ -84,4 +93,8 @@ protected
})
end
def find_tags
@tags = BlogPost.tag_counts_on(:tags)
end
end

View file

@ -1,5 +1,4 @@
<% content_for :body_content_left do %>
<%= @page[Page.default_parts.first.to_sym] %>
<h1><%= t('.blog_archive_for', :date => @archive_date.strftime('%B %Y')) %></h1>
<% if @blog_posts.any? %>
<section id="blog_posts">
@ -11,8 +10,8 @@
<% end %>
<% content_for :body_content_right do %>
<%= @page[Page.default_parts.second.to_sym] %>
<%= render :partial => "/blog/shared/categories" %>
<%= render :partial => "/blog/shared/tags" %>
<%= render :partial => "/blog/shared/rss_feed" %>
<%= blog_archive_list %>
<% end %>

View file

@ -15,6 +15,7 @@
<%=raw @page[Page.default_parts.second.to_sym] if Page.default_parts.many? %>
<%= render :partial => "/blog/shared/categories" %>
<%= render :partial => "/blog/shared/tags" %>
<%= render :partial => "/blog/shared/rss_feed" %>
<%= blog_archive_list %>
<% end %>

View file

@ -49,6 +49,7 @@
<% content_for :body_content_right do %>
<%= render :partial => "/blog/shared/categories" %>
<%= render :partial => "/blog/shared/tags" %>
<%= render :partial => "/blog/shared/posts" %>
<%= render :partial => "/blog/shared/rss_feed" %>
<%= blog_archive_list %>

View file

@ -0,0 +1,22 @@
<% content_for :body_content_title, "Posts tagged &#8220;#{@tag_name.titleize}&#8221;".html_safe -%>
<% content_for :body_content_left do %>
<% if @blog_posts.any? %>
<section id="blog_posts">
<%= render :partial => "/blog/shared/post", :collection => @blog_posts %>
<%= will_paginate @blog_posts %>
</section>
<% else %>
<p><%= t('.no_blog_articles_yet') %></p>
<% end %>
<% end %>
<% content_for :body_content_right do %>
<%= render :partial => "/blog/shared/categories" %>
<%= render :partial => "/blog/shared/tags" %>
<%= render :partial => "/blog/shared/rss_feed" %>
<%= blog_archive_list %>
<% end %>
<%= render :partial => "/shared/content_page" %>
<% content_for :stylesheets, stylesheet_link_tag('refinerycms-blog') %>

View file

@ -9,9 +9,13 @@
<% if (categories = post.categories).any? %>
<aside class='filed_in'>
<%= t('filed_in', :scope => 'blog.posts.show') %>
<% categories.each_with_index do |category, index| %>
<%= link_to category.title, blog_category_url(category) -%><%= ',' if index < ((categories.length) - 1) %>
<% end %>
<%=raw categories.collect { |category| link_to category.title, blog_category_url(category) }.to_sentence %>
</aside>
<% end %>
<% if (tags = post.tag_list).any? %>
<aside class='tagged'>
<%= t('tagged', :scope => 'blog.posts.show') %>
<%=raw tags.collect { |tag| link_to tag, tagged_posts_path(tag.parameterize) }.to_sentence %>
</aside>
<% end %>
</details>

View file

@ -0,0 +1,8 @@
<% unless @tags.nil? %>
<h2><%= t('.title') %></h2>
<nav id='tags'>
<% tag_cloud(@tags, %w(tag1 tag2 tag3 tag4)) do |tag, css_class| %>
<%= link_to tag.name, tagged_posts_path(tag.name.parameterize), :class => css_class %>
<% end %>
</nav>
<% end %>

View file

@ -101,6 +101,8 @@ en:
singular: comment
none: no comments
archives: Archives
tags:
title: "Tags"
categories:
show:
no_posts: There are no posts here yet.
@ -122,7 +124,10 @@ en:
add: Make a Comment
other: Other Blog Posts
filed_in: Filed in
tagged: Tagged
submit: Send comment
tagged:
no_blog_articles_yet: There are no blog articles posted yet. Stay tuned.
archive:
blog_archive_for: 'Blog Archive for %{date}'
no_blog_articles_posted: 'There are no blog articles posted for %{date}. Stay tuned.'

View file

@ -6,6 +6,7 @@ Refinery::Application.routes.draw do
match 'categories/:id', :to => 'categories#show', :as => 'blog_category'
match ':id/comments', :to => 'posts#comment', :as => 'blog_post_blog_comments'
get 'archive/:year(/:month)', :to => 'posts#archive', :as => 'archive_blog_posts'
get 'tagged/:tag_name' => 'posts#tagged', :as => 'tagged_posts'
end
scope(:path => 'refinery', :as => 'admin', :module => 'admin') do

View file

@ -1,3 +1,11 @@
Given /^there is a blog post titled "([^"]*)" and tagged "([^"]*)"$/ do |title, tag_name|
@blog_post = Factory(:post, :title => title, :tag_list => tag_name)
end
When /^I visit the tagged posts page for "([^"]*)"$/ do |tag_name|
visit tagged_posts_path(tag_name.parameterize)
end
Then /^the blog post should have the tags "([^"]*)"$/ do |tag_list|
BlogPost.last.tag_list == tag_list.split(', ')
end

View file

@ -2,15 +2,14 @@
Feature: Blog Post Tags
Blog posts can be assigned tags
Scenario: The blog post new/edit form has tag_list
Background:
Given I am a logged in refinery user
Scenario: The blog post new/edit form has tag_list
When I am on the new blog post form
Then I should see "Tags"
Scenario: The blog post new/edit form saves tag_list
Given I am a logged in refinery user
When I am on the new blog post form
And I fill in "Title" with "This is my blog post"
And I fill in "Body" with "And I love it"
@ -19,3 +18,9 @@ Feature: Blog Post Tags
Then there should be 1 blog post
And the blog post should have the tags "chicago, bikes, beers, babes"
Scenario: The blog has a "tagged" route & view
Given there is a blog post titled "I love my city" and tagged "chicago"
When I visit the tagged posts page for "chicago"
Then I should see "Chicago"
And I should see "I love my city"