Permalink
Browse files

added tagging views and methods

  • Loading branch information...
1 parent 113febc commit 36767af44418af417039442485f3c7e0ff2918fa Mike Stickel committed Nov 3, 2010
@@ -25,7 +25,7 @@ def create
post_tags = []
tags = list_to_array(params[:tags])
tags.each do |t|
- post_tags << Tag.find_or_create_by_name(t)
+ post_tags << Tag.find_or_create_by_name(t.strip)
end
post.tags = post_tags
end
@@ -55,7 +55,7 @@ def update
post_tags = []
tags = list_to_array(params[:tags])
tags.each do |t|
- post_tags<< Tag.find_or_create_by_name(t)
+ post_tags<< Tag.find_or_create_by_name(t.strip)
end
post.tags = post_tags
end
@@ -0,0 +1,8 @@
+class TagsController < ApplicationController
+ helper :posts
+
+ def list
+ @tag = params[:tag]
+ @posts = Post.with_tag(@tag)
+ end
+end
@@ -13,6 +13,15 @@ def tags_as_sentence(tags, links = true)
return sentence.to_sentence
end
+ def tags_into_array(tags)
+ raise "No tags" if tags.nil?
+ tag_array = []
+ tags.each do |t|
+ tag_array << t.name
+ end
+ return tag_array
+ end
+
def related_posts(number_of_posts, title = "Related Posts")
raise "No tags" if @posts.tags.blank?
random_tag = @posts.tags[rand(@posts.tags.length.to_i)].name
@@ -0,0 +1,2 @@
+module TagsHelper
+end
@@ -2,9 +2,14 @@
<ul>
<%- @posts.each do |p| -%>
- <li><%= link_to p.title, post_path(Site.archive_path,p.permalink) %></li>
+ <li>
+ <%= link_to p.title, post_path(Site.archive_path, p.permalink) %>
+ <%= truncate_paragraphs(scrub_images(p.body)) %> <%= link_to '[Read more]', post_path(Site.archive_path, p.permalink) %>
+ </li>
<%- end -%>
</ul>
+<%= paginate(params[:offset],@total_pages,Site.number_of_posts,"/#{Site.archive_path}",'&larr;Older posts', 'Newer posts &rarr;') %>
+
<%= render :partial => 'posts/sidebar' %>
<%= render :partial => 'layouts/footer' %>
@@ -0,0 +1,13 @@
+<%= render :partial => 'layouts/header' %>
+
+<ul>
+<%- @posts.each do |p| -%>
+ <li class="posts<%= ' link' if tags_into_array(p.tags).include?('link') %><%= ' quote' if tags_into_array(p.tags).include?('quote') %>">
+ <%= link_to p.title, post_path(Site.archive_path, p.permalink) %>
+ <p class="byline">Posted by <%= p.person.name %> on <%= p.published_at.to_s(:long_form) %></p>
+ </li>
+<%- end -%>
+</ul>
+
+<%= render :partial => 'posts/sidebar' %>
+<%= render :partial => 'layouts/footer' %>
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class TagsControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class TagsHelperTest < ActionView::TestCase
+end
@@ -2,7 +2,7 @@
<ul>
<%- @posts.each do |p| -%>
- <li>
+ <li class="posts<%= ' link' if tags_into_array(p.tags).include?('link') %><%= ' quote' if tags_into_array(p.tags).include?('quote') %>">
<%= link_to p.title, post_path(Site.archive_path, p.permalink) %>
<%= truncate_paragraphs(scrub_images(p.body)) %> <%= link_to '[Read more]', post_path(Site.archive_path, p.permalink) %>
</li>
@@ -0,0 +1,13 @@
+<%= render :partial => 'layouts/header' %>
+
+<ul>
+<%- @posts.each do |p| -%>
+ <li class="posts<%= ' link' if tags_into_array(p.tags).include?('link') %><%= ' quote' if tags_into_array(p.tags).include?('quote') %>">
+ <%= link_to p.title, post_path(Site.archive_path, p.permalink) %>
+ <p class="byline">Posted by <%= p.person.name %> on <%= p.published_at.to_s(:long_form) %></p>
+ </li>
+<%- end -%>
+</ul>
+
+<%= render :partial => 'posts/sidebar' %>
+<%= render :partial => 'layouts/footer' %>

0 comments on commit 36767af

Please sign in to comment.