![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
TurboScroll is a minimalistic gem that provides infinite scrolling for Rails based applications using Turbo.
Why a new gem? Leveraging Turbo we can build a very small and efficient implementation for infinite page scrolling without extra dependencies.
It's made to be independent from your choice of pagination. You can use the next-pageable gem, which is another minimalistic gem for very basic paging leveraging Rails concerns, to just provide the functionality you need for infinite scrolling and avoiding a count query on each page request (Your main page might still do a count query but you won't be repeating them when requesting next page data behind the scenes.)
Underlying it depends on ViewComponent and Slim but these are not forced upon the user.
Make sure your index action responds both to html and turbo_stream
@articles = Article.scoped.paginate(params[:page]) # next-pageable
respond_to do |format|
format.html
format.turbo_stream
end
The simplest is to use the turbo_scroll_auto
helper and
nest inside your initial infinite content. This will wrap the
content with an element with id #infinite that will be
used to append new content to for infinite scrolling.
= turbo_scroll_auto page: @articles.next_page_index
- @articles.each do |article|
= article
Alternatively, in your index page, make sure you have a DOM element with ID infinite
and render inside of it your initial page content.
At the bottom of your page, add the infinite scrolling loader
by calling the turbo_scroll_auto
helper and passing the next page index
if a next page is present.
#infinite
- @articles.each do |article|
= article
= turbo_scroll_auto page: @articles.next_page_index
This gem currently assumes that the page parameter is called page
, so in
your controller make sure you use that parameter for selecting
the records for a given page.
When the loader component becomes visible, it will do 2 things
If you want to use a different ID, you'll have to pass it on in turbo_stream response.
Your turbo_stream response can use the turbo_scroll_auto_stream
helper to
append the next page content and update the current loader with a
loader for the next page.
When using the next-pageable gem the next_page_index is already present on the collection when a next page exists.
= turbo_scroll_auto_stream page: @articles.next_page_index
- @articles.each do |article|
= article
= turbo_scroll_more page: @articles.next_page_index
= render(Articles::Row.with_collection(@articles))
Your turbo_stream response can use the turbo_scroll_more_stream
helper to
append the next page content and update the current more loader with a
more loader for the next page.
articles\index.turbo_stream.slim
= turbo_scroll_more_stream page: @articles.next_page_index
= render Articles::Row.with_collection(@articles)
As HTML is pretty picky on the tags allowed inside 'table', 'tr', 'td', etc you can consider using CSS grid as an alternative.
.article.row {
display: grid;
grid-template-columns: minmax(0, 2fr) minmax(0, 2fr) minmax(0, 8fr) minmax(0, 2fr) minmax(0, 1fr) 3em;
max-width: 100%;
width: 100%;
}
.article.row .col {
height: 2.75rem;
display: flex;
align-items: center;
width: 100%;
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.article.row .col-head {
font-weight: bolder;
}
.article.row .col-filter {
padding-left: 0rem;
padding-right: 0rem;
}
.article.row .align-right {
justify-content: right;
}
.article.row.striped:nth-child(2n+1) {
background-color: #EEEEEE;
}
which would go hand in hand with this partial for a record row
.article.row.striped
.col = article.articlenumber
.col = article.barcode
.col = article.description
.col = article.supplier
.col.align-right = article.price.print
.col.align-right
a.btn.btn-sm.btn-secondary href=edit_article_path(article)
i.bi.bi-pencil
In case you want or need to use a different DOM ID you
can pass it on as an extra param to the turbo_scroll_auto_stream
helper.
The below example illustrates this for the case where your
DOM ID is #scroll
.
index.html.slim
= turbo_scroll_auto page: @articles.next_page_index, id: :scroll
- @articles.each do |article|
= article
index.turbo_stream.slim
= turbo_scroll_auto_stream page: @articles.next_page_index, infinite_dom_id: :scroll
- @articles.each do |article|
= article
Install the gem and add to the application's Gemfile by executing:
$ bundle add turbo-scroll
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install turbo-scroll
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that turbo-scroll demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.