turbo-scroll 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +110 -0
- data/Rakefile +3 -0
- data/lib/tasks/turbo_scroll_tasks.rake +4 -0
- data/lib/turbo-scroll/loader.html.slim +3 -0
- data/lib/turbo-scroll/loader.rb +31 -0
- data/lib/turbo-scroll/loader.scss +10 -0
- data/lib/turbo-scroll/railtie.rb +13 -0
- data/lib/turbo-scroll/update.html.slim +5 -0
- data/lib/turbo-scroll/update.rb +17 -0
- data/lib/turbo-scroll/version.rb +3 -0
- data/lib/turbo-scroll.rb +14 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 23360c1f88090467e027eea7b95d0e26124eaf84a88a6b61d92ff4383e5c7547
|
4
|
+
data.tar.gz: 1c530abf7d4c18357db082d3c537ccc11304d9a25b18a38566b9df52762f67c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5655f6dfb6f34dd1811713562de9c19bf0af16acdd3a2e10d1652e9eea90d42f2bc5139eacabf130a91fa06ff7e4a577408c4739426e7059d200deb3494946bb
|
7
|
+
data.tar.gz: da875aded8920791a105d033078d89c394acc08fb5fc056049256cb3707fd3fc0cd1d9849cb8e09136da2640c7262b1bc2d675384e5731c9d5e0f71f152ced50
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2022 Koen handekyn
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# TurboScroll
|
2
|
+
|
3
|
+
TurboScroll is a minimalistic gem that provides infinite scrolling for Rails based applications
|
4
|
+
using Turbo.
|
5
|
+
|
6
|
+
Underlying it depends on ViewComponent and Slim but these are not forced upon the user.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
### Controller
|
11
|
+
|
12
|
+
Make sure your index action responds both to html and turbo_stream
|
13
|
+
|
14
|
+
```
|
15
|
+
respond_to do |format|
|
16
|
+
format.html
|
17
|
+
format.turbo_stream
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
### index.html.erb|slim
|
22
|
+
|
23
|
+
In your index page, make sure you have a DOM element with ID `infinite`
|
24
|
+
and render inside of it your initial page content.
|
25
|
+
|
26
|
+
At the bottom of your page, add the infinite scrolling loader
|
27
|
+
by calling the `turbo_scroll_loader` helper and passing the next page index
|
28
|
+
if a next page is present.
|
29
|
+
|
30
|
+
You could use the [next_pageable](https://github.com/allcrux/next_pageable) gem
|
31
|
+
but one can also use any other pagination gem of choice.
|
32
|
+
|
33
|
+
#### Slim Example
|
34
|
+
|
35
|
+
|
36
|
+
```
|
37
|
+
#infinite
|
38
|
+
- @articles.each do |article|
|
39
|
+
= article
|
40
|
+
|
41
|
+
= turbo_scroll_loader(page: @articles.next_page_index)
|
42
|
+
```
|
43
|
+
|
44
|
+
If you want to use a different ID, you'll have to pass it on in turbo_stream response.
|
45
|
+
|
46
|
+
### index.turbo_stream.erb|slim
|
47
|
+
|
48
|
+
Your turbo_stream response can use the `turbo_scroll_update` helper to
|
49
|
+
append the next page content and update the current loader with a
|
50
|
+
loader for the next page.
|
51
|
+
|
52
|
+
When using the [next_pageable](https://github.com/allcrux/next_pageable) gem
|
53
|
+
the next_page_index is already present on the collection when a next page exists.
|
54
|
+
|
55
|
+
```
|
56
|
+
= turbo_scroll_update page: @articles.next_page_index
|
57
|
+
- @articles.each do |article|
|
58
|
+
= article
|
59
|
+
```
|
60
|
+
|
61
|
+
### Using a different DOM ID
|
62
|
+
|
63
|
+
In case you want or need to use a different DOM ID you
|
64
|
+
can pass it on as an extra param to the `turbo_scroll_update` helper.
|
65
|
+
|
66
|
+
The below example illustrates this for the case where your
|
67
|
+
DOM ID is `#scroll`.
|
68
|
+
|
69
|
+
index.html.slim
|
70
|
+
|
71
|
+
```
|
72
|
+
#scroll
|
73
|
+
- @articles.each do |article|
|
74
|
+
= article
|
75
|
+
|
76
|
+
= turbo_scroll_loader(page: @articles.next_page_index)
|
77
|
+
```
|
78
|
+
|
79
|
+
index.turbo_stream.slim
|
80
|
+
|
81
|
+
```
|
82
|
+
= turbo_scroll_update page: @articles.next_page_index, infinite_dom_id: :scroll
|
83
|
+
- @articles.each do |article|
|
84
|
+
= article
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
### index.
|
90
|
+
|
91
|
+
## Installation
|
92
|
+
Add this line to your application's Gemfile:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
gem "turbo-scroll"
|
96
|
+
```
|
97
|
+
|
98
|
+
And then execute:
|
99
|
+
```bash
|
100
|
+
$ bundle
|
101
|
+
```
|
102
|
+
|
103
|
+
Or install it yourself as:
|
104
|
+
```bash
|
105
|
+
$ gem install turbo-scroll
|
106
|
+
```
|
107
|
+
|
108
|
+
## License
|
109
|
+
|
110
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "turbo-rails"
|
4
|
+
|
5
|
+
class TurboScroll::Loader < ViewComponent::Base
|
6
|
+
include Turbo::FramesHelper
|
7
|
+
|
8
|
+
attr_reader :page
|
9
|
+
|
10
|
+
def initialize(page:)
|
11
|
+
@page = page
|
12
|
+
end
|
13
|
+
|
14
|
+
def query_params
|
15
|
+
@query_params ||=
|
16
|
+
request.query_parameters.except(:page, :raw, :format)
|
17
|
+
end
|
18
|
+
|
19
|
+
def next_page_path
|
20
|
+
url_for(page: page, **query_params)
|
21
|
+
end
|
22
|
+
|
23
|
+
def next_page_stream_path
|
24
|
+
url_for(format: :turbo_stream, page: page, **query_params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def render?
|
28
|
+
page
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module TurboScroll
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
initializer "turbo-scrolls.load_components" do
|
4
|
+
require_relative "update"
|
5
|
+
require_relative "loader"
|
6
|
+
end
|
7
|
+
initializer "turbo-scrolls.view_helpers" do
|
8
|
+
ActiveSupport.on_load(:action_view) do
|
9
|
+
include TurboScroll::ViewHelpers
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "turbo-rails"
|
4
|
+
|
5
|
+
class TurboScroll::Update < ViewComponent::Base
|
6
|
+
include Turbo::FramesHelper
|
7
|
+
include Turbo::StreamsHelper
|
8
|
+
|
9
|
+
attr_reader :page
|
10
|
+
attr_reader :infinite_dom_id
|
11
|
+
|
12
|
+
def initialize(page:, infinite_dom_id: :infinite)
|
13
|
+
@page = page
|
14
|
+
@infinite_dom_id = infinite_dom_id
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
data/lib/turbo-scroll.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "turbo-scroll/version"
|
2
|
+
require "turbo-scroll/railtie" if defined?(Rails::Railtie)
|
3
|
+
|
4
|
+
module TurboScroll
|
5
|
+
module ViewHelpers
|
6
|
+
def turbo_scroll_loader(page:)
|
7
|
+
render(TurboScroll::Loader.new(page: page))
|
8
|
+
end
|
9
|
+
|
10
|
+
def turbo_scroll_update(page:, infinite_dom_id: :infinite, &block)
|
11
|
+
render(TurboScroll::Update.new(page: page, infinite_dom_id: infinite_dom_id), &block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: turbo-scroll
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Koen handekyn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: turbo-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: view_component
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: slim
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4'
|
69
|
+
description: Description of TurboScroll.
|
70
|
+
email:
|
71
|
+
- koen@handekyn.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- MIT-LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/tasks/turbo_scroll_tasks.rake
|
80
|
+
- lib/turbo-scroll.rb
|
81
|
+
- lib/turbo-scroll/loader.html.slim
|
82
|
+
- lib/turbo-scroll/loader.rb
|
83
|
+
- lib/turbo-scroll/loader.scss
|
84
|
+
- lib/turbo-scroll/railtie.rb
|
85
|
+
- lib/turbo-scroll/update.html.slim
|
86
|
+
- lib/turbo-scroll/update.rb
|
87
|
+
- lib/turbo-scroll/version.rb
|
88
|
+
homepage: https://github.com/allcrux/turbo-scroll
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata:
|
92
|
+
allowed_push_host: https://rubygems.org
|
93
|
+
homepage_uri: https://github.com/allcrux/turbo-scroll
|
94
|
+
source_code_uri: https://github.com/allcrux/turbo-scroll
|
95
|
+
changelog_uri: https://github.com/allcrux/turbo-scroll/blob/main/CHANGELOG.md
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubygems_version: 3.3.7
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Summary of TurboScroll.
|
115
|
+
test_files: []
|