Skip to content

Commit

Permalink
small code normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 19, 2021
1 parent 3ea2d27 commit 487eb70
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 42 deletions.
2 changes: 1 addition & 1 deletion lib/pagy/extras/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def pagy_bootstrap_combo_nav_js(pagy, id=pagy_id)
%(<a class="next btn btn-primary disabled" href="#">#{pagy_t 'pagy.nav.next' }</a>)
end
}</div></nav>#{
pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
})
end

Expand Down
6 changes: 3 additions & 3 deletions lib/pagy/extras/bulma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def pagy_bulma_nav(pagy)
html << case item
when Integer then %(<li>#{link.call item, item, %(class="pagination-link" aria-label="goto page #{item}") }</li>) # page link
when String then %(<li>#{link.call item, item, %(class="pagination-link is-current" aria-label="page #{item}" aria-current="page")}</li>) # active page
when :gap then %(<li><span class="pagination-ellipsis">#{pagy_t('pagy.nav.gap')}</span></li>) # page gap
when :gap then %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap'}</span></li>) # page gap
end
end
html << %(</ul></nav>)
Expand Down Expand Up @@ -48,14 +48,14 @@ def pagy_bulma_combo_nav_js(pagy, id=pagy_id)
else
%(<p class="control"><a class="button" disabled>#{pagy_t 'pagy.nav.prev'}</a></p>)
end
}<div class="pagy-combo-input control level is-mobile">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div>#{
}<div class="pagy-combo-input control level is-mobile">#{pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</div>#{
if (p_next = pagy.next)
%(<p class="control">#{link.call p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"'}</p>)
else
%(<p class="control"><a class="button" disabled>#{pagy_t 'pagy.nav.next'}</a></p>)
end
}</div></nav>#{
pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
})
end

Expand Down
10 changes: 6 additions & 4 deletions lib/pagy/extras/foundation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def pagy_foundation_nav(pagy)
# 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=pagy_id)
link = pagy_link_proc(pagy)
tags = { 'before' => %(<ul class="pagination">#{pagy_foundation_prev_html(pagy, link)}),
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>) }
'after' => %(#{pagy_foundation_next_html pagy, link}</ul>) }

html = %(<nav id="#{id}" class="pagy-foundation-nav-js" role="navigation" aria-label="Pagination"></nav>)
html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
Expand All @@ -47,15 +47,17 @@ def pagy_foundation_combo_nav_js(pagy, id=pagy_id)
if (p_prev = pagy.prev)
link.call p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom: 0px;" aria-label="previous" class="prev button primary"'
else
%(<a style="margin-bottom: 0px;" class="prev button primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>)
%(<a style="margin-bottom: 0px;" class="prev button primary disabled" href="#">#{pagy_t 'pagy.nav.prev'}</a>)
end
}<span class="input-group-label">#{pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</span>#{
if (p_next = pagy.next)
link.call p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0px;" aria-label="next" class="next button primary"'
else
%(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t 'pagy.nav.next'}</a>)
end
}</div></nav>#{pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))})
}</div></nav>#{
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
})
end

private
Expand Down
18 changes: 9 additions & 9 deletions lib/pagy/extras/materialize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def pagy_materialize_nav(pagy)
html << case item
when Integer then %(<li class="waves-effect">#{link.call item}</li>) # page link
when String then %(<li class="active">#{link.call item}</li>) # active page
when :gap then %(<li class="gap disabled"><a href="#">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
when :gap then %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>) # page gap
end
end
html << pagy_materialize_next_html(pagy, link)
Expand All @@ -26,11 +26,11 @@ def pagy_materialize_nav(pagy)
# 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=pagy_id)
link = pagy_link_proc(pagy)
tags = { 'before' => %(<ul class="pagination">#{pagy_materialize_prev_html(pagy, link)}),
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>) }
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>),
'after' => %(#{pagy_materialize_next_html pagy, link}</ul>) }

html = %(<div id="#{id}" class="pagy-materialize-nav-js" role="navigation" aria-label="pager"></div>)
html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
Expand All @@ -45,13 +45,13 @@ def pagy_materialize_combo_nav_js(pagy, id=pagy_id)
input = %(<input type="number" class="browser-default" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 2px; border: none; border-radius: 2px; text-align: center; width: #{p_pages.to_s.length+1}rem;">)

%(<div id="#{id}" class="pagy-materialize-combo-nav-js pagination" role="navigation" aria-label="pager"><div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;"><ul class="pagination" style="margin: 0px;">#{
pagy_materialize_prev_html(pagy, link, style)
pagy_materialize_prev_html pagy, link, style
}<div class="pagy-combo-input btn-flat" style="cursor: default; padding: 0px">#{
pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
}</div>#{
pagy_materialize_next_html(pagy, link, style)
pagy_materialize_next_html pagy, link, style
}</ul></div>#{
pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
})
end

