Permalink
Browse files

Move newspost formatting to a helper

* Moved newspost formatting to a helper
* Added a new helper which handles displaying all newsposts,
  separating that logic out from the view itself
  • Loading branch information...
1 parent f917c21 commit f8960dca59dd5634ac663272958b06d84d065327 @mistydemeo committed Aug 19, 2012
Showing with 17 additions and 9 deletions.
  1. +16 −0 helpers.rb
  2. +0 −7 models/post.rb
  3. +1 −2 views/lost.erb
View
@@ -73,4 +73,20 @@ def submission_confirmation
"Thanks for submitting your #{params["item"]}!"
end
end
+
+ # Formats each newspost in this format with a 1-space indent,
+ # as seen in the Poignant Guide:
+ # / dd month year /
+ # text...
+ # - salutation, poster
+ def newspost_string post; <<-EOS
+ / #{post.created_on.strftime("%d %B %Y")} /
+#{post.text.each_line.map {|l| l.prepend " "}.join}
+#{" " * 49} - #{post.salutation+", " if post.salutation}#{post.poster.name}
+ EOS
+ end
+
+ def display_newsposts
+ Post.limit(10).reverse.map {|p| newspost_string p}.join "\n"
+ end
end
View
@@ -4,11 +4,4 @@ class Post < ActiveRecord::Base
validates_presence_of :created_on
belongs_to :poster, :class_name => "Poster", :inverse_of => :posts
-
- def post; <<-EOS
-/ #{created_on.strftime("%d %B %Y")} /
-#{text}
- - #{salutation+", " if salutation}#{poster.name}
- EOS
- end
end
View
@@ -32,8 +32,7 @@
IMPORTANT NEWS
==============
-<%= news_string = Post.limit(10).reverse.map(&:post).join("\n").chomp
- news_string.each_line.map {|l| l.prepend " "}.join %>
+<%= display_newsposts %>
USING THE L&amp;F SERVER
====================

0 comments on commit f8960dc

Please sign in to comment.