futurism 0.3.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +69 -13
- data/lib/futurism/channel.rb +30 -9
- data/lib/futurism/channel.rb~ +30 -9
- data/lib/futurism/helpers.rb +51 -18
- data/lib/futurism/helpers.rb~ +79 -9
- data/lib/futurism/shims/deep_transform_values.rb +47 -0
- data/lib/futurism/version.rb +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cde59cb75363c7ba6032575a5783a0f0407cdb630fa1301fda0c38e7bc21949f
|
4
|
+
data.tar.gz: d8f5acd7d125dd0b41071704c10e0db6cca741cea7f271c290517527ff522ef6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d561d2864614bbc0bc41f030477f7cc1ab8ea3518edbca35903054adcc0107aad3634085cd3de85455f2c0d0569829a13ec7cb2ada161db812b478d2140cd2
|
7
|
+
data.tar.gz: efcd9f32c2814e05f9603daf8e949c6df2869d32e94da772cf6097ceb6e5587f3d543363c95eea07f8ad26e41ce18430899a6e2a541bff31ccc0c62cb1171883
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
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-12-orange.svg?style=flat-square)](#contributors-)
|
5
5
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
6
6
|
Lazy-load Rails partials via CableReady
|
7
7
|
|
@@ -10,6 +10,25 @@ Lazy-load Rails partials via CableReady
|
|
10
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
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
12
|
|
13
|
+
## Table of Contents
|
14
|
+
|
15
|
+
- [Table of Contents](#table-of-contents)
|
16
|
+
- [Facts](#facts)
|
17
|
+
- [Browser Support](#browser-support)
|
18
|
+
- [Usage](#usage)
|
19
|
+
- [API](#api)
|
20
|
+
- [Resource](#resource)
|
21
|
+
- [Explicit Partial](#explicit-partial)
|
22
|
+
- [HTML Options](#html-options)
|
23
|
+
- [Events](#events)
|
24
|
+
- [Installation](#installation)
|
25
|
+
- [Manual Installation](#manual-installation)
|
26
|
+
- [Authentication](#authentication)
|
27
|
+
- [Gotchas](#gotchas)
|
28
|
+
- [Contributing](#contributing)
|
29
|
+
- [License](#license)
|
30
|
+
- [Contributors](#contributors)
|
31
|
+
|
13
32
|
## Facts
|
14
33
|
- only one dependency: CableReady
|
15
34
|
- bundle size (without CableReady) is around [~1.04kB](https://bundlephobia.com/result?p=@minthesize/futurism@0.1.3)
|
@@ -93,6 +112,16 @@ You can also use the shorthand syntax:
|
|
93
112
|
<% end %>
|
94
113
|
```
|
95
114
|
|
115
|
+
#### Collections
|
116
|
+
|
117
|
+
Collection rendering is also possible:
|
118
|
+
|
119
|
+
```erb
|
120
|
+
<%= futurize partial: "items/card", collection: @cards, extends: :div do %>
|
121
|
+
<div class="spinner"></div>
|
122
|
+
<% end %>
|
123
|
+
```
|
124
|
+
|
96
125
|
### HTML Options
|
97
126
|
|
98
127
|
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.
|
@@ -111,16 +140,6 @@ This will output the following:
|
|
111
140
|
</tr>
|
112
141
|
```
|
113
142
|
|
114
|
-
#### Collections
|
115
|
-
|
116
|
-
Collection rendering is also possible:
|
117
|
-
|
118
|
-
```erb
|
119
|
-
<%= futurize partial: "items/card", collection: @cards, extends: :div do %>
|
120
|
-
<div class="spinner"></div>
|
121
|
-
<% end %>
|
122
|
-
```
|
123
|
-
|
124
143
|
## Events
|
125
144
|
|
126
145
|
Once your futurize element has been rendered, the `futurize:appeared` custom event will be called.
|
@@ -155,7 +174,7 @@ $ bin/yarn add @minthesize/futurism
|
|
155
174
|
In your `app/javascript/channels/index.js`, add the following
|
156
175
|
|
157
176
|
```js
|
158
|
-
import * as Futurism from '@minthesize/futurism'
|
177
|
+
import * as Futurism from '@minthesize/futurism'
|
159
178
|
|
160
179
|
import consumer from './consumer'
|
161
180
|
|
@@ -163,6 +182,39 @@ Futurism.initializeElements()
|
|
163
182
|
Futurism.createSubscription(consumer)
|
164
183
|
```
|
165
184
|
|
185
|
+
## Authentication
|
186
|
+
For authentication, you can rely on ActionCable identifiers, for example, if you use Devise:
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
module ApplicationCable
|
190
|
+
class Connection < ActionCable::Connection::Base
|
191
|
+
identified_by :current_user
|
192
|
+
|
193
|
+
def connect
|
194
|
+
self.current_user = env["warden"].user || reject_unauthorized_connection
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
```
|
199
|
+
|
200
|
+
The [Stimulus Reflex Docs](https://docs.stimulusreflex.com/authentication) have an excellent section about all sorts of authentication.
|
201
|
+
|
202
|
+
## Gotchas
|
203
|
+
|
204
|
+
### ActiveStorage URLs aren't correct in development
|
205
|
+
|
206
|
+
Out of the box, Rails will prefix generated urls with `http://example.org` rather than `http://localhost`, much like ActionMailer. To amend this, add
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
# config/environments/development.rb
|
210
|
+
config.action_controller.default_url_options = {host: "localhost", port: 3000}
|
211
|
+
|
212
|
+
# config/environments/production.rb
|
213
|
+
config.action_controller.default_url_options = {host: "mysite.com"}
|
214
|
+
```
|
215
|
+
|
216
|
+
to your environments.
|
217
|
+
|
166
218
|
## Contributing
|
167
219
|
|
168
220
|
## License
|
@@ -182,11 +234,15 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
182
234
|
<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>
|
183
235
|
<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>
|
184
236
|
<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>
|
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>
|
237
|
+
<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> <a href="https://github.com/julianrubisch/futurism/pulls?q=is%3Apr+reviewed-by%3Aleastbad" title="Reviewed Pull Requests">👀</a></td>
|
186
238
|
<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
239
|
</tr>
|
188
240
|
<tr>
|
189
241
|
<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>
|
242
|
+
<td align="center"><a href="http://hass.codes"><img src="https://avatars2.githubusercontent.com/u/1064205?v=4" width="100px;" alt=""/><br /><sub><b>Hassanin Ahmed</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=sas1ni69" title="Code">💻</a></td>
|
243
|
+
<td align="center"><a href="https://marcoroth.dev"><img src="https://avatars2.githubusercontent.com/u/6411752?v=4" width="100px;" alt=""/><br /><sub><b>Marco Roth</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=marcoroth" title="Code">💻</a></td>
|
244
|
+
<td align="center"><a href="https://viedit.com"><img src="https://avatars1.githubusercontent.com/u/49990587?v=4" width="100px;" alt=""/><br /><sub><b>Viedit com</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=vieditcom" title="Documentation">📖</a></td>
|
245
|
+
<td align="center"><a href="http://scottbarrow.ca"><img src="https://avatars2.githubusercontent.com/u/5571736?v=4" width="100px;" alt=""/><br /><sub><b>Scott Barrow</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=scottbarrow" title="Code">💻</a></td>
|
190
246
|
</tr>
|
191
247
|
</table>
|
192
248
|
|
data/lib/futurism/channel.rb
CHANGED
@@ -2,25 +2,46 @@ module Futurism
|
|
2
2
|
class Channel < ActionCable::Channel::Base
|
3
3
|
include CableReady::Broadcaster
|
4
4
|
|
5
|
+
def stream_name
|
6
|
+
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
|
7
|
+
[
|
8
|
+
params[:channel],
|
9
|
+
ids.select(&:present?).join(";")
|
10
|
+
].select(&:present?).join(":")
|
11
|
+
end
|
12
|
+
|
5
13
|
def subscribed
|
6
|
-
stream_from
|
14
|
+
stream_from stream_name
|
7
15
|
end
|
8
16
|
|
9
17
|
def receive(data)
|
10
|
-
resources = data
|
11
|
-
[signed_params, Rails.application.message_verifier("futurism").verify(signed_params)]
|
12
|
-
}
|
18
|
+
resources = data.fetch_values("signed_params", "sgids") { |key| [nil] }.transpose
|
13
19
|
|
14
|
-
ApplicationController.renderer.
|
20
|
+
new_env = connection.env.merge(ApplicationController.renderer.instance_variable_get(:@env))
|
21
|
+
ApplicationController.renderer.instance_variable_set(:@env, new_env)
|
15
22
|
|
16
|
-
resources.each do |signed_params,
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
resources.each do |signed_params, sgid|
|
24
|
+
selector = "[data-signed-params='#{signed_params}']"
|
25
|
+
selector << "[data-sgid='#{sgid}']" if sgid.present?
|
26
|
+
cable_ready[stream_name].outer_html(
|
27
|
+
selector: selector,
|
28
|
+
html: ApplicationController.render(resource(signed_params: signed_params, sgid: sgid))
|
20
29
|
)
|
21
30
|
end
|
22
31
|
|
23
32
|
cable_ready.broadcast
|
24
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def resource(signed_params:, sgid:)
|
38
|
+
return GlobalID::Locator.locate_signed(sgid) if sgid.present?
|
39
|
+
|
40
|
+
Rails
|
41
|
+
.application
|
42
|
+
.message_verifier("futurism")
|
43
|
+
.verify(signed_params)
|
44
|
+
.deep_transform_values { |value| value.is_a?(String) && value.start_with?("gid://") ? GlobalID::Locator.locate(value) : value }
|
45
|
+
end
|
25
46
|
end
|
26
47
|
end
|
data/lib/futurism/channel.rb~
CHANGED
@@ -2,25 +2,46 @@ module Futurism
|
|
2
2
|
class Channel < ActionCable::Channel::Base
|
3
3
|
include CableReady::Broadcaster
|
4
4
|
|
5
|
+
def stream_name
|
6
|
+
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
|
7
|
+
[
|
8
|
+
params[:channel],
|
9
|
+
ids.select(&:present?).join(";")
|
10
|
+
].select(&:present?).join(":")
|
11
|
+
end
|
12
|
+
|
5
13
|
def subscribed
|
6
|
-
stream_from
|
14
|
+
stream_from stream_name
|
7
15
|
end
|
8
16
|
|
9
17
|
def receive(data)
|
10
|
-
resources = data
|
11
|
-
[signed_params, Rails.application.message_verifier("futurism").verify(signed_params)]
|
12
|
-
}
|
18
|
+
resources = data.fetch_values("signed_params", "sgids") { |key| [nil] }.transpose
|
13
19
|
|
14
|
-
ApplicationController.renderer.
|
20
|
+
new_env = connection.env.merge(ApplicationController.renderer.instance_variable_get(:@env))
|
21
|
+
ApplicationController.renderer.instance_variable_set(:@env, new_env)
|
15
22
|
|
16
|
-
resources.each do |signed_params,
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
resources.each do |signed_params, sgid|
|
24
|
+
selector = "[data-signed-params='#{signed_params}']"
|
25
|
+
selector << "[data-sgid='#{sgid}']" if sgid.present?
|
26
|
+
cable_ready[stream_name].outer_html(
|
27
|
+
selector: selector,
|
28
|
+
html: ApplicationController.render(resource(signed_params: signed_params, sgid: sgid))
|
20
29
|
)
|
21
30
|
end
|
22
31
|
|
23
32
|
cable_ready.broadcast
|
24
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def resource(signed_params:, sgid:)
|
38
|
+
return GlobalID::Locator.locate_signed(sgid) if sgid.present?
|
39
|
+
|
40
|
+
Rails
|
41
|
+
.application
|
42
|
+
.message_verifier("futurism")
|
43
|
+
.verify(signed_params)
|
44
|
+
.deep_transform_values { |value| value.start_with?("gid://") ? GlobalID::Locator.locate(value) : value }
|
45
|
+
end
|
25
46
|
end
|
26
47
|
end
|
data/lib/futurism/helpers.rb
CHANGED
@@ -6,7 +6,8 @@ module Futurism
|
|
6
6
|
if records_or_string.is_a?(ActiveRecord::Base) || records_or_string.is_a?(ActiveRecord::Relation)
|
7
7
|
futurize_active_record(records_or_string, extends: extends, placeholder: placeholder, **options)
|
8
8
|
elsif records_or_string.is_a?(String)
|
9
|
-
|
9
|
+
html_options = options.delete(:html_options)
|
10
|
+
futurize_with_options(extends: extends, placeholder: placeholder, partial: records_or_string, locals: options, html_options: html_options)
|
10
11
|
else
|
11
12
|
futurize_with_options(extends: extends, placeholder: placeholder, **options)
|
12
13
|
end
|
@@ -15,36 +16,68 @@ module Futurism
|
|
15
16
|
def futurize_with_options(extends:, placeholder:, **options)
|
16
17
|
collection = options.delete(:collection)
|
17
18
|
if collection.nil?
|
18
|
-
|
19
|
+
Element.new(extends: extends, placeholder: placeholder, options: options).render
|
19
20
|
else
|
20
|
-
collection_class_name = collection.
|
21
|
+
collection_class_name = collection.klass.name
|
22
|
+
as = options.delete(:as) || collection_class_name.downcase
|
21
23
|
collection.map { |record|
|
22
|
-
|
24
|
+
Element.new(extends: extends, placeholder: placeholder, options: options.deep_merge(locals: {as.to_sym => record})).render
|
23
25
|
}.join.html_safe
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
29
|
def futurize_active_record(records, extends:, placeholder:, **options)
|
28
30
|
Array(records).map { |record|
|
29
|
-
|
31
|
+
Element.new(extends: extends, options: options.merge(model: record), placeholder: placeholder).render
|
30
32
|
}.join.html_safe
|
31
33
|
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
# wraps functionality for rendering a futurism element
|
36
|
+
class Element
|
37
|
+
include ActionView::Helpers
|
38
|
+
|
39
|
+
attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options
|
40
|
+
|
41
|
+
def initialize(extends:, placeholder:, options:)
|
42
|
+
@extends = extends
|
43
|
+
@placeholder = placeholder
|
44
|
+
@html_options = options.delete(:html_options) || {}
|
45
|
+
@data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params)
|
46
|
+
@model = options.delete(:model)
|
47
|
+
@options = data_attributes.any? ? options.merge(data: data_attributes) : options
|
43
48
|
end
|
44
|
-
end
|
45
49
|
|
46
|
-
|
47
|
-
|
50
|
+
def dataset
|
51
|
+
data_attributes.merge({
|
52
|
+
signed_params: signed_params,
|
53
|
+
sgid: model && model.to_sgid.to_s
|
54
|
+
})
|
55
|
+
end
|
56
|
+
|
57
|
+
def render
|
58
|
+
case extends
|
59
|
+
when :li
|
60
|
+
content_tag :li, placeholder, html_options.deep_merge({data: dataset, is: "futurism-li"})
|
61
|
+
when :tr
|
62
|
+
content_tag :tr, placeholder, html_options.deep_merge({data: dataset, is: "futurism-table-row"})
|
63
|
+
else
|
64
|
+
content_tag :"futurism-element", placeholder, html_options.deep_merge({data: dataset})
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def transformed_options
|
69
|
+
require_relative "shims/deep_transform_values" unless options.respond_to? :deep_transform_values
|
70
|
+
|
71
|
+
options.deep_transform_values do |value|
|
72
|
+
value.is_a?(ActiveRecord::Base) ? value.to_global_id.to_s : value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def signed_params
|
79
|
+
Rails.application.message_verifier("futurism").generate(transformed_options)
|
80
|
+
end
|
48
81
|
end
|
49
82
|
end
|
50
83
|
end
|
data/lib/futurism/helpers.rb~
CHANGED
@@ -1,13 +1,83 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module Futurism
|
2
|
+
module Helpers
|
3
|
+
def futurize(records_or_string = nil, extends:, **options, &block)
|
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, **options)
|
8
|
+
elsif records_or_string.is_a?(String)
|
9
|
+
html_options = options.delete(:html_options)
|
10
|
+
futurize_with_options(extends: extends, placeholder: placeholder, partial: records_or_string, locals: options, html_options: html_options)
|
8
11
|
else
|
9
|
-
|
12
|
+
futurize_with_options(extends: extends, placeholder: placeholder, **options)
|
10
13
|
end
|
11
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
def futurize_with_options(extends:, placeholder:, **options)
|
17
|
+
collection = options.delete(:collection)
|
18
|
+
if collection.nil?
|
19
|
+
Element.new(extends: extends, placeholder: placeholder, options: options).render
|
20
|
+
else
|
21
|
+
collection_class_name = collection.klass.name
|
22
|
+
as = options.delete(:as) || collection_class_name.downcase
|
23
|
+
collection.map { |record|
|
24
|
+
Element.new(extends: extends, placeholder: placeholder, options: options.deep_merge(locals: {as.to_sym => record})).render
|
25
|
+
}.join.html_safe
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def futurize_active_record(records, extends:, placeholder:, **options)
|
30
|
+
Array(records).map { |record|
|
31
|
+
Element.new(extends: extends, options: options.merge(model: record), placeholder: placeholder).render
|
32
|
+
}.join.html_safe
|
33
|
+
end
|
34
|
+
|
35
|
+
# wraps functionality for rendering a futurism element
|
36
|
+
class Element
|
37
|
+
include ActionView::Helpers
|
38
|
+
|
39
|
+
attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options
|
40
|
+
|
41
|
+
def initialize(extends:, placeholder:, options:)
|
42
|
+
@extends = extends
|
43
|
+
@placeholder = placeholder
|
44
|
+
@html_options = options.delete(:html_options) || {}
|
45
|
+
@data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params)
|
46
|
+
@model = options.delete(:model)
|
47
|
+
@options = data_attributes.any? ? options.merge(data: data_attributes) : options
|
48
|
+
end
|
49
|
+
|
50
|
+
def dataset
|
51
|
+
data_attributes.merge({
|
52
|
+
signed_params: signed_params,
|
53
|
+
sgid: model && model.to_sgid.to_s
|
54
|
+
})
|
55
|
+
end
|
56
|
+
|
57
|
+
def render
|
58
|
+
case extends
|
59
|
+
when :li
|
60
|
+
content_tag :li, placeholder, html_options.deep_merge({data: dataset, is: "futurism-li"})
|
61
|
+
when :tr
|
62
|
+
content_tag :tr, placeholder, html_options.deep_merge({data: dataset, is: "futurism-table-row"})
|
63
|
+
else
|
64
|
+
content_tag :"futurism-element", placeholder, html_options.deep_merge({data: dataset})
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def transformed_options
|
69
|
+
require_relative "shims/deep_transform_values" unless options.respond_to? :deep_transform_values
|
70
|
+
|
71
|
+
options.deep_transform_values do |value|
|
72
|
+
value.is_a?(ActiveRecord::Base) ? value.to_global_id.to_s : value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def signed_params
|
79
|
+
Rails.application.message_verifier("futurism").generate(transformed_options)
|
80
|
+
end
|
81
|
+
end
|
12
82
|
end
|
13
83
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
# Returns a new hash with all values converted by the block operation.
|
5
|
+
# This includes the values from the root hash and from all
|
6
|
+
# nested hashes and arrays.
|
7
|
+
#
|
8
|
+
# hash = { person: { name: 'Rob', age: '28' } }
|
9
|
+
#
|
10
|
+
# hash.deep_transform_values{ |value| value.to_s.upcase }
|
11
|
+
# # => {person: {name: "ROB", age: "28"}}
|
12
|
+
def deep_transform_values(&block)
|
13
|
+
_deep_transform_values_in_object(self, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Destructively converts all values by using the block operation.
|
17
|
+
# This includes the values from the root hash and from all
|
18
|
+
# nested hashes and arrays.
|
19
|
+
def deep_transform_values!(&block)
|
20
|
+
_deep_transform_values_in_object!(self, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Support methods for deep transforming nested hashes and arrays.
|
26
|
+
def _deep_transform_values_in_object(object, &block)
|
27
|
+
case object
|
28
|
+
when Hash
|
29
|
+
object.transform_values { |value| _deep_transform_values_in_object(value, &block) }
|
30
|
+
when Array
|
31
|
+
object.map { |e| _deep_transform_values_in_object(e, &block) }
|
32
|
+
else
|
33
|
+
yield(object)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def _deep_transform_values_in_object!(object, &block)
|
38
|
+
case object
|
39
|
+
when Hash
|
40
|
+
object.transform_values! { |value| _deep_transform_values_in_object!(value, &block) }
|
41
|
+
when Array
|
42
|
+
object.map! { |e| _deep_transform_values_in_object!(e, &block) }
|
43
|
+
else
|
44
|
+
yield(object)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/futurism/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: futurism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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-
|
11
|
+
date: 2020-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appraisal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +142,14 @@ dependencies:
|
|
128
142
|
requirements:
|
129
143
|
- - ">="
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
145
|
+
version: '5.2'
|
132
146
|
type: :runtime
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
150
|
- - ">="
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
152
|
+
version: '5.2'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: cable_ready
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,6 +184,7 @@ files:
|
|
170
184
|
- lib/futurism/engine.rb
|
171
185
|
- lib/futurism/helpers.rb
|
172
186
|
- lib/futurism/helpers.rb~
|
187
|
+
- lib/futurism/shims/deep_transform_values.rb
|
173
188
|
- lib/futurism/version.rb
|
174
189
|
- lib/tasks/futurism_tasks.rake
|
175
190
|
- lib/tasks/futurism_tasks.rake~
|