Class: Struggle::Pager

Inherits:
Object
  • Object
show all
Defined in:
lib/struggle/pager.rb

Instance Method Summary collapse

Constructor Details

#initialize(dqyclass = 'page-navigator-current PNNW-S', aclass = 'page-navigator-number PNNW-S', spageclass = 'page-navigator-prev', xpageclass = 'page-navigator-next', spagedis = 'page-navigator-prev-disable', xpagedis = 'page-navigator-next-disable', dianclass = 'page-navigator-dots') ⇒ Pager

Returns a new instance of Pager.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/struggle/pager.rb', line 3

def initialize(dqyclass='page-navigator-current PNNW-S', aclass='page-navigator-number PNNW-S',
               spageclass='page-navigator-prev', xpageclass='page-navigator-next', spagedis='page-navigator-prev-disable',
               xpagedis='page-navigator-next-disable', dianclass='page-navigator-dots')
  @dqyclass = dqyclass
  @aclass = aclass
  @spageclass = spageclass
  @xpageclass = xpageclass
  @spagedis = spagedis
  @xpagedis = xpagedis
  @dianclass = dianclass
end

Instance Method Details

#getpage(currentpage, pagecount, route) ⇒ Object



15
16
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
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/struggle/pager.rb', line 15

def getpage(currentpage, pagecount, route)
  shenglvhao = "<span class='#{@dianclass}'>...</span>"
  syiye = currentpage>1 ? "<a class='#{@spageclass}' href='#{route}#{currentpage-1}'>&lt;上一页</a>" : "<span class='#{@spagedis}'>&lt;上一页</span>"
  xyiye = currentpage<pagecount ? "<a class='#{@xpageclass}' href='#{route}#{currentpage+1}'>下一页&gt;</a>" : "<span class='#{@xpagedis}'>&lt;下一页</span>"
  pages=""
  if currentpage<7 && pagecount>10
    for i in 1..9
      if currentpage==i
        pages += "<span class='#{@dqyclass}'>#{currentpage}</span>"
      else
        pages += "<a class='#{@aclass}' href='#{route}#{i}'>#{i}</a>"
      end
    end
    pages += shenglvhao
    pages += "<a class='#{@aclass}' href='#{route}#{pagecount}'>#{pagecount}</a>"
  elsif currentpage>=7 && currentpage<=pagecount-7
    pages = "<a class='#{@aclass}' href='1'>1</a>"
    pages += shenglvhao
    pages += "<a class='#{@aclass}S' href='#{route}#{currentpage-4}'>#{currentpage-4}</a>"
    pages += "<a class='#{@aclass}' href='#{route}#{currentpage-3}'>#{currentpage-3}</a>"
    pages += "<a class='#{@aclass}' href='#{route}#{currentpage-2}'>#{currentpage-2}</a>"
    pages += "<a class='#{@aclass}' href='#{route}#{currentpage-1}'>#{currentpage-1}</a>"
    pages += "<span class='#{@dqyclass}'>#{currentpage}</span>"
    pages += "<a class='#{@aclass}' href='#{route}#{currentpage+1}'>#{currentpage+1}</a>"
    pages += "<a class='#{@aclass}' href='#{route}#{currentpage+2}'>#{currentpage+2}</a>"
    pages += "<a class='#{@aclass}' href='#{route}#{currentpage+3}'>#{currentpage+3}</a>"
    pages += "<a class='#{@aclass}' href='#{route}#{currentpage+4}'>#{currentpage+4}</a>"
    pages += shenglvhao
    pages += "<a class='#{@aclass}' href='#{route}#{pagecount}'>#{pagecount}</a>"
  elsif currentpage>=7 && currentpage>pagecount-7
    pages = "<a class='#{@aclass}' href='1'>1</a>"
    pages += shenglvhao
    for i in 1..9
      fpage = pagecount-9+i
      if currentpage == fpage
        pages += "<span class='#{@dqyclass}'>#{currentpage}</span>"
      else
        pages += "<a class='#{@aclass}' href='#{route}#{fpage}'>#{fpage}</a>"
      end
    end
  elsif currentpage>0 && pagecount<=10
    for i in 1..10
      if currentpage==i
        pages += "<span class='#{@dqyclass}'>#{currentpage}</span>"
      else
        pages += "<a class='#{@aclass}' href='#{route}#{i}'>#{i}</a>"
      end
    end
  end
  syiye + pages +xyiye
end