Class: PaginationListLinkRenderer

Inherits:
WillPaginate::ViewHelpers::LinkRenderer
  • Object
show all
Defined in:
lib/pagination_list_link_renderer.rb

Instance Method Summary collapse

Instance Method Details

#alphabetic_page_href(character) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/pagination_list_link_renderer.rb', line 36

def alphabetic_page_href(character)
  # Add character to query
  search_params = @params.merge(:by_character => character)
  params = @template.params.merge(@search_key => search_params)
  # Drop page index
  params.delete(:page)

  @template.url_for(params)
end


26
27
28
29
30
31
32
33
34
# File 'lib/pagination_list_link_renderer.rb', line 26

def alphabetic_page_link(character, options = {})
  if character == @params[:by_character]
    link = "<em>%s</em>" % character.upcase
  else
    link = "<a class='per_page' href='%s'>%s</a>" % [alphabetic_page_href((options[:link_keyword] ? options[:link_keyword] : character)), character.upcase]
  end

  link
end

#alphabetic_paginationObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pagination_list_link_renderer.rb', line 13

def alphabetic_pagination
  paginated_scope = @template.instance_variable_get(:@paginated_scope)
  return "" unless paginated_scope

  characters = paginated_scope.character_list
  page_links = characters.map{|character| alphabetic_page_link(character)}
  all_links = Array.new
  all_links << alphabetic_page_link(I18n.t('katalog.show_all'), :link_keyword => '')
  all_links.concat(page_links)

  all_links.join('')
end

#html_container(html) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/pagination_list_link_renderer.rb', line 3

def html_container(html)
  @search_key = :search
  @params = @template.params[@search_key] || {}

  html = [per_page_link(25), per_page_link(50), per_page_link(200)].join('') + "<span>|</span>" + html
  html += "</div><div style='clear: both; padding-top: 0.5em;'>" + alphabetic_pagination
  html = "<div style='clear: both'>" + html + "</div>"
  tag(:div, html, container_attributes)
end

#per_page_href(count) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/pagination_list_link_renderer.rb', line 56

def per_page_href(count)
  params = @template.params.merge({:per_page => count})
  # Drop page index
  params.delete(:page)

  @template.url_for(params)
end


46
47
48
49
50
51
52
53
54
# File 'lib/pagination_list_link_renderer.rb', line 46

def per_page_link(count)
  if count == @template.params[:per_page].to_i
    link = "<em>%s</em>"  % count
  else
    link = "<a class='per_page' href='%s'>%s</a>" % [per_page_href(count), count]
  end

  link
end