Class: DmPagination::PaginationBuilder
- Inherits:
-
Object
- Object
- DmPagination::PaginationBuilder
- Defined in:
- lib/dm-pagination/pagination_builder.rb
Instance Method Summary collapse
-
#initialize(context, pagination, *args, &block) ⇒ PaginationBuilder
constructor
A new instance of PaginationBuilder.
- #link_to_next ⇒ Object
- #link_to_page(page) ⇒ Object
- #link_to_pages ⇒ Object
- #link_to_prev ⇒ Object
- #to_s(*args) ⇒ Object
Constructor Details
#initialize(context, pagination, *args, &block) ⇒ PaginationBuilder
Returns a new instance of PaginationBuilder.
3 4 5 6 7 8 9 10 |
# File 'lib/dm-pagination/pagination_builder.rb', line 3 def initialize(context, pagination, *args, &block) @context = context @pagination = pagination @block = block @options = args.last.kind_of?(Hash) ? args.pop : {} @options[:page] ||= :page @args = args.blank? ? [:prev, :pages, :next] : args end |
Instance Method Details
#link_to_next ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/dm-pagination/pagination_builder.rb', line 33 def link_to_next if @pagination.page < @pagination.num_pages @context.link_to next_label, url(@options[:page] => @pagination.page + 1), :class => :next, :rel => "next" else span.call(next_label, :next) end end |
#link_to_page(page) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/dm-pagination/pagination_builder.rb', line 43 def link_to_page(page) if page.nil? span.call truncate, @options[:style] elsif page == @pagination.page span.call page, [@options[:style], 'current'].compact.join(' ') else span.call link(page), @options[:style] end end |
#link_to_pages ⇒ Object
19 20 21 |
# File 'lib/dm-pagination/pagination_builder.rb', line 19 def link_to_pages @pagination.pages.map{|page| link_to_page(page)} end |
#link_to_prev ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/dm-pagination/pagination_builder.rb', line 23 def link_to_prev if @pagination.page > 1 @context.link_to prev_label, url(@options[:page] => @pagination.page - 1), :class => :prev, :rel => "prev" else span.call(prev_label, :prev) end end |
#to_s(*args) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/dm-pagination/pagination_builder.rb', line 12 def to_s(*args) args = @args if args.blank? items = args.map{|i| respond_to?("link_to_#{i}") ? send("link_to_#{i}") : []}.flatten @context.tag(:div, items.join("\n"), :class => "pagination") end |