Module: GuessPaging::GuessHelper
- Defined in:
- lib/guess_paging/guess_helper.rb
Instance Method Summary collapse
- #first_paging(guess, hash) ⇒ Object
- #last_paging(guess, hash) ⇒ Object
- #middle_paging(guess, hash) ⇒ Object
- #paging(guess) ⇒ Object
Instance Method Details
#first_paging(guess, hash) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/guess_paging/guess_helper.rb', line 21 def first_paging(guess, hash) li = "" (1..4).each do |i| li << if i == guess.current_page content_tag(:li, class: 'active') do "#{i}" end else content_tag(:li) do link_to("#{i}", request.path + "?" + hash.merge(page: i).to_param) end end end li << content_tag(:li, class: 'truncate') do "..." end li << content_tag(:li, class: 'last') do link_to("#{guess.max_page}", request.path + "?" + hash.merge(page: guess.max_page).to_param) end li.html_safe end |
#last_paging(guess, hash) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/guess_paging/guess_helper.rb', line 43 def last_paging(guess, hash) li = content_tag(:li) do link_to("1", request.path + "?" + hash.merge(page: 1).to_param) end li << content_tag(:li, class: 'truncate') do "..." end ((guess.max_page - 3)..guess.max_page).each do |i| li << if i == guess.current_page content_tag(:li, class: 'active') do "#{i}" end else content_tag(:li) do link_to("#{i}", request.path + "?" + hash.merge(page: i).to_param) end end end li.html_safe end |
#middle_paging(guess, hash) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/guess_paging/guess_helper.rb', line 64 def middle_paging(guess, hash) li = content_tag(:li) do link_to("1", request.path + "?" + hash.merge(page: 1).to_param) end li << content_tag(:li, class: 'truncate') do "..." end ((guess.current_page - 2)..(guess.current_page + 2)).each do |i| li << if guess.current_page == i content_tag(:li, class: 'active') do "#{i}" end else content_tag(:li) do link_to("#{i}", request.path + "?" + hash.merge(page: i).to_param) end end end li << content_tag(:li) do "..." end li << content_tag(:li) do link_to("#{guess.max_page}", request.path + "?" + hash.merge(page: guess.max_page).to_param) end li.html_safe end |
#paging(guess) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/guess_paging/guess_helper.rb', line 3 def paging(guess) hash = request.params hash.delete(:controller) hash.delete(:action) div = content_tag(:div, class: 'guess-paging') do content_tag(:ul) do if guess.current_page < 5 first_paging(guess, hash) elsif guess.current_page > guess.max_page - 4 last_paging(guess, hash) else middle_paging(guess, hash) end end end div.html_safe end |