turbo-scroll 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23360c1f88090467e027eea7b95d0e26124eaf84a88a6b61d92ff4383e5c7547
4
- data.tar.gz: 1c530abf7d4c18357db082d3c537ccc11304d9a25b18a38566b9df52762f67c1
3
+ metadata.gz: 795c13de80b15a25b9b37dcd9944855ac52c8b5270b0acfce62a959feddb5bec
4
+ data.tar.gz: 758a95cedc0db75a01c2619bc0eae553bc94afdabd514333c04d547942952cc4
5
5
  SHA512:
6
- metadata.gz: 5655f6dfb6f34dd1811713562de9c19bf0af16acdd3a2e10d1652e9eea90d42f2bc5139eacabf130a91fa06ff7e4a577408c4739426e7059d200deb3494946bb
7
- data.tar.gz: da875aded8920791a105d033078d89c394acc08fb5fc056049256cb3707fd3fc0cd1d9849cb8e09136da2640c7262b1bc2d675384e5731c9d5e0f71f152ced50
6
+ metadata.gz: 8353ba4300980c23841f3ea261b871fe33f26a9766a4b6ba5892c876b8c6c57d5f321a012b5965d40f4b5f5a07292cdb20ac55b278ab455b4b2d998301ab4763
7
+ data.tar.gz: 0d2c3b2866a548b54b2cf79c8cc8b1953f1b4f399b7599f72b2f37e481f331ac63d1db7e6bd2d29b9ed40893cb0af3b2715736063e13d536c387bf549d8bc7cf
data/README.md CHANGED
@@ -3,6 +3,17 @@
3
3
  TurboScroll is a minimalistic gem that provides infinite scrolling for Rails based applications
4
4
  using Turbo.
5
5
 
