[Borges-users] Extension of BatchedList
Eric Hodel
drbrain at segment7.net
Thu Apr 1 06:15:07 EST 2004
Kaspar Schiess (eule at space.ch) wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello all,
>
> I have developed an extension of the Borges::BatchedList. I would like
> to submit it to you for free usage; maybe we could even add this to
> Borges itself ?
Yes, this looks nice.
[snip]
> I will gladly listen to all suggestions. Note that this is tested code
> and seems to work, but as always, if it blows, it's not the fault of the
> friendly guy giving away stuff (ie: me).
Comments inline
> class Borges::ExtendedBatchedList < Borges::BatchedList
A better name is needed, since "Extended" isn't very descriptive.
Perhaps something like Limited or (I thought of something almost there,
but I've since lost it).
> DEFAULT_ENV = 5
>
> attr_accessor :environment
>
> ##
> # Create a new BatchedList from +items+, with +size+ items per page.
Fix comment to read something like:
##
# Create a new BatchedList from +items+, with +size+ items per page,
# and links +environment+ immediately surrounding pages.
> def initialize(items = [], size = DEFAULT_SIZE, environment = DEFAULT_ENV)
> super(items, size)
> @environment = environment
> end
>
> # Decides if the page number n is displayed, given current page and
> # environment size
> def should_display?(n)
> f = 1
> while f<max_pages
> if (n+1)%f==0 && (current_page-n).abs < environment*f
> return true
> end
>
> f *= 10
while f < max_pages do
if (n + 1) % f == 0 && (current_page - n).abs < environment*f then
return true
end
I always use the do and then keywords, and I always have space between
operators. (The indent looks funny because of the tab.)
> end
> return false
> end
>
> ##
> # Render the page selector for the batch.
> #
> # You must supply your own code to render the contents of the batch. See
> # StoreItemList for an example.
>
> def render_content_on(r)
> return if max_pages == 0
>
> r.div_named('batch') do
> unless on_first_page? then
> r.anchor('<<') do previous_page end
> else
> r.text('<<')
If you'd like, you can omit () if unneeded. I plan on removing them in
methods I touch, since they're just leftovers from the port from
Seaside.
> end
>
> r.space
>
> dots = false
> 0.upto(max_pages - 1) do |i|
> unless should_display?(i)
> unless dots
> r.space
> r.text('...')
> end
> dots = true
> next
> end
>
> dots = false
>
> r.space
>
> unless @current_page == i then
> r.anchor(i + 1) do @current_page = i end
> else
> r.bold(i + 1)
> end
>
> end
>
> r.space
> r.space
>
> unless on_last_page? then
> r.anchor('>>') do next_page end
>
> else
> r.text('>>')
>
> end
> end
> end
>
> end
>
--
Eric Hodel - drbrain at segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/borges-users/attachments/20040401/1d81c584/attachment.bin
More information about the Borges-users
mailing list