Class: UiKitLinkRenderer
- Inherits:
-
WillPaginate::ViewHelpers::LinkRendererBase
- Object
- WillPaginate::ViewHelpers::LinkRendererBase
- UiKitLinkRenderer
- Defined in:
- lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb
Constant Summary collapse
- GET_PARAMS_BLACKLIST =
[:script_name, :original_script_name]
Instance Method Summary collapse
-
#container_attributes ⇒ Object
Returns the subset of
optionsthis instance was initialized with that represent HTML attributes for the container element of pagination links. - #default_url_params ⇒ Object
- #gap ⇒ Object
- #html_container(html) ⇒ Object
- #next_page ⇒ Object
- #page_number(page) ⇒ Object
-
#prepare(collection, options, template) ⇒ Object
-
collectionis a WillPaginate::Collection instance or any other object that conforms to that API *optionsare forwarded fromwill_paginateview helper *templateis the reference to the template being rendered.
-
- #previous_or_next_page(page, attribute) ⇒ Object
- #previous_page ⇒ Object
-
#to_html ⇒ Object
Process it! This method returns the complete HTML string which contains pagination links.
Instance Method Details
#container_attributes ⇒ Object
Returns the subset of options this instance was initialized with that represent HTML attributes for the container element of pagination links.
31 32 33 |
# File 'lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb', line 31 def container_attributes @container_attributes ||= @options.except(*(WillPaginate::ViewHelpers..keys + [:renderer] - [:class])) end |
#default_url_params ⇒ Object
35 36 37 |
# File 'lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb', line 35 def default_url_params {} end |
#gap ⇒ Object
51 52 53 54 55 56 |
# File 'lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb', line 51 def gap text = @template.will_paginate_translate(:page_gap) { '…' } tag(:li) do tag(:span, text) end end |
#html_container(html) ⇒ Object
84 85 86 |
# File 'lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb', line 84 def html_container(html) tag(:ul, html, container_attributes) end |
#next_page ⇒ Object
63 64 65 66 |
# File 'lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb', line 63 def next_page num = @collection.current_page < total_pages && @collection.current_page + 1 previous_or_next_page(num, 'uk-pagination-next') end |
#page_number(page) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb', line 39 def page_number(page) if page == current_page tag(:li, nil, class: 'uk-active') do tag(:span, page) end else tag(:li) do tag(:a, page, href: url(page), rel: rel_value(page)) end end end |
#prepare(collection, options, template) ⇒ Object
-
collectionis a WillPaginate::Collection instance or any other object that conforms to that API -
optionsare forwarded fromwill_paginateview helper -
templateis the reference to the template being rendered
9 10 11 12 13 14 |
# File 'lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb', line 9 def prepare(collection, , template) super(collection, ) @options[:class] = 'uk-pagination' @template = template @container_attributes = @base_url_params = nil end |
#previous_or_next_page(page, attribute) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb', line 68 def previous_or_next_page(page, attribute) if page tag(:li, nil) do tag(:a, nil, href: url(page), rel: rel_value(page)) do tag(:span, '', attribute => '') end end else tag(:li, nil, class: 'uk-disabled') do tag(:a, nil, href: '#') do tag(:span, '', attribute => '') end end end end |
#previous_page ⇒ Object
58 59 60 61 |
# File 'lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb', line 58 def previous_page num = @collection.current_page > 1 && @collection.current_page - 1 previous_or_next_page(num, 'uk-pagination-previous') end |
#to_html ⇒ Object
Process it! This method returns the complete HTML string which contains pagination links. Feel free to subclass LinkRenderer and change this method as you see fit.
19 20 21 22 23 24 25 26 27 |
# File 'lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb', line 19 def to_html html = pagination.map do |item| item.is_a?(Integer) ? page_number(item) : send(item) end.join(@options[:link_separator]) @options[:container] ? html_container(html) : html end |