Permalink
Browse files

Removed register call. Updated #href_for_pagin to allow for base uri …

…override option
  • Loading branch information...
1 parent f34d4e7 commit 328693dfc14985d21fda2de6f364eedee9c77eef @nowk committed Aug 1, 2010
Showing with 22 additions and 7 deletions.
  1. +5 −0 Changelog.md
  2. +4 −1 README.md
  3. +7 −5 lib/sinatra/pagin.rb
  4. +6 −1 spec/pagin_spec.rb
View
@@ -1,3 +1,8 @@
+### sinatra-pagin - 0.0.3 / 2010-08-01
+
+* #href_for_pagin now accepts overrides for the base uri to be used when attaching the page/#
+* Helper registration is now manual, i've removed the registration call.
+
### sinatra-pagin - 0.0.2 / 2010-02-15
* Added a new helper method `href_for_pagin` to help facilitate creating pagination hrefs for use with pagin.
View
@@ -23,6 +23,7 @@ Given you have mapped paths as such:
Without changing those paths, you can run a paginated url.
require 'sinatra/pagin
+ Sinatra::Application.register Sinatra::Pagin
###
@@ -85,10 +86,12 @@ Install the gem:
sudo gem install sinatra-pagin
-Require in your app:
+Require & Register in your app:
require 'sinatra/pagin'
+ Sinatra::Application.register Sinatra::Pagin
+
## Integrity
[Checked by Integrity](http://ci.damncarousel.com)
View
@@ -26,8 +26,12 @@ def page(pg = 1)
@page || 1
end
- def href_for_pagin(total_pages, direction = :next)
- path_info = request.path_info.gsub(/\/$/, '') # clear off the last slash just in case
+ def href_for_pagin(total_pages, direction = :next, override = nil)
+ if override.nil?
+ path_info = request.path_info.gsub(/\/$/, '') # clear off the last slash just in case
+ else
+ path_info = override
+ end
page_num = 1
case
@@ -41,6 +45,4 @@ def href_for_pagin(total_pages, direction = :next)
end
end
end
-
- Sinatra::Application.register Pagin
-end
+end
View
@@ -194,6 +194,11 @@ def get_absolute(uri)
page 3
href_for_pagin(3, :next).should == "/2009/10/page/3"
end
+
+ it "allows for the base path to be overridden" do
+ page 2
+ href_for_pagin(3, :next, '/base/path').should == '/base/path/page/3'
+ end
end
context "within an actual app" do
@@ -244,4 +249,4 @@ def get_absolute(uri)
end
end
end
-end
+end

0 comments on commit 328693d

Please sign in to comment.