Skip to content

Commit c891922

Browse files
committed
Moving from WP to MM's default pagination.
1 parent 22349b5 commit c891922

7 files changed

Lines changed: 14 additions & 45 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.swp
22
*~
33
.bundle
4+
tmp/

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ gem "pony", "~>1.0.1"
1818
gem "sinatra-content-for"
1919
gem "exceptional"
2020
gem "newrelic_rpm"
21-
gem "will_paginate"
2221

2322
group :development do
2423
gem "rocco"

Gemfile.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ GEM
8989
nokogiri (>= 1.2.0)
9090
rack (>= 1.0)
9191
rack-test (>= 0.5.3)
92-
will_paginate (2.3.15)
9392

9493
PLATFORMS
9594
ruby
@@ -115,4 +114,3 @@ DEPENDENCIES
115114
sinatra-content-for
116115
steak (~> 1.0.0)
117116
webrat (~> 0.7.1)
118-
will_paginate

hackety.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@
100100
# [a Sinatra version](https://github.com/foca/sinatra-content-for).
101101
require 'sinatra/content_for'
102102

103-
# will_paginate can work with Sinatra
104-
# https://gist.github.com/553473
105-
require 'will_paginate'
106-
require 'will_paginate/collection'
107-
require 'will_paginate/view_helpers'
108-
109-
110103
# We moved lots of helpers into a separate file. These are all things that are
111104
# useful throughout the rest of the application. This file
112105
require_relative 'helpers'
@@ -217,14 +210,15 @@
217210
# the content that others have posted. So we grab it all, and sort it in the
218211
# opposite order that it's been updated. Wouldn't want to see old stuff!
219212
get '/stream' do
220-
limit = 20
221213
page = params[:page] || 1
222-
page = page.to_i
223-
page -= 1
224-
offset = limit * page
225-
content_list = Content.sort(:updated_at.desc).all( :limit => limit, :offset => offset)
214+
@content_list = Content.paginate( :page => params[:page], :per_page => params[:per_page] || 20, :order => :updated_at.desc)
215+
if @content_list.next_page
216+
@next_page = "?#{Rack::Utils.build_query :page => @content_list.next_page}"
217+
end
226218

227-
@content_list = WillPaginate::Collection.create(page + 1, limit, Content.count) {|p| p.replace content_list }
219+
if @content_list.previous_page
220+
@prev_page = "?#{Rack::Utils.build_query :page => @content_list.previous_page}"
221+
end
228222
haml :stream
229223
end
230224

helpers.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ def gravatar_url_for email
7474
"http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.downcase)}"
7575
end
7676

77-
# Will_paginate helpers
78-
include WillPaginate::ViewHelpers
79-
8077
end
8178

8279
# This handy helper method lets us require an entire directory of `rb` files.

models/stream_renderer.rb

Lines changed: 0 additions & 25 deletions
This file was deleted.

views/stream.haml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@
5353
shared a
5454
%a{:href => "/content/#{content.id}"}= content.type
5555
\: "#{content.body[0,50]}..." (#{content.comments.length} comments)
56-
!= will_paginate @content_list
56+
- unless @prev_page.nil?
57+
%a.button{:href => @prev_page, :id => "prev_button"}
58+
« Previous
5759

60+
- unless @next_page.nil?
61+
%a.button{:href => @next_page, :id => "next_button"}
62+
Next »
5863

5964
- content_for :head do
6065
:javascript

0 commit comments

Comments
 (0)