Class: Symphonia::BootstrapLinkRender

Inherits:
WillPaginate::ActionView::LinkRenderer
  • Object
show all
Defined in:
lib/symphonia/bootstrap_link_render.rb

Instance Method Summary collapse

Instance Method Details

#default_url_paramsObject



34
35
36
# File 'lib/symphonia/bootstrap_link_render.rb', line 34

def default_url_params
  @options[:query] && @options[:query].to_params || {}
end

#page_number(page) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/symphonia/bootstrap_link_render.rb', line 48

def page_number(page)
  link_options = @options[:link_options] || {}

  if page == current_page
    tag(:span, page, class: 'page-link current_page')
  else
    link_options.merge! class: 'page-link', rel: rel_value(page)
    link(page, page, {:'data-remote' => @options[:remote]}.merge(link_options))
  end
end

#paginationObject



5
6
7
8
9
10
11
12
# File 'lib/symphonia/bootstrap_link_render.rb', line 5

def pagination
  items = @options[:page_links] ? windowed_page_numbers : []
  unless @options[:page_links] == :only
    items.unshift :previous_page
    items.push :next_page
  end
  items
end

#previous_or_next_page(page, text, classname) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/symphonia/bootstrap_link_render.rb', line 59

def previous_or_next_page(page, text, classname)
  if page
    link(text, page, :'data-remote' => @options[:remote], class: "page-link #{classname}")
  else
    tag(:span, text, class: "page-link #{classname} disabled")
  end
end

#to_htmlObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/symphonia/bootstrap_link_render.rb', line 14

def to_html
  html = pagination.map do |item|
    if @options[:remote]
      if item == :next_page
        tag :li,next_page, class: 'page-item'
      end
    else
      tag(:li, (item.is_a?(Integer) ?
        page_number(item) :
        send(item)).html_safe, class: 'page-item' + (item == current_page ? ' active' : ''))
    end
  end.join(@options[:link_separator])

  container_classes = %w(pagination justify-content-center)
  container_classes << 'pagination-sm' if @options[:small]
  container_classes << 'pagination-lg' if @options[:large]
  nav = tag(:ul, html.html_safe, class: container_classes.join(' '))
  tag :nav, nav, class: 'd-print-none'
end

#url(page) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/symphonia/bootstrap_link_render.rb', line 38

def url(page)
  @base_url_params ||= begin
    url_params = merge_get_params(default_url_params)
    url_params[:only_path] = true
    merge_optional_params(url_params)
  end

  @template.url_for(@base_url_params.merge({:page => page}))
end