Module: PaginatorHelper

Defined in:
app/helpers/paginator_helper.rb

Instance Method Summary collapse

Instance Method Details

#paginator(current_page, total_pages, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/paginator_helper.rb', line 4

def paginator(current_page, total_pages, options={})
	content = []

	state = current_page == 1 ? :disabled : :normal
	param_name = options.delete(:param) || :page
	content << page_item('«', current_page-1, state, param_name)

	total_pages.times do |i|
		page_num = i + 1
		state = page_num == current_page ? :active : :normal
		content << page_item(page_num, page_num, state, param_name)
	end

	state = current_page == total_pages ? :disabled : :normal
	content << page_item('»', current_page+1, state, param_name)

	paginator_params = options.dup
	paginator_params[:class] = parse_html_classes_to_arr paginator_params[:class]
	paginator_params[:class] << 'pagination'

	size = paginator_params.delete :size

	case size
		when :large
			paginator_params[:class] << 'pagination-lg'
		when :small
			paginator_params[:class] << 'pagination-sm'
	end

	 :ul, content.join("\n").html_safe, paginator_params
end