futurism 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +41 -5
- data/lib/futurism.rb +4 -0
- data/lib/futurism/channel.rb +6 -4
- data/lib/futurism/helpers.rb +27 -3
- data/lib/futurism/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 490e77869b91685fe4335badd8006842871eaba8df9cab7998038c531f11e607
|
4
|
+
data.tar.gz: 9bc29e824f7a1e8298942842d543e19eef1e2cf6e22d1b058109675b2d38ad15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55449d0339a7731cb8725459aca47b66ac8039600c4e8e24a5dbf3f7c9986466f949fc91042f1882dbc2332a61009f3cabbd3c76dda98d1a07bd7a4c9abdb111
|
7
|
+
data.tar.gz: 315e1274d56647b26bd0a703759160f93fa75e8d302bf5cc6304835e74fabc727e68395cba3554bf7a2fa5174acfb11c481fdbe536df0af34870560a1aa54b54
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# Futurism
|
2
2
|
[](https://twitter.com/julian_rubisch)
|
3
3
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
4
|
-
[](#contributors-)
|
5
5
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
6
6
|
Lazy-load Rails partials via CableReady
|
7
7
|
|
8
|
+
:rotating_light: *Futurism is still in pre-1.0 state. As much as I hope to keep the API backwards-compatible, I cannot guarantee it* :rotating_light:
|
9
|
+
|
8
10
|
## Facts
|
9
11
|
- only one dependency: CableReady
|
10
12
|
- bundle size (without CableReady) is around [~1.04kB](https://bundlephobia.com/result?p=@minthesize/futurism@0.1.3)
|
@@ -23,7 +25,9 @@ Lazy-load Rails partials via CableReady
|
|
23
25
|
with a helper in your template
|
24
26
|
|
25
27
|
```erb
|
26
|
-
<%= futurize @posts %>
|
28
|
+
<%= futurize @posts, extends: :div do %>
|
29
|
+
<!-- placeholder -->
|
30
|
+
<% end %>
|
27
31
|
```
|
28
32
|
|
29
33
|
custom `<futurism-element>`s (in the form of a `<div>` or a `<tr is="futurism-table-row">` are rendered. Those custom elements have an `IntersectionObserver` attached that will send a signed global id to an ActionCable channel (`FuturismChannel`) which will then replace the placeholders with the actual resource partial.
|
@@ -40,7 +44,21 @@ You can pass the placeholder as a block:
|
|
40
44
|
|
41
45
|

|
42
46
|
|
43
|
-
|
47
|
+
## API
|
48
|
+
|
49
|
+
Currently there are two ways to call `futurize`, designed to wrap `render`'s behavior:
|
50
|
+
|
51
|
+
### Resource
|
52
|
+
|
53
|
+
You can pass a single `ActiveRecord` or an `ActiveRecord::Relation` to `futurize`, just as you would call `render`:
|
54
|
+
|
55
|
+
```erb
|
56
|
+
<%= futurize @posts, extends: :tr do %>
|
57
|
+
<td class="placeholder"></td>
|
58
|
+
<% end %>
|
59
|
+
```
|
60
|
+
|
61
|
+
#### Partial Path
|
44
62
|
|
45
63
|
Remember that you can override the partial path in you models, like so:
|
46
64
|
|
@@ -54,6 +72,23 @@ end
|
|
54
72
|
|
55
73
|
That way you get maximal flexibility when just specifying a single resource.
|
56
74
|
|
75
|
+
### Explicit Partial
|
76
|
+
|
77
|
+
Call `futurize` with a `partial` keyword:
|
78
|
+
|
79
|
+
```erb
|
80
|
+
<%= futurize partial: "items/card", locals: {card: @card}, extends: :div %>
|
81
|
+
<div class="spinner"></div>
|
82
|
+
<% end %>
|
83
|
+
```
|
84
|
+
|
85
|
+
You can also use the shorthand syntax:
|
86
|
+
|
87
|
+
```erb
|
88
|
+
<%= futurize "items/card", card: @card, extends: :div %>
|
89
|
+
<div class="spinner"></div>
|
90
|
+
<% end %>
|
91
|
+
|
57
92
|
## Installation
|
58
93
|
Add this line to your application's Gemfile:
|
59
94
|
|
@@ -72,13 +107,13 @@ To copy over the javascript files to your application, run
|
|
72
107
|
$ bin/rails futurism:install
|
73
108
|
```
|
74
109
|
|
75
|
-
|
110
|
+
**! Note that the installer will run `yarn add @minthesize/futurism` for you !**
|
76
111
|
|
77
112
|
### Manual Installation
|
78
113
|
After `bundle`, install the Javascript library:
|
79
114
|
|
80
115
|
```bash
|
81
|
-
$ bin/yarn
|
116
|
+
$ bin/yarn add @minthesize/futurism
|
82
117
|
```
|
83
118
|
|
84
119
|
In your `app/javascript/channels/index.js`, add the following
|
@@ -111,6 +146,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
111
146
|
<td align="center"><a href="https://ParamagicDev.github.io/portfolio"><img src="https://avatars2.githubusercontent.com/u/26425882?v=4" width="100px;" alt=""/><br /><sub><b>Konnor Rogers</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=ParamagicDev" title="Code">💻</a></td>
|
112
147
|
<td align="center"><a href="https://www.andrewm.codes"><img src="https://avatars1.githubusercontent.com/u/18423853?v=4" width="100px;" alt=""/><br /><sub><b>Andrew Mason</b></sub></a><br /><a href="#maintenance-andrewmcodes" title="Maintenance">🚧</a></td>
|
113
148
|
<td align="center"><a href="http://gorails.com"><img src="https://avatars1.githubusercontent.com/u/67093?v=4" width="100px;" alt=""/><br /><sub><b>Chris Oliver</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=excid3" title="Code">💻</a> <a href="https://github.com/julianrubisch/futurism/pulls?q=is%3Apr+reviewed-by%3Aexcid3" title="Reviewed Pull Requests">👀</a></td>
|
149
|
+
<td align="center"><a href="https://github.com/leastbad"><img src="https://avatars2.githubusercontent.com/u/38150464?v=4" width="100px;" alt=""/><br /><sub><b>leastbad</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=leastbad" title="Code">💻</a></td>
|
114
150
|
</tr>
|
115
151
|
</table>
|
116
152
|
|
data/lib/futurism.rb
CHANGED
data/lib/futurism/channel.rb
CHANGED
@@ -7,13 +7,15 @@ module Futurism
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def receive(data)
|
10
|
-
resources = data["
|
11
|
-
[
|
10
|
+
resources = data["signed_params"].map { |signed_params|
|
11
|
+
[signed_params, Rails.application.message_verifier("futurism").verify(signed_params)]
|
12
12
|
}
|
13
13
|
|
14
|
-
|
14
|
+
ApplicationController.renderer.instance_variable_set(:@env, connection.env)
|
15
|
+
|
16
|
+
resources.each do |signed_params, resource|
|
15
17
|
cable_ready["Futurism::Channel"].outer_html(
|
16
|
-
selector: "[data-
|
18
|
+
selector: "[data-signed-params='#{signed_params}']",
|
17
19
|
html: ApplicationController.render(resource)
|
18
20
|
)
|
19
21
|
end
|
data/lib/futurism/helpers.rb
CHANGED
@@ -1,15 +1,39 @@
|
|
1
1
|
module Futurism
|
2
2
|
module Helpers
|
3
|
-
def futurize(
|
3
|
+
def futurize(records_or_string = nil, extends:, **options, &block)
|
4
4
|
placeholder = capture(&block)
|
5
|
+
|
6
|
+
if records_or_string.is_a?(ActiveRecord::Base) || records_or_string.is_a?(ActiveRecord::Relation)
|
7
|
+
futurize_active_record(records_or_string, extends: extends, placeholder: placeholder)
|
8
|
+
elsif records_or_string.is_a?(String)
|
9
|
+
futurize_with_options(extends: extends, partial: records_or_string, locals: options, placeholder: placeholder)
|
10
|
+
else
|
11
|
+
futurize_with_options(extends: extends, placeholder: placeholder, **options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def futurize_with_options(extends:, placeholder:, **options)
|
16
|
+
case extends
|
17
|
+
when :tr
|
18
|
+
content_tag :tr, placeholder, data: {signed_params: futurism_signed_params(options)}, is: "futurism-table-row"
|
19
|
+
else
|
20
|
+
content_tag :"futurism-element", placeholder, data: {signed_params: futurism_signed_params(options)}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def futurize_active_record(records, extends:, placeholder:)
|
5
25
|
Array(records).map { |record|
|
6
26
|
case extends
|
7
27
|
when :tr
|
8
|
-
content_tag :tr, placeholder, data: {
|
28
|
+
content_tag :tr, placeholder, data: {signed_params: futurism_signed_params(record)}, is: "futurism-table-row"
|
9
29
|
else
|
10
|
-
content_tag :"futurism-element", placeholder, data: {
|
30
|
+
content_tag :"futurism-element", placeholder, data: {signed_params: futurism_signed_params(record)}
|
11
31
|
end
|
12
32
|
}.join.html_safe
|
13
33
|
end
|
34
|
+
|
35
|
+
def futurism_signed_params(params)
|
36
|
+
Rails.application.message_verifier("futurism").generate(params)
|
37
|
+
end
|
14
38
|
end
|
15
39
|
end
|
data/lib/futurism/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: futurism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Rubisch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.12.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: standardrb
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|