Expand All @@ -61,7 +61,7 @@ def pagy_materialize_prev_html(pagy, link, style='')
if (p_prev = pagy.prev)
%(<li class="waves-effect prev"#{style}>#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
else
+%(<li class="prev disabled"#{style}><a href="#"><i class="material-icons">chevron_left</i></a></li>)
%(<li class="prev disabled"#{style}><a href="#"><i class="material-icons">chevron_left</i></a></li>)
end
end

Expand Down
14 changes: 7 additions & 7 deletions lib/pagy/extras/navs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def pagy_nav_js(pagy, id=pagy_id)
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> ),
'gap' => %(<span class="page gap">#{pagy_t 'pagy.nav.gap'}</span> ),
'after' => pagy_nav_next_html(pagy, link) }

html = %(<nav id="#{id}" class="pagy-nav-js pagination" role="navigation" aria-label="pager"></nav>)
Expand All @@ -27,13 +27,13 @@ def pagy_combo_nav_js(pagy, id=pagy_id)
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;">)

%(<nav id="#{id}" class="pagy-combo-nav-js pagination" role="navigation" aria-label="pager">#{
pagy_nav_prev_html(pagy, link)
pagy_nav_prev_html pagy, link
}<span class="pagy-combo-input" style="margin: 0 0.6rem;">#{
pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
}</span> #{
pagy_nav_next_html(pagy, link)
pagy_nav_next_html pagy, link
}</nav>#{
pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
})
end

Expand All @@ -43,15 +43,15 @@ def pagy_nav_prev_html(pagy, link)
if (p_prev = pagy.prev)
%(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
else
%(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> )
%(<span class="page prev disabled">#{pagy_t 'pagy.nav.prev'}</span> )
end
end

def pagy_nav_next_html(pagy, link)
if (p_next = pagy.next)
%(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
else
%(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>)
%(<span class="page next disabled">#{pagy_t 'pagy.nav.next'}</span>)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/overflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def initialize(vars)
raise # same as without the extra
when :last_page
initial_page = @vars[:page] # save the very initial page (even after re-run)
initialize(vars.merge!(page: @last)) # re-run with the last page
initialize vars.merge!(page: @last) # re-run with the last page
@vars[:page] = initial_page # restore the inital page
when :empty_page
@offset = @items = @from = @to = 0 # vars relative to the actual page
@prev = @last # prev relative to the actual page
extend(Series) # special series for :empty_page
extend Series # special series for :empty_page
else
raise VariableError.new(self), "expected :overflow variable in [:last_page, :empty_page, :exception]; got #{@vars[:overflow].inspect}"
end
Expand Down
12 changes: 6 additions & 6 deletions lib/pagy/extras/semantic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def pagy_semantic_combo_nav_js(pagy, id=pagy_id)
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">)

%(<div id="#{id}" class="pagy-semantic-combo-nav-js ui compact menu" role="navigation" aria-label="pager">#{
pagy_semantic_prev_html(pagy, link)
pagy_semantic_prev_html pagy, link
}<div class="pagy-combo-input item">#{
pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
}</div> #{
pagy_semantic_next_html(pagy, link)
pagy_semantic_next_html pagy, link
}</div>#{
pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
})
end

