Skip to content

Commit

Permalink
helper tags are strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 10, 2018
1 parent 4788c3c commit cee02c6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/pagy/frontend.rb
Expand Up @@ -10,25 +10,25 @@ module Frontend

# Generic pagination: it returns the html with the series of links to the pages
def pagy_nav(pagy)
tags = []; link = pagy_link_proc(pagy)
tags = ''; link = pagy_link_proc(pagy)

tags << (pagy.prev ? %(<span class="page prev">#{link.call pagy.prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze}</span>)
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev'.freeze)}</span>))
tags << (pagy.prev ? %(<span class="page prev">#{link.call pagy.prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze}</span> )
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev'.freeze)}</span> ))
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
tags << if item.is_a?(Integer); %(<span class="page">#{link.call item}</span>) # page link
elsif item.is_a?(String) ; %(<span class="page active">#{item}</span>) # current page
elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap'.freeze)}</span>) # page gap
tags << if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> ) # page link
elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> ) # current page
elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap'.freeze)}</span> ) # page gap
end
end
tags << (pagy.next ? %(<span class="page next">#{link.call pagy.next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}</span>)
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next'.freeze)}</span>))
%(<nav class="pagination" role="navigation" aria-label="pager">#{tags.join(' '.freeze)}</nav>)
%(<nav class="pagination" role="navigation" aria-label="pager">#{tags}</nav>)
end


# Pagination for bootstrap: it returns the html with the series of links to the pages
def pagy_nav_bootstrap(pagy)
tags = []; link = pagy_link_proc(pagy, 'class="page-link"'.freeze)
tags = ''; link = pagy_link_proc(pagy, 'class="page-link"'.freeze)

tags << (pagy.prev ? %(<li class="page-item prev">#{link.call pagy.prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze}</li>)
: %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev'.freeze)}</a></li>))
Expand All @@ -40,7 +40,7 @@ def pagy_nav_bootstrap(pagy)
end
tags << (pagy.next ? %(<li class="page-item next">#{link.call pagy.next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}</li>)
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next'.freeze)}</a></li>))
%(<nav class="pagination" role="navigation" aria-label="pager"><ul class="pagination">#{tags.join}</ul></nav>)
%(<nav class="pagination" role="navigation" aria-label="pager"><ul class="pagination">#{tags}</ul></nav>)
end


Expand Down Expand Up @@ -79,7 +79,7 @@ def pagy_link_proc(pagy, lx=''.freeze) # "lx" means "link extra"
# define #pagy_t depending on I18N[:gem] and I18n
if I18N[:gem] || I18N[:gem].nil? && defined?(I18n)
I18n.load_path << I18N[:file]
def pagy_t(*a); I18n.t(*a) end
def pagy_t(*a) I18n.t(*a) end
else
# load data from the first locale in the file
I18N_DATA = YAML.load_file(I18N[:file]).first[1].freeze
Expand Down

0 comments on commit cee02c6

Please sign in to comment.