lib/models/blog.rb in yodel_blog-0.0.2 vs lib/models/blog.rb in yodel_blog-0.0.4
- old
+ new
@@ -1,9 +1,14 @@
class Blog < Page
attr_reader :number_of_pages, :page_params, :tag, :total_articles, :month, :year
respond_to :get do
+ with :html do
+ articles
+ super()
+ end
+
with :atom do |xml|
@xml = xml
layout('atom').render(self)
end
end
@@ -42,18 +47,38 @@
def first_page?
page_number == 0
end
def last_page?
- page_number == @number_of_pages - 1
+ page_number == (@number_of_pages - 1)
end
def page_number
@page_number ||= params['page'].to_i
end
def tag_path(tag)
"#{path}?tag=#{CGI::escape(tag || '')}"
+ end
+
+ def page_path(page_number)
+ "#{path}?page=#{page_number}"
+ end
+
+ def previous_page_path
+ if first_page?
+ path
+ else
+ "#{path}?page=#{page_number - 1}"
+ end
+ end
+
+ def next_page_path
+ if last_page?
+ path
+ else
+ "#{path}?page=#{page_number + 1}"
+ end
end
def month_path(month, year)
"#{path}?month=#{month}&year=#{year}"
end