Commit 0ce4ec09561fd251d804ff6d972457bbbec43cdf
1 parent
a2d83d73
Exists in
master
and in
28 other branches
Limiting blog and forum view to 15 posts
Showing
6 changed files
with
39 additions
and
2 deletions
Show diff stats
app/models/blog.rb
| 1 | class Blog < Folder | 1 | class Blog < Folder |
| 2 | 2 | ||
| 3 | acts_as_having_posts | 3 | acts_as_having_posts |
| 4 | + include PostsLimit | ||
| 4 | 5 | ||
| 5 | #FIXME This should be used until there is a migration to fix all blogs that | 6 | #FIXME This should be used until there is a migration to fix all blogs that |
| 6 | # already have folders inside them | 7 | # already have folders inside them |
app/models/forum.rb
| @@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
| 1 | +module PostsLimit | ||
| 2 | + module ClassMethods | ||
| 3 | + def posts_per_page_limit | ||
| 4 | + 15 | ||
| 5 | + end | ||
| 6 | + | ||
| 7 | + def posts_per_page_options | ||
| 8 | + [5, 10, 15] | ||
| 9 | + end | ||
| 10 | + end | ||
| 11 | + | ||
| 12 | + def self.included(klass) | ||
| 13 | + klass.send(:extend, PostsLimit::ClassMethods) | ||
| 14 | + klass.class_eval do | ||
| 15 | + def posts_per_page_with_limit | ||
| 16 | + [self.class.posts_per_page_limit, posts_per_page_without_limit].min | ||
| 17 | + end | ||
| 18 | + alias_method_chain :posts_per_page, :limit | ||
| 19 | + end | ||
| 20 | + end | ||
| 21 | +end |
app/views/cms/_blog.rhtml
| @@ -56,7 +56,7 @@ | @@ -56,7 +56,7 @@ | ||
| 56 | 56 | ||
| 57 | <%= labelled_form_field(_('How to display posts:'), f.select(:visualization_format, [ [ _('Full post'), 'full'], [ _('First paragraph'), 'short'] ])) %> | 57 | <%= labelled_form_field(_('How to display posts:'), f.select(:visualization_format, [ [ _('Full post'), 'full'], [ _('First paragraph'), 'short'] ])) %> |
| 58 | 58 | ||
| 59 | -<%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, [5, 10, 20, 50, 100])) %> | 59 | +<%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %> |
| 60 | 60 | ||
| 61 | <%= labelled_check_box(_("List only translated posts"), 'article[display_posts_in_current_language]', '1', @article.display_posts_in_current_language?) %> | 61 | <%= labelled_check_box(_("List only translated posts"), 'article[display_posts_in_current_language]', '1', @article.display_posts_in_current_language?) %> |
| 62 | 62 |
app/views/cms/_forum.rhtml
| @@ -10,4 +10,4 @@ | @@ -10,4 +10,4 @@ | ||
| 10 | 10 | ||
| 11 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64, :rows => 10)) %> | 11 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64, :rows => 10)) %> |
| 12 | 12 | ||
| 13 | -<%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, [5, 10, 20, 50, 100])) %> | 13 | +<%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, Forum.posts_per_page_options)) %> |
| @@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | + | ||
| 3 | +class PostsLimitTest < ActiveSupport::TestCase | ||
| 4 | + | ||
| 5 | + CLASSES = [Blog, Forum] | ||
| 6 | + | ||
| 7 | + should 'limit posts per_page_page' do | ||
| 8 | + CLASSES.each do |klass| | ||
| 9 | + object = klass.new | ||
| 10 | + object.posts_per_page = klass.posts_per_page_limit + 1 | ||
| 11 | + assert_equal klass.posts_per_page_limit, object.posts_per_page | ||
| 12 | + end | ||
| 13 | + end | ||
| 14 | +end |