Skip to content

Commit

Permalink
helpers: deprecated positional id argument and added keyword arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 23, 2021
1 parent 9fd7930 commit 6ce0c1d
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 141 deletions.
22 changes: 12 additions & 10 deletions lib/pagy/extras/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Pagy
module Frontend

# Pagination for bootstrap: it returns the html with the series of links to the pages
def pagy_bootstrap_nav(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy, 'class="page-link"')
def pagy_bootstrap_nav(pagy, pagy_id: nil, link_extra: '')
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, %(class="page-link" #{link_extra}))

html = +%(<nav#{p_id} class="pagy-bootstrap-nav" role="navigation" aria-label="pager"><ul class="pagination">)
html << pagy_bootstrap_prev_html(pagy, link)
Expand All @@ -25,23 +25,25 @@ def pagy_bootstrap_nav(pagy, id=nil)
end

# Javascript pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_bootstrap_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy, 'class="page-link"')
def pagy_bootstrap_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, %(class="page-link" #{link_extra}))
tags = { 'before' => %(<ul class="pagination">#{pagy_bootstrap_prev_html pagy, link}),
'link' => %(<li class="page-item">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
'active' => %(<li class="page-item active">#{mark}</li>),
'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.gap'}</a></li>),
'after' => %(#{pagy_bootstrap_next_html pagy, link}</ul>) }

html = %(<nav#{p_id} class="pagy-bootstrap-nav-js" role="navigation" aria-label="pager"></nav>)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
end

# Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_bootstrap_combo_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_bootstrap_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
p_pages = pagy.pages
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" class="text-primary" style="padding: 0; border: none; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
Expand Down
22 changes: 12 additions & 10 deletions lib/pagy/extras/bulma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Pagy
module Frontend

# Pagination for Bulma: it returns the html with the series of links to the pages
def pagy_bulma_nav(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '')
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)

html = +%(<nav#{p_id} class="pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">)
html << pagy_bulma_prev_next_html(pagy, link)
Expand All @@ -24,23 +24,25 @@ def pagy_bulma_nav(pagy, id=nil)
html << %(</ul></nav>)
end

def pagy_bulma_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_bulma_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
tags = { 'before' => %(#{pagy_bulma_prev_next_html(pagy, link)}<ul class="pagination-list">),
'link' => %(<li>#{link.call PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link" aria-label="goto page #{PAGE_PLACEHOLDER}")}</li>),
'active' => %(<li>#{link.call PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link is-current" aria-current="page" aria-label="page #{PAGE_PLACEHOLDER}")}</li>),
'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap' }</span></li>),
'after' => '</ul>' }

html = %(<nav#{p_id} class="pagy-bulma-nav-js pagination is-centered" role="navigation" aria-label="pagination"></nav>)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
end

# Javascript combo pagination for Bulma: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_bulma_combo_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_bulma_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
p_pages = pagy.pages
input = %(<input class="input" type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem; margin:0 0.3rem;">)
Expand Down
22 changes: 12 additions & 10 deletions lib/pagy/extras/foundation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Pagy
module Frontend

# Pagination for Foundation: it returns the html with the series of links to the pages
def pagy_foundation_nav(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_foundation_nav(pagy, pagy_id: nil, link_extra: '')
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)

html = +%(<nav#{p_id} class="pagy-foundation-nav" role="navigation" aria-label="Pagination"><ul class="pagination">)
html << pagy_foundation_prev_html(pagy, link)
Expand All @@ -25,23 +25,25 @@ def pagy_foundation_nav(pagy, id=nil)
end

# Javascript pagination for foundation: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_foundation_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_foundation_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
tags = { 'before' => %(<ul class="pagination">#{pagy_foundation_prev_html pagy, link}),
'link' => %(<li>#{link.call PAGE_PLACEHOLDER}</li>),
'active' => %(<li class="current">#{pagy.page}</li>),
'gap' => %(<li class="ellipsis gap" aria-hidden="true"></li>),
'after' => %(#{pagy_foundation_next_html pagy, link}</ul>) }

html = %(<nav#{p_id} class="pagy-foundation-nav-js" role="navigation" aria-label="Pagination"></nav>)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
end

# Javascript combo pagination for Foundation: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_foundation_combo_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_foundation_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
p_pages = pagy.pages
input = %(<input class="input-group-field cell shrink" type="number" min="1" max="#{p_pages}" value="#{p_page}" style="width: #{p_pages.to_s.length+1}rem; padding: 0 0.3rem; margin: 0 0.3rem;">)
Expand Down
9 changes: 5 additions & 4 deletions lib/pagy/extras/items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def pagy_url_for(page, pagy, url=nil)
prepend UseItemsExtra

# Return the items selector HTML. For example "Show [20] items per page"
def pagy_items_selector_js(pagy, id=nil)
p_id = %( id="#{id}") if id
def pagy_items_selector_js(pagy, deprecated_id=nil, pagy_id: nil, item_name: nil, i18n_key: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
p_vars = pagy.vars
p_items = p_vars[:items]
p_vars[:items] = ITEMS_PLACEHOLDER
Expand All @@ -59,10 +60,10 @@ def pagy_items_selector_js(pagy, id=nil)

html = %(<span#{p_id}>)
input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length+1}rem;">)
html << pagy_t('pagy.items_selector_js', item_name: pagy_t(p_vars[:i18n_key], count: p_items),
html << pagy_t('pagy.items_selector_js', item_name: item_name || pagy_t(i18n_key || p_vars[:i18n_key], count: p_items),
items_input: input,
count: p_items)
html << %(</span>#{pagy_json_tag(pagy, :items_selector, pagy.from, link)})
html << %(</span>#{pagy_json_tag pagy, :items_selector, pagy.from, link})
end

end
Expand Down
23 changes: 13 additions & 10 deletions lib/pagy/extras/materialize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Pagy
module Frontend

# Pagination for materialize: it returns the html with the series of links to the pages
def pagy_materialize_nav(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_materialize_nav(pagy, pagy_id: nil, link_extra: '')
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)

html = +%(<div#{p_id} class="pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">)
html << pagy_materialize_prev_html(pagy, link)
Expand All @@ -25,23 +25,26 @@ def pagy_materialize_nav(pagy, id=nil)
end

# Javascript pagination for materialize: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_materialize_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_materialize_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)

tags = { 'before' => %(<ul class="pagination">#{pagy_materialize_prev_html pagy, link}),
'link' => %(<li class="waves-effect">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
'active' => %(<li class="active">#{mark}</li>),
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>),
'after' => %(#{pagy_materialize_next_html pagy, link}</ul>) }

html = %(<div#{p_id} class="pagy-materialize-nav-js" role="navigation" aria-label="pager"></div>)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
end

# Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_materialize_combo_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_materialize_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
p_pages = pagy.pages
style = ' style="vertical-align: middle;"'
Expand Down
16 changes: 9 additions & 7 deletions lib/pagy/extras/navs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ class Pagy
module Frontend

# Javascript pagination: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
tags = { 'before' => pagy_nav_prev_html(pagy, link),
'link' => %(<span class="page">#{link.call(PAGE_PLACEHOLDER)}</span> ),
'active' => %(<span class="page active">#{pagy.page}</span> ),
'gap' => %(<span class="page gap">#{pagy_t 'pagy.nav.gap'}</span> ),
'after' => pagy_nav_next_html(pagy, link) }

html = %(<nav#{p_id} class="pagy-nav-js pagination" role="navigation" aria-label="pager"></nav>)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
end

# Javascript combo pagination: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_combo_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy)
def pagy_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra)
p_page = pagy.page
p_pages = pagy.pages
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
Expand Down
22 changes: 12 additions & 10 deletions lib/pagy/extras/semantic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Pagy
module Frontend

# Pagination for semantic: it returns the html with the series of links to the pages
def pagy_semantic_nav(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy, 'class="item"')
def pagy_semantic_nav(pagy, pagy_id: nil, link_extra: '')
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, %(class="item" #{link_extra}"))

html = +%(<div#{p_id} class="pagy-semantic-nav ui pagination menu" aria-label="pager">)
html << pagy_semantic_prev_html(pagy, link)
Expand All @@ -25,23 +25,25 @@ def pagy_semantic_nav(pagy, id=nil)
end

# Javascript pagination for semantic: it returns a nav and a JSON tag used by the Pagy.nav javascript
def pagy_semantic_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy, 'class="item"')
def pagy_semantic_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, %(class="item" #{link_extra}))
tags = { 'before' => pagy_semantic_prev_html(pagy, link),
'link' => link.call(PAGE_PLACEHOLDER),
'active' => %(<a class="item active">#{pagy.page}</a>),
'gap' => %(<div class="disabled item">#{pagy_t('pagy.nav.gap')}</div>),
'after' => pagy_semantic_next_html(pagy, link) }

html = %(<div#{p_id} class="pagy-semantic-nav-js ui pagination menu" role="navigation" aria-label="pager"></div>)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels)
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
end

# Combo pagination for semantic: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
def pagy_semantic_combo_nav_js(pagy, id=nil)
p_id = %( id="#{id}") if id
link = pagy_link_proc(pagy, 'class="item"')
def pagy_semantic_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
pagy_id = pagy_deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, %(class="item" #{link_extra}))
p_page = pagy.page
p_pages = pagy.pages
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem; margin: 0 0.3rem">)
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Pagy
# "350" => [1, 2, :gap, 17, 18, 19, "20", 21, 22, 23, :gap, 49, 50],
# "550" => [1, 2, 3, :gap, 16, 17, 18, 19, "20", 21, 22, 23, 24, :gap, 48, 49, 50] }
# Notice: if :steps is false it will use the single {0 => @vars[:size]} size
def sequels
steps = @vars[:steps] || {0 => @vars[:size]}
def sequels(steps=nil)
steps ||= @vars[:steps] || {0 => @vars[:size]}
raise VariableError.new(self), "expected :steps to define the 0 width; got #{steps.inspect}" \
unless steps.key?(0)
{}.tap do |sequels|
Expand Down
8 changes: 6 additions & 2 deletions lib/pagy/extras/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ def pagy_next_url(pagy)
pagy_url_for(pagy.next, pagy) if pagy.next
end

def pagy_prev_link(pagy, text = pagy_t('pagy.nav.prev'), link_extra = '')
def pagy_prev_link(pagy, deprecated_text=nil, deprecated_link_extra=nil, text: pagy_t('pagy.nav.prev'), link_extra: '')
text = pagy_deprecated_arg(:text, deprecated_text, :text, text) if deprecated_text
link_extra = pagy_deprecated_arg(:link_extra, deprecated_link_extra, :link_extra, link_extra) if deprecated_link_extra
if pagy.prev
%(<span class="page prev"><a href="#{pagy_url_for(pagy.prev, pagy)}" rel="prev" aria-label="previous" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
else
%(<span class="page prev disabled">#{text}</span>)
end
end

def pagy_next_link(pagy, text = pagy_t('pagy.nav.next'), link_extra = '')
def pagy_next_link(pagy, deprecated_text=nil, deprecated_link_extra=nil, text: pagy_t('pagy.nav.next'), link_extra: '')
text = pagy_deprecated_arg(:text, deprecated_text, :text, text) if deprecated_text
link_extra = pagy_deprecated_arg(:link_extra, deprecated_link_extra, :link_extra, link_extra) if deprecated_link_extra
if pagy.next
%(<span class="page next"><a href="#{pagy_url_for(pagy.next, pagy)}" rel="next" aria-label="next" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
else
Expand Down
Loading

0 comments on commit 6ce0c1d

Please sign in to comment.