6
+ Why a new gem? Leveraging Turbo we can build a very small and efficient implementation
7
+ for infinite page scrolling without extra dependencies.
8
+
9
+ It's made to be independent from your choice of pagination.
10
+ You can use the [next-pageable](https://github.com/allcrux/next-pageable) gem, which
11
+ is another minimalistic gem for very basic paging leveraging Rails concerns, to just
12
+ provide the functionality you need for infinite scrolling and avoiding a count query
13
+ on each page request (Your main page might still do a count query but you won't
14
+ be repeating them when requesting next page data behind the scenes.)
15
+
16
+
6
17
  Underlying it depends on ViewComponent and Slim but these are not forced upon the user.
7
18
 
8
19
  ## Usage
@@ -12,6 +23,8 @@ Underlying it depends on ViewComponent and Slim but these are not forced upon th
12
23
  Make sure your index action responds both to html and turbo_stream
13
24
 
14
25
  ```
26
+ @articles = Article.scoped.page(params[:page]) # next-pageable
27
+
15
28
  respond_to do |format|
16
29
  format.html
17
30
  format.turbo_stream
@@ -27,14 +40,21 @@ At the bottom of your page, add the infinite scrolling loader
27
40
  by calling the `turbo_scroll_loader` helper and passing the next page index
28
41
  if a next page is present.
29
42
 
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.
43
+ This gem currently assumes that the page parameter is called `page`, so in
44
+ your controller make sure you use that parameter for selecting
45
+ the records for a given page.
32
46
 
33
- #### Slim Example
47
+ When the loader component becomes visible, it will do 2 things
48
+
49
+ - append the next page to the #infinite dom id
50
+ - update the loader to load the next page (when present)
34
51
 
52
+ #### Slim Example
35
53
 
36
54
  ```
37
55
  #infinite
56
+ / render your page fragment here in whatever structure you desire
57
+ / and extract it into a partial or a component to avoid repition, if desired.
38
58
  - @articles.each do |article|
39
59
  = article
40
60
 
@@ -49,15 +69,63 @@ Your turbo_stream response can use the `turbo_scroll_update` helper to
49
69
  append the next page content and update the current loader with a
50
70
  loader for the next page.
51
71
 
52
- When using the [next_pageable](https://github.com/allcrux/next_pageable) gem
72
+ When using the [next-pageable](https://github.com/allcrux/next-pageable) gem
53
73
  the next_page_index is already present on the collection when a next page exists.
54
74
 
55
75
  ```
56
76
  = turbo_scroll_update page: @articles.next_page_index
77
+ / render your page fragment here in whatever structure you desire
78
+ / and extract it into a partial or a component to avoid repition, if desired.
57
79
  - @articles.each do |article|
58
80
  = article
59
81
  ```
60
82
 
83
+ ### An HTML table alternative for table layouts using CSS grids
84
+
85
+ As HTML is pretty picky on the tags allowed inside 'table', 'tr', 'td', etc you
86
+ can consider using CSS grid as an alternative.
87
+
88
+ ```
89
+ .articles-table {
90
+ display: grid;
91
+ grid-template-columns: minmax(0, 2fr) minmax(0, 2fr) minmax(0, 8fr) minmax(0, 2fr) minmax(0, 1fr) 3em;
92
+ max-width: 100%;
93
+ width: 100%;
94
+ }
95
+
96
+ .articles-table .col {
97
+ height: 2.75rem;
98
+ display: flex;
99
+ align-items: center;
100
+ width: 100%;
101
+ padding-left: 0.5rem;
102
+ padding-right: 0.5rem;
103
+ }
104
+
105
+ .articles-table .col-striped:nth-child(12n+7),
106
+ .articles-table .col-striped:nth-child(12n+8),
107
+ .articles-table .col-striped:nth-child(12n+9),
108
+ .articles-table .col-striped:nth-child(12n+10),
109
+ .articles-table .col-striped:nth-child(12n+11),
110
+ .articles-table .col-striped:nth-child(12n+12) {
111
+ background-color: #EEEEEE;
112
+ }
113
+ ```
114
+
115
+ which would go hand in hand with this partial for a record row
116
+
117
+ ```
118
+ .col.col-striped = article.articlenumber
119
+ .col.col-striped = article.barcode
120
+ .col.col-striped = article.description
121
+ .col.col-striped = article.supplier
122
+ .col.col-striped.align-right = article.price.print
123
+ .col.col-striped.align-right
124
+ a.btn.btn-sm.btn-secondary href=edit_article_path(article)
125
+ i.bi.bi-pencil
126
+ ```
127
+
128
+
61
129
  ### Using a different DOM ID
62
130
 
63
131
  In case you want or need to use a different DOM ID you
@@ -84,26 +152,15 @@ index.turbo_stream.slim
84
152
  = article
85
153
  ```
86
154
 
87
-
88
-
89
- ### index.
90
-
91
155
  ## Installation
92
- Add this line to your application's Gemfile:
93
156
 
94
- ```ruby
95
- gem "turbo-scroll"
96
- ```
157
+ Install the gem and add to the application's Gemfile by executing:
97
158
 
98
- And then execute:
99
- ```bash
100
- $ bundle
101
- ```
159
+ $ bundle add turbo-scroll
102
160
 
103
- Or install it yourself as:
104
- ```bash
105
- $ gem install turbo-scroll
106
- ```
161
+ If bundler is not being used to manage dependencies, install the gem by executing:
162
+
163
+ $ gem install turbo-scroll
107
164
 
108
165
  ## License
109
166
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
1
  require "bundler/setup"
2
2
 
3
3
  require "bundler/gem_tasks"
4
+
5
+ task default: %i[rubocop]
@@ -0,0 +1,3 @@
1
+ ---
2
+ en:
3
+ click_here: Click <a href="%{next_page_path}">here<a> to force load the next page.
@@ -0,0 +1,3 @@
1
+ ---
2
+ fr:
3
+ click_here: Cliquez <a href="%{next_page_path}">ici<a> pour charger la page suivante.
@@ -0,0 +1,3 @@
1
+ ---
2
+ nl:
3
+ click_here: Klik <a href="%{next_page_path}">hier<a> voor de volgende pagina.
@@ -0,0 +1,3 @@
1
+ ---
2
+ ro:
3
+ click_here: Faceți clic <a href="%{next_page_path}">aici<a> pentru a încărca pagina următoare.
@@ -0,0 +1,3 @@
1
+ ---
2
+ fr:
3
+ click_here: Nhấp vào <a href="%{next_page_path}">đây<a> để tải trang tiếp theo.
@@ -1,3 +1,4 @@
1
1
  = turbo_frame_tag :infinite_loader, src: next_page_stream_path, loading: "lazy", target: "_top"
2
2
  .page-loading
3
- p ==t(".click_here", next_page_path: next_page_path)
3
+ p == I18n.t(".click_here", next_page_path: next_page_path)
4
+ = render(TurboScroll::SpinLoader.new(loading_indicator: loading_indicator))
@@ -5,10 +5,11 @@ require "turbo-rails"
5
5
  class TurboScroll::Loader < ViewComponent::Base
6
6
  include Turbo::FramesHelper
7
7
 
8
- attr_reader :page
8
+ attr_reader :page, :loading_indicator
9
9
 
10
- def initialize(page:)
10
+ def initialize(page:, loading_indicator: true)
11
11
  @page = page
12
+ @loading_indicator = loading_indicator
12
13
  end
13
14
 
14
15
  def query_params
@@ -28,4 +29,3 @@ class TurboScroll::Loader < ViewComponent::Base
28
29
  page
29
30
  end
30
31
  end
31
-
@@ -1,6 +1,9 @@
1
1
  .page-loading {
2
2
  height: 15.5em;
3
3
  padding-top: 4em;
4
+ display: flex;
5
+ justify-content: center;
6
+ align-items: center;
4
7
  }
5
8
 
6
9
  .page-loading p {
@@ -3,11 +3,13 @@ module TurboScroll
3
3
  initializer "turbo-scrolls.load_components" do
4
4
  require_relative "update"
5
5
  require_relative "loader"
6
+ require_relative "spin_loader"
6
7
  end
7
- initializer "turbo-scrolls.view_helpers" do
8
+ initializer "turbo-scrolls.view_helpers" do |app|
8
9
  ActiveSupport.on_load(:action_view) do
9
10
  include TurboScroll::ViewHelpers
10
11
  end
12
+ app.config.i18n.load_path += Dir[File.expand_path(File.join(File.dirname(__FILE__), '../locales', '*.yml')).to_s]
11
13
  end
12
14
  end
13
15
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "turbo-rails"
4
+
5
+ class TurboScroll::SpinLoader < ViewComponent::Base
6
+ attr_reader :loading_indicator
7
+
8
+ def initialize(loading_indicator: true)
9
+ @loading_indicator = loading_indicator
10
+ end
11
+
12
+ def render?
13
+ loading_indicator
14
+ end
15
+ end
@@ -0,0 +1,50 @@
1
+ css:
2
+ .loader {
3
+ display: inline-block;
4
+ position: relative;
5
+ width: 45px;
6
+ height: 45px;
7
+ margin: auto;
8
+ }
9
+ .loader div {
10
+ box-sizing: border-box;
11
+ display: block;
12
+ position: absolute;
13
+ width: 32px;
14
+ height: 32px;
15
+ margin: 8px 0px;
16
+ border: 3px solid #00afd4;
17
+ border-radius: 50%;
18
+ animation: loader 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
19
+ border-color: #00afd4 transparent transparent transparent;
20
+ }
21
+ .loader div:nth-child(1) {
22
+ animation-delay: -0.45s;
23
+ }
24
+ .loader div:nth-child(2) {
25
+ animation-delay: -0.3s;
26
+ }
27
+ .loader div:nth-child(3) {
28
+ animation-delay: -0.15s;
29
+ }
30
+ .page-loading {
31
+ display: flex;
32
+ flex-direction: column;
33
+ justify-content: center;
34
+ align-items: center;
35
+ }
36
+
37
+ @keyframes loader {
38
+ 0% {
39
+ transform: rotate(0deg);
40
+ }
41
+ 100% {
42
+ transform: rotate(360deg);
43
+ }
44
+ }
45
+
46
+ .loader
47
+ div
48
+ div
49
+ div
50
+ div
@@ -2,4 +2,4 @@
2
2
  = content
3
3
 
4
4
  = turbo_stream.replace(:infinite_loader)
5
- = render(TurboScroll::Loader.new(page: page))
5
+ = render(TurboScroll::Loader.new(page: page, loading_indicator: loading_indicator))
@@ -6,12 +6,11 @@ class TurboScroll::Update < ViewComponent::Base
6
6
  include Turbo::FramesHelper
7
7
  include Turbo::StreamsHelper
8
8
 
9
- attr_reader :page
10
- attr_reader :infinite_dom_id
9
+ attr_reader :page, :infinite_dom_id, :loading_indicator
11
10
 
12
- def initialize(page:, infinite_dom_id: :infinite)
11
+ def initialize(page:, loading_indicator:, infinite_dom_id: :infinite)
13
12
  @page = page
14
13
  @infinite_dom_id = infinite_dom_id
14
+ @loading_indicator = loading_indicator
15
15
  end
16
16
  end
17
-
@@ -1,3 +1,3 @@
1
1
  module TurboScroll
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/turbo-scroll.rb CHANGED
@@ -3,12 +3,19 @@ require "turbo-scroll/railtie" if defined?(Rails::Railtie)
3
3
 
4
4
  module TurboScroll
5
5
  module ViewHelpers
6
- def turbo_scroll_loader(page:)
7
- render(TurboScroll::Loader.new(page: page))
6
+ def turbo_scroll_loader(page:, loading_indicator: true)
7
+ render(TurboScroll::Loader.new(page: page, loading_indicator: loading_indicator))
8
8
  end
9
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)
10
+ def turbo_scroll_update(page:, infinite_dom_id: :infinite, loading_indicator: true, &block)
11
+ render(
12
+ TurboScroll::Update.new(
13
+ page: page,
14
+ infinite_dom_id: infinite_dom_id,
15
+ loading_indicator: loading_indicator
16
+ ),
17
+ &block
18
+ )
12
19
  end
13
20
  end
14
21
  end
metadata CHANGED
@@ -1,72 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo-scroll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koen handekyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-05 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: turbo-rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: view_component
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: slim
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '4'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '4'
69
- description: Description of TurboScroll.
69
+ description: TurboScroll is a minimalistic gem that provides infinite scrolling for
70
+ Rails based applications using Turbo.
70
71
  email:
71
72
  - koen@handekyn.com
72
73
  executables: []
@@ -76,12 +77,19 @@ files:
76
77
  - MIT-LICENSE
77
78
  - README.md
78
79
  - Rakefile
80
+ - lib/locales/en.yml
81
+ - lib/locales/fr.yml
82
+ - lib/locales/nl.yml
83
+ - lib/locales/ro.yml
84
+ - lib/locales/vn.yml
79
85
  - lib/tasks/turbo_scroll_tasks.rake
80
86
  - lib/turbo-scroll.rb
81
87
  - lib/turbo-scroll/loader.html.slim
82
88
  - lib/turbo-scroll/loader.rb
83
89
  - lib/turbo-scroll/loader.scss
84
90
  - lib/turbo-scroll/railtie.rb
91
+ - lib/turbo-scroll/spin_loader.rb
92
+ - lib/turbo-scroll/spin_loader.slim
85
93
  - lib/turbo-scroll/update.html.slim
86
94
  - lib/turbo-scroll/update.rb
87
95
  - lib/turbo-scroll/version.rb
@@ -93,6 +101,7 @@ metadata:
93
101
  homepage_uri: https://github.com/allcrux/turbo-scroll
94
102
  source_code_uri: https://github.com/allcrux/turbo-scroll
95
103
  changelog_uri: https://github.com/allcrux/turbo-scroll/blob/main/CHANGELOG.md
104
+ rubygems_mfa_required: 'true'
96
105
  post_install_message:
97
106
  rdoc_options: []
98
107
  require_paths:
@@ -111,5 +120,5 @@ requirements: []
111
120
  rubygems_version: 3.3.7
112
121
  signing_key:
113
122
  specification_version: 4
114
- summary: Summary of TurboScroll.
123
+ summary: Modern infinite page scrolling for Rails.
115
124
  test_files: []