Permalink
Browse files

was be able to change the number of posts displayed

  • Loading branch information...
1 parent 5d4be38 commit d3bbff3ce042902cbfb36815255b2f0184e933c9 @daichirata daichirata committed Feb 19, 2012
Showing with 37 additions and 8 deletions.
  1. +1 −0 i18n/en.yml
  2. +1 −0 i18n/ja.yml
  3. +8 −8 lib/lokka/app/entries.rb
  4. +5 −0 lib/lokka/site.rb
  5. +4 −0 public/admin/site/edit.haml
  6. +18 −0 spec/integration/app_spec.rb
View
@@ -170,6 +170,7 @@ en:
description: Description
dashboard: Dashboard
theme: Theme
+ per_page: Number per page
default_sort: Default sort
default_order: Default order
meta_description: Meta description
View
@@ -170,6 +170,7 @@ ja:
description: 詳細
dashboard: ダッシュボード
theme: テーマ
+ per_page: 表示件数
default_sort: デフォルトのソート対象
default_order: デフォルトのソート順
meta_description: メタディスクリプション
View
@@ -4,9 +4,9 @@ class App
get '/' do
@theme_types << :index
@theme_types << :entries
-
+
@posts = Post.published.
- page(params[:page], :per_page => settings.per_page, :order => @site.default_order_query_operator)
+ page(params[:page], :per_page => @site.per_page, :order => @site.default_order_query_operator)
@posts = apply_continue_reading(@posts)
@title = @site.title
@@ -18,7 +18,7 @@ class App
get '/index.atom' do
@posts = Post.published.
- page(params[:page], :per_page => settings.per_page, :order => @site.default_order_query_operator)
+ page(params[:page], :per_page => @site.per_page, :order => @site.default_order_query_operator)
@posts = apply_continue_reading(@posts)
content_type 'application/atom+xml', :charset => 'utf-8'
builder :'system/index'
@@ -31,7 +31,7 @@ class App
@query = params[:query]
@posts = Post.published.search(@query).
- page(params[:page], :per_page => settings.per_page, :order => @site.default_order_query_operator)
+ page(params[:page], :per_page => @site.per_page, :order => @site.default_order_query_operator)
@posts = apply_continue_reading(@posts)
@title = "Search by #{@query}"
@@ -51,7 +51,7 @@ class App
@category = Category.get_by_fuzzy_slug(category_title)
return 404 if @category.nil?
@posts = Post.all(:category => @category).published.
- page(params[:page], :per_page => settings.per_page, :order => @site.default_order_query_operator)
+ page(params[:page], :per_page => @site.per_page, :order => @site.default_order_query_operator)
@posts = apply_continue_reading(@posts)
@title = @category.title
@@ -74,7 +74,7 @@ class App
return 404 if @tag.nil?
@posts = Post.all(:id => @tag.taggings.map {|o| o.taggable_id }).
published.
- page(params[:page], :per_page => settings.per_page, :order => @site.default_order_query_operator)
+ page(params[:page], :per_page => @site.per_page, :order => @site.default_order_query_operator)
@posts = apply_continue_reading(@posts)
@title = @tag.name
@@ -94,7 +94,7 @@ class App
@posts = Post.all(:created_at.gte => DateTime.new(year, month)).
all(:created_at.lt => DateTime.new(year, month) >> 1).
published.
- page(params[:page], :per_page => settings.per_page, :order => @site.default_order_query_operator)
+ page(params[:page], :per_page => @site.per_page, :order => @site.default_order_query_operator)
@posts = apply_continue_reading(@posts)
@title = "#{year}/#{month}"
@@ -115,7 +115,7 @@ class App
@posts = Post.all(:created_at.gte => DateTime.new(year)).
all(:created_at.lt => DateTime.new(year + 1)).
published.
- page(params[:page], :per_page => settings.per_page, :order => @site.default_order_query_operator)
+ page(params[:page], :per_page => @site.per_page, :order => @site.default_order_query_operator)
@posts = apply_continue_reading(@posts)
@title = year
View
@@ -11,13 +11,18 @@ class Site
property :dashboard, Text, :length => 65535
property :theme, String, :length => 64
property :mobile_theme, String, :length => 64
+ property :per_page, Integer
property :default_sort, String, :length => 255
property :default_order, String, :length => 255
property :meta_description, String, :length => 255
property :meta_keywords, String, :length => 255
property :created_at, DateTime
property :updated_at, DateTime
+ def per_page
+ super || '10'
+ end
+
def default_sort
super || 'created_at'
end
@@ -16,6 +16,10 @@
%br/
~ f.text_area :dashboard
%p
+ = f.label :per_page, :caption => t('site.per_page')
+ %br/
+ = f.select :per_page, :options => (1..20).to_a
+ %p
= f.label :default_sort, :caption => t('site.default_sort')
%br/
= f.select :default_sort, :options => sort_options
@@ -20,6 +20,24 @@
subject.index(/First Post/).should be > subject.index(/Test Post \d+/)
end
end
+
+ context 'number of posts displayed' do
+ before { 11.times { Factory(:post) } }
+ after { Post.destroy }
+
+ it 'should displayed 10' do
+ subject.scan(/<h2 class="title"><a href="\/[^"]*">Test Post.*<\/a><\/h2>/).size.should eq(10)
+ end
+
+ context 'change the number displayed on 5' do
+ before { Site.first.update(:per_page => 5) }
+ after { Site.first.update(:per_page => 10) }
+
+ it 'should displayed 5' do
+ subject.scan(/<h2 class="title"><a href="\/[^"]*">Test Post.*<\/a><\/h2>/).size.should eq(5)
+ end
+ end
+ end
end
context '/:id' do

0 comments on commit d3bbff3

Please sign in to comment.