Expand All @@ -60,15 +60,15 @@ def pagy_semantic_prev_html(pagy, link)
if (p_prev = pagy.prev)
link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'
else
%(<div class="item disabled"><i class="left small chevron icon"></i></div>)
+%(<div class="item disabled"><i class="left small chevron icon"></i></div>)
end
end

def pagy_semantic_next_html(pagy, link)
if (p_next = pagy.next)
link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'
else
%(<div class="item disabled"><i class="right small chevron icon"></i></div>)
+%(<div class="item disabled"><i class="right small chevron icon"></i></div>)
end
end

Expand Down
18 changes: 9 additions & 9 deletions lib/pagy/extras/uikit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ module Frontend
def pagy_uikit_nav(pagy)
link = pagy_link_proc(pagy)

html = %(<ul class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html(pagy, link)})
html = %(<ul class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html pagy, link})
pagy.series.each do |item|
html << case item
when Integer then %(<li>#{link.call item}</li>)
when String then %(<li class="uk-active"><span>#{item}</span></li>)
when :gap then %(<li class="uk-disabled"><span>#{pagy_t('pagy.nav.gap')}</span></li>)
when :gap then %(<li class="uk-disabled"><span>#{pagy_t 'pagy.nav.gap'}</span></li>)
end
end
html << pagy_uikit_next_html(pagy, link)
Expand Down Expand Up @@ -46,18 +46,18 @@ def pagy_uikit_combo_nav_js(pagy, id=pagy_id)
if (p_prev = pagy.prev)
link.call p_prev, pagy_t('pagy.nav.prev'), 'class="uk-button uk-button-default"'
else
%(<button class="uk-button uk-button-default" disabled>#{pagy_t('pagy.nav.prev')}</button>)
%(<button class="uk-button uk-button-default" disabled>#{pagy_t 'pagy.nav.prev'}</button>)
end
}<div class="uk-text-middle uk-margin-left uk-margin-right">#{
pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
}</div>#{
if (p_next = pagy.next)
link.call(p_next, pagy_t('pagy.nav.next'), 'class="uk-button uk-button-default"')
link.call p_next, pagy_t('pagy.nav.next'), 'class="uk-button uk-button-default"'
else
%(<button class="uk-button uk-button-default" disabled>#{pagy_t('pagy.nav.next')}</button>)
%(<button class="uk-button uk-button-default" disabled>#{pagy_t 'pagy.nav.next'}</button>)
end
}</div>#{
pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
})
end

Expand All @@ -66,7 +66,7 @@ def pagy_uikit_combo_nav_js(pagy, id=pagy_id)
private

def pagy_uikit_prev_html(pagy, link)
previous_span = %(<span uk-pagination-previous>#{pagy_t('pagy.nav.prev')}</span>)
previous_span = %(<span uk-pagination-previous>#{pagy_t 'pagy.nav.prev'}</span>)
if (p_prev = pagy.prev)
%(<li>#{link.call p_prev, previous_span}</li>)
else
Expand All @@ -75,7 +75,7 @@ def pagy_uikit_prev_html(pagy, link)
end

def pagy_uikit_next_html(pagy, link)
next_span = %(<span uk-pagination-next>#{pagy_t('pagy.nav.next')}</span>)
next_span = %(<span uk-pagination-next>#{pagy_t 'pagy.nav.next'}</span>)
if (p_next = pagy.next)
%(<li>#{link.call p_next, next_span}</li>)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/frontend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def pagy_info(pagy, item_name=nil)
def pagy_link_proc(pagy, link_extra='')
p_prev = pagy.prev
p_next = pagy.next
left, right = %(<a href="#{pagy_url_for(PAGE_PLACEHOLDER, pagy)}" #{pagy.vars[:link_extra]} #{link_extra}).split(PAGE_PLACEHOLDER, 2)
left, right = %(<a href="#{pagy_url_for PAGE_PLACEHOLDER, pagy}" #{pagy.vars[:link_extra]} #{link_extra}).split(PAGE_PLACEHOLDER, 2)
lambda do |num, text=num, extra=''|
%(#{left}#{num}#{right}#{ case num
when p_prev then ' rel="prev"'
Expand Down

0 comments on commit 487eb70

Please sign in to comment.