17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/orthor_helper.rb', line 17
def (category_id, options = {})
return unless defined?(request) && defined?(params)
current_page = params[:page] ? params[:page].to_i : 1
category = Orthor.category(category_id, :page => current_page)
return if category == "" || category["total_pages"] == 1
options[:prev_label] ||= "←"
options[:next_label] ||= "→"
if params[:page] && params[:page].to_i > 0
href = request.url
else
href = request.url + (request.url.include?("?") ? "&" : "?") + "page=#{current_page}"
end
previous_link = if current_page > 1
%!<a class="previous" href="#{href.gsub("page=#{current_page}", "page=#{current_page - 1}")}">#{options[:prev_label]}</a>!
else
%!<span class="previous disabled">#{options[:prev_label]}</span>!
end
next_link = if current_page < category["total_pages"]
%!<a class="next" href="#{href.gsub("page=#{current_page}", "page=#{current_page + 1}")}">#{options[:next_label]}</a>!
else
%!<span class="next disabled">#{options[:next_label]}</span>!
end
html = <<-HTML
<div class="orthor-pagination">
#{previous_link}
#{next_link}
</div>
HTML
make_safe(html)
end
|