Class: WillPaginate::Liquidized::LinkRenderer

Inherits:
WillPaginate::LinkRenderer
  • Object
show all
Includes:
ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
Defined in:
lib/generators/liquid_cms/templates/vendor/plugins/will_paginate-liquidized/lib/will_paginate/liquidized/view_helpers.rb

Instance Method Summary collapse

Instance Method Details



50
51
52
# File 'lib/generators/liquid_cms/templates/vendor/plugins/will_paginate-liquidized/lib/will_paginate/liquidized/view_helpers.rb', line 50

def page_link(page, text, attributes = {})
  link_to text, url_for_page(page), attributes
end

#page_span(page, text, attributes = {}) ⇒ Object



54
55
56
# File 'lib/generators/liquid_cms/templates/vendor/plugins/will_paginate-liquidized/lib/will_paginate/liquidized/view_helpers.rb', line 54

def page_span(page, text, attributes = {})
   :span, text, attributes
end

#to_htmlObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/liquid_cms/templates/vendor/plugins/will_paginate-liquidized/lib/will_paginate/liquidized/view_helpers.rb', line 36

def to_html
  return "<p><strong style=\"color:red;\">(Will Paginate Liquidized) Error:</strong> you must pass a controller in Liquid render call; <br/>
          e.g. Liquid::Template.parse(\"{{ movies | will_paginate_liquid }}\").render({'movies' => @movies}, :registers => {:controller => @controller})</p>" unless @options[:controller]
  
  links = @options[:page_links] ? windowed_links : []
  # previous/next buttons added in to the links collection
  links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label])
  links.push    page_link_or_span(@collection.next_page,     'disabled next_page', @options[:next_label])
  
  html = links.join(@options[:separator])
  html_attributes.delete(:controller)
  @options[:container] ? (:div, html, html_attributes) : html
end

#url_for_page(page) ⇒ Object



58
59
60
61
62
63
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
90
91
92
93
94
95
96
# File 'lib/generators/liquid_cms/templates/vendor/plugins/will_paginate-liquidized/lib/will_paginate/liquidized/view_helpers.rb', line 58

def url_for_page(page)
  page_one = page == 1
  unless @url_string and !page_one
    @url_params = {}
    @controller = @options[:controller]
    # page links should preserve GET parameters
    stringified_merge @url_params, @controller.params if @controller && @controller.request.get? && @controller.params
    stringified_merge @url_params, @options[:params] if @options[:params]
    
    if complex = param_name.index(/[^\w-]/)
      page_param = (defined?(CGIMethods) ? CGIMethods : ActionController::AbstractRequest).
        parse_query_parameters("#{param_name}=#{page}")
      
      stringified_merge @url_params, page_param
    else
      @url_params[param_name] = page_one ? 1 : 2
    end

    url = @controller.url_for(@url_params)
    url = "#{url}##{@options[:params][:anchor]}" if @options[:params] && @options[:params][:anchor]
    return url if page_one
    
    if complex
      @url_string = url.sub(%r!((?:\?|&amp;)#{CGI.escape param_name}=)#{page}!, '\1@')
      return url
    else
      @url_string = url
      @url_params[param_name] = 3
      @controller.url_for(@url_params).split(//).each_with_index do |char, i|
        if char == '3' and url[i, 1] == '2'
          @url_string[i] = '@'
          break
        end
      end
    end
  end
  # finally!
  @url_string.sub '@', page.to_s
end