Module: PaginateAlphabetically::ViewHelpers

Defined in:
lib/view_helpers.rb

Instance Method Summary collapse

Instance Method Details



17
18
19
20
21
# File 'lib/view_helpers.rb', line 17

def alphabetical_links_to(available_letters)
  ('A'..'Z').map do |letter|
    (:li, paginated_letter(available_letters, letter))
  end.join(" ")
end

#alphabetically_paginate(collection) ⇒ Object



3
4
5
6
7
8
# File 'lib/view_helpers.rb', line 3

def alphabetically_paginate(collection)
  return "" if collection.empty?
  available_letters = collection.first.class.pagination_letters
  (:ul, safe(alphabetical_links_to(available_letters)),
              :class => "pagination")
end

#paginated_letter(available_letters, letter) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/view_helpers.rb', line 23

def paginated_letter(available_letters, letter)
  if available_letters.include?(letter)
    link_to(letter, "#{request.path}?letter=#{letter}")
  else
    letter
  end
end

#safe(content) ⇒ Object



10
11
12
13
14
15
# File 'lib/view_helpers.rb', line 10

def safe(content)
  if content.respond_to?(:html_safe)
    return content.html_safe
  end
  content
end