futurism 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -2
- data/lib/futurism/channel.rb~ +20 -16
- data/lib/futurism/helpers.rb +9 -5
- data/lib/futurism/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4790301758ddfdcf0a2e22b4f0f55977cdaf96f64fcef74ba85ccb4f6e7c71c
|
4
|
+
data.tar.gz: 07435fbcfbc75b1846015b319f8dc2056897f8cbb020ff29bf92c48366ea8a9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88a0bb998ccc4192238f8936f80f77cf9b938bd70d141413be1d049265e59eb555d35ad77940ebae8d072b512aa97291a81d57ac1d397bf9c8fc37d54db4e55a
|
7
|
+
data.tar.gz: 6d5e8a2af44e58857f27fb54e6304f903c43901a05e8036f0ba1622e8ed0b8c29fbdbf1fc99e2fdfcbcaf841430ed3f3a7e5bd7d905d891797bbf294d803fe8b
|
data/README.md
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
# Futurism
|
2
2
|
[![Twitter follow](https://img.shields.io/twitter/follow/julian_rubisch?style=social)](https://twitter.com/julian_rubisch)
|
3
3
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
4
|
-
[![All Contributors](https://img.shields.io/badge/all_contributors-
|
4
|
+
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)
|
5
5
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
6
6
|
Lazy-load Rails partials via CableReady
|
7
7
|
|
8
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
9
|
|
10
|
+
<img src="https://user-images.githubusercontent.com/4352208/88374198-9e6f3500-cd99-11ea-804b-0216ed320eff.jpg" alt="birmingham-museums-trust-GrvC6MI-z4w-unsplash" width="50%" align="center"/>
|
11
|
+
<span>Photo by <a href="https://unsplash.com/@birminghammuseumstrust?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Birmingham Museums Trust</a> on <a href="https://unsplash.com/s/photos/futurism?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a></span>
|
12
|
+
|
10
13
|
## Facts
|
11
14
|
- only one dependency: CableReady
|
12
15
|
- bundle size (without CableReady) is around [~1.04kB](https://bundlephobia.com/result?p=@minthesize/futurism@0.1.3)
|
@@ -90,6 +93,24 @@ You can also use the shorthand syntax:
|
|
90
93
|
<% end %>
|
91
94
|
```
|
92
95
|
|
96
|
+
### HTML Options
|
97
|
+
|
98
|
+
You can pass a hash of attribute/value pairs which will be mixed into the HTML markup for the placeholder element. This is important for layouts that require elements to have dimensionality. For example, many scripts calculate size based on element height and width. This option ensures that your elements have integrity, even if they are gone before you see them.
|
99
|
+
|
100
|
+
```erb
|
101
|
+
<%= futurize @posts, extends: :tr, html_options: {style: "width: 50px; height: 50px;"} do %>
|
102
|
+
<td class="placeholder"></td>
|
103
|
+
<% end %>
|
104
|
+
```
|
105
|
+
|
106
|
+
This will output the following:
|
107
|
+
|
108
|
+
```html
|
109
|
+
<tr style="width: 50px; height: 50px;">
|
110
|
+
<td class="placeholder"></td>
|
111
|
+
</tr>
|
112
|
+
```
|
113
|
+
|
93
114
|
#### Collections
|
94
115
|
|
95
116
|
Collection rendering is also possible:
|
@@ -100,6 +121,10 @@ Collection rendering is also possible:
|
|
100
121
|
<% end %>
|
101
122
|
```
|
102
123
|
|
124
|
+
## Events
|
125
|
+
|
126
|
+
Once your futurize element has been rendered, the `futurize:appeared` custom event will be called.
|
127
|
+
|
103
128
|
## Installation
|
104
129
|
Add this line to your application's Gemfile:
|
105
130
|
|
@@ -130,7 +155,7 @@ $ bin/yarn add @minthesize/futurism
|
|
130
155
|
In your `app/javascript/channels/index.js`, add the following
|
131
156
|
|
132
157
|
```js
|
133
|
-
import * as Futurism
|
158
|
+
import * as Futurism from '@minthesize/futurism''
|
134
159
|
|
135
160
|
import consumer from './consumer'
|
136
161
|
|
@@ -158,6 +183,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
158
183
|
<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>
|
159
184
|
<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>
|
160
185
|
<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>
|
186
|
+
<td align="center"><a href="http://code.digimonkey.com"><img src="https://avatars0.githubusercontent.com/u/74207?v=4" width="100px;" alt=""/><br /><sub><b>M. E. Patterson</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/issues?q=author%3Amepatterson" title="Bug reports">🐛</a></td>
|
187
|
+
</tr>
|
188
|
+
<tr>
|
189
|
+
<td align="center"><a href="http://fractaledmind.com"><img src="https://avatars3.githubusercontent.com/u/5077225?v=4" width="100px;" alt=""/><br /><sub><b>Stephen Margheim</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=fractaledmind" title="Code">💻</a></td>
|
161
190
|
</tr>
|
162
191
|
</table>
|
163
192
|
|
data/lib/futurism/channel.rb~
CHANGED
@@ -1,22 +1,26 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Futurism
|
2
|
+
class Channel < ActionCable::Channel::Base
|
3
|
+
include CableReady::Broadcaster
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def subscribed
|
6
|
+
stream_from "Futurism::Channel"
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def receive(data)
|
10
|
+
resources = data["signed_params"].map { |signed_params|
|
11
|
+
[signed_params, Rails.application.message_verifier("futurism").verify(signed_params)]
|
12
|
+
}
|
12
13
|
|
13
|
-
|
14
|
-
cable_ready["FuturismChannel"].outer_html(
|
15
|
-
selector: "[data-sgid='#{sgid}']",
|
16
|
-
html: ApplicationController.render(resource)
|
17
|
-
)
|
18
|
-
end
|
14
|
+
ApplicationController.renderer.instance_variable_set(:@env, connection.env)
|
19
15
|
|
20
|
-
|
16
|
+
resources.each do |signed_params, resource|
|
17
|
+
cable_ready["Futurism::Channel"].outer_html(
|
18
|
+
selector: "[data-signed-params='#{signed_params}']",
|
19
|
+
html: ApplicationController.render(resource)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
cable_ready.broadcast
|
24
|
+
end
|
21
25
|
end
|
22
26
|
end
|
data/lib/futurism/helpers.rb
CHANGED
@@ -4,7 +4,7 @@ module Futurism
|
|
4
4
|
placeholder = capture(&block)
|
5
5
|
|
6
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)
|
7
|
+
futurize_active_record(records_or_string, extends: extends, placeholder: placeholder, **options)
|
8
8
|
elsif records_or_string.is_a?(String)
|
9
9
|
futurize_with_options(extends: extends, partial: records_or_string, locals: options, placeholder: placeholder)
|
10
10
|
else
|
@@ -24,18 +24,22 @@ module Futurism
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def futurize_active_record(records, extends:, placeholder
|
27
|
+
def futurize_active_record(records, extends:, placeholder:, **options)
|
28
28
|
Array(records).map { |record|
|
29
|
-
render_element(extends: extends, placeholder: placeholder, options: record)
|
29
|
+
render_element(extends: extends, placeholder: placeholder, options: options.merge(model: record))
|
30
30
|
}.join.html_safe
|
31
31
|
end
|
32
32
|
|
33
33
|
def render_element(extends:, options:, placeholder:)
|
34
|
+
html_options = options.delete(:html_options) || {}
|
35
|
+
model_or_options = options.delete(:model) || options
|
34
36
|
case extends
|
37
|
+
when :li
|
38
|
+
content_tag :li, placeholder, {data: {signed_params: futurism_signed_params(model_or_options)}, is: "futurism-li"}.merge(html_options)
|
35
39
|
when :tr
|
36
|
-
content_tag :tr, placeholder, data: {signed_params: futurism_signed_params(
|
40
|
+
content_tag :tr, placeholder, {data: {signed_params: futurism_signed_params(model_or_options)}, is: "futurism-table-row"}.merge(html_options)
|
37
41
|
else
|
38
|
-
content_tag :"futurism-element", placeholder, data: {signed_params: futurism_signed_params(
|
42
|
+
content_tag :"futurism-element", placeholder, {data: {signed_params: futurism_signed_params(model_or_options)}}.merge(html_options)
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
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.3.
|
4
|
+
version: 0.3.1
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|