aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/blog/posts_controller.rb13
-rw-r--r--app/views/blog/posts/archive.html.erb3
-rw-r--r--app/views/blog/posts/index.html.erb1
-rw-r--r--app/views/blog/posts/show.html.erb1
-rw-r--r--app/views/blog/posts/tagged.html.erb22
-rw-r--r--app/views/blog/shared/_post.html.erb10
-rw-r--r--app/views/blog/shared/_tags.html.erb8
-rw-r--r--config/locales/en.yml5
-rw-r--r--config/routes.rb1
-rw-r--r--features/support/step_definitions/tags_steps.rb8
-rw-r--r--features/tags.feature15
11 files changed, 77 insertions, 10 deletions
diff --git a/app/controllers/blog/posts_controller.rb b/app/controllers/blog/posts_controller.rb
index 576073e..9c413ed 100644
--- a/app/controllers/blog/posts_controller.rb
+++ b/app/controllers/blog/posts_controller.rb
@@ -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
@@ -64,6 +65,14 @@ class Blog::PostsController < BlogController
end
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
@@ -83,5 +92,9 @@ protected
:per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
})
end
+
+ def find_tags
+ @tags = BlogPost.tag_counts_on(:tags)
+ end
end
diff --git a/app/views/blog/posts/archive.html.erb b/app/views/blog/posts/archive.html.erb
index d44aa7f..a2044e8 100644
--- a/app/views/blog/posts/archive.html.erb
+++ b/app/views/blog/posts/archive.html.erb
@@ -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 %>
diff --git a/app/views/blog/posts/index.html.erb b/app/views/blog/posts/index.html.erb
index 08e3578..8c3801a 100644
--- a/app/views/blog/posts/index.html.erb
+++ b/app/views/blog/posts/index.html.erb
@@ -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 %>
diff --git a/app/views/blog/posts/show.html.erb b/app/views/blog/posts/show.html.erb
index 504db2c..92898a4 100644
--- a/app/views/blog/posts/show.html.erb
+++ b/app/views/blog/posts/show.html.erb
@@ -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 %>
diff --git a/app/views/blog/posts/tagged.html.erb b/app/views/blog/posts/tagged.html.erb
new file mode 100644
index 0000000..29de791
--- /dev/null
+++ b/app/views/blog/posts/tagged.html.erb
@@ -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') %>
diff --git a/app/views/blog/shared/_post.html.erb b/app/views/blog/shared/_post.html.erb
index 2e92f73..716c1ad 100644
--- a/app/views/blog/shared/_post.html.erb
+++ b/app/views/blog/shared/_post.html.erb
@@ -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>
diff --git a/app/views/blog/shared/_tags.html.erb b/app/views/blog/shared/_tags.html.erb
new file mode 100644
index 0000000..f8833f1
--- /dev/null
+++ b/app/views/blog/shared/_tags.html.erb
@@ -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 %> \ No newline at end of file
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 357f4be..f5b5461 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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.'
diff --git a/config/routes.rb b/config/routes.rb
index e37987a..421e845 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/features/support/step_definitions/tags_steps.rb b/features/support/step_definitions/tags_steps.rb
index 00e8a3e..5d4dced 100644
--- a/features/support/step_definitions/tags_steps.rb
+++ b/features/support/step_definitions/tags_steps.rb
@@ -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
diff --git a/features/tags.feature b/features/tags.feature
index d8b9427..07c73cd 100644
--- a/features/tags.feature
+++ b/features/tags.feature
@@ -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"
@@ -18,4 +17,10 @@ Feature: Blog Post Tags
And I press "Save"
Then there should be 1 blog post
- And the blog post should have the tags "chicago, bikes, beers, babes" \ No newline at end of file
+ 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" \ No newline at end of file