futurism 0.3.3 → 0.4.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 +1 -1
- data/lib/futurism/channel.rb +14 -6
- data/lib/futurism/channel.rb~ +16 -7
- data/lib/futurism/helpers.rb +40 -17
- data/lib/futurism/helpers.rb~ +69 -9
- 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: ba66b2cb1a12fb863e2e0fc34798411d7f95947a197496150e1a499582fc4e28
|
4
|
+
data.tar.gz: 3f7f290ef2b0b79f9c9e5100e7eaed2520dcb8e481e391bd537649d0023d379b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e772253cf0ed802d14c6836c0fb7285f7011f79f516fa88cc85e13191b7de0f29ebbc0edbd5c7996f4f858ec4efe4890613605587a2cbd6c17c4ecbad05b4985
|
7
|
+
data.tar.gz: cf4db9dd38a545a7fe43381dc22597a4c5e77a4023698b19017740fa996e6aa0433e1927c115a1187bb9028ad26e2b36aa3ecd9f66fb19000380a6b6467efffb
|
data/README.md
CHANGED
@@ -182,7 +182,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
182
182
|
<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
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>
|
184
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>
|
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>
|
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> <a href="https://github.com/julianrubisch/futurism/pulls?q=is%3Apr+reviewed-by%3Aleastbad" title="Reviewed Pull Requests">👀</a></td>
|
186
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
187
|
</tr>
|
188
188
|
<tr>
|
data/lib/futurism/channel.rb
CHANGED
@@ -7,21 +7,29 @@ module Futurism
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def receive(data)
|
10
|
-
resources = data
|
11
|
-
[signed_params, Rails.application.message_verifier("futurism").verify(signed_params)]
|
12
|
-
}
|
10
|
+
resources = data.fetch_values("signed_params", "sgids") { |key| [nil] }.transpose
|
13
11
|
|
14
12
|
new_env = connection.env.merge(ApplicationController.renderer.instance_variable_get(:@env))
|
15
13
|
ApplicationController.renderer.instance_variable_set(:@env, new_env)
|
16
14
|
|
17
|
-
resources.each do |signed_params,
|
15
|
+
resources.each do |signed_params, sgid|
|
16
|
+
selector = "[data-signed-params='#{signed_params}']"
|
17
|
+
selector << "[data-sgid='#{sgid}']" if sgid.present?
|
18
18
|
cable_ready["Futurism::Channel"].outer_html(
|
19
|
-
selector:
|
20
|
-
html: ApplicationController.render(resource)
|
19
|
+
selector: selector,
|
20
|
+
html: ApplicationController.render(resource(signed_params: signed_params, sgid: sgid))
|
21
21
|
)
|
22
22
|
end
|
23
23
|
|
24
24
|
cable_ready.broadcast
|
25
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def resource(signed_params:, sgid:)
|
30
|
+
return GlobalID::Locator.locate_signed(sgid) if sgid.present?
|
31
|
+
|
32
|
+
Rails.application.message_verifier("futurism").verify(signed_params)
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
data/lib/futurism/channel.rb~
CHANGED
@@ -7,20 +7,29 @@ module Futurism
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def receive(data)
|
10
|
-
resources = data
|
11
|
-
[signed_params, Rails.application.message_verifier("futurism").verify(signed_params)]
|
12
|
-
}
|
10
|
+
resources = data.fetch_values("signed_params", "sgids") { |key| [nil] }.transpose
|
13
11
|
|
14
|
-
ApplicationController.renderer.
|
12
|
+
new_env = connection.env.merge(ApplicationController.renderer.instance_variable_get(:@env))
|
13
|
+
ApplicationController.renderer.instance_variable_set(:@env, new_env)
|
15
14
|
|
16
|
-
resources.each do |signed_params,
|
15
|
+
resources.each do |signed_params, sgid|
|
16
|
+
selector = "[data-signed-params='#{signed_params}']"
|
17
|
+
selector << "[data-sgid='#{sgid}']" if sgid.present?
|
17
18
|
cable_ready["Futurism::Channel"].outer_html(
|
18
|
-
selector:
|
19
|
-
html: ApplicationController.render(resource)
|
19
|
+
selector: selector,
|
20
|
+
html: ApplicationController.render(resource(signed_params: signed_params, sgid: sgid))
|
20
21
|
)
|
21
22
|
end
|
22
23
|
|
23
24
|
cable_ready.broadcast
|
24
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def resource(signed_params:, sgid:)
|
30
|
+
return GlobalID::Locator.locate_signed(sgid) if sgid.present?
|
31
|
+
|
32
|
+
Rails.application.message_verifier("futurism").verify(signed_params)
|
33
|
+
end
|
25
34
|
end
|
26
35
|
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,37 +16,59 @@ 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
21
|
collection_class_name = collection.klass.name
|
21
22
|
as = options.delete(:as) || collection_class_name.downcase
|
22
23
|
collection.map { |record|
|
23
|
-
|
24
|
+
Element.new(extends: extends, placeholder: placeholder, options: options.deep_merge(locals: {as.to_sym => record})).render
|
24
25
|
}.join.html_safe
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
def futurize_active_record(records, extends:, placeholder:, **options)
|
29
30
|
Array(records).map { |record|
|
30
|
-
|
31
|
+
Element.new(extends: extends, options: options.merge(model: record), placeholder: placeholder).render
|
31
32
|
}.join.html_safe
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
# wraps functionality for rendering a futurism element
|
36
|
+
class Element
|
37
|
+
include ActionView::Helpers
|
38
|
+
|
39
|
+
attr_reader :extends, :placeholder, :html_options, :model, :options
|
40
|
+
|
41
|
+
def initialize(extends:, placeholder:, options:)
|
42
|
+
@extends = extends
|
43
|
+
@placeholder = placeholder
|
44
|
+
@html_options = options.delete(:html_options) || {}
|
45
|
+
@model = options.delete(:model)
|
46
|
+
@options = options
|
47
|
+
end
|
48
|
+
|
49
|
+
def dataset
|
50
|
+
{
|
51
|
+
signed_params: signed_params,
|
52
|
+
sgid: model && model.to_sgid.to_s
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def render
|
57
|
+
case extends
|
58
|
+
when :li
|
59
|
+
content_tag :li, placeholder, {data: dataset, is: "futurism-li"}.merge(html_options)
|
60
|
+
when :tr
|
61
|
+
content_tag :tr, placeholder, {data: dataset, is: "futurism-table-row"}.merge(html_options)
|
62
|
+
else
|
63
|
+
content_tag :"futurism-element", placeholder, {data: dataset}.merge(html_options)
|
64
|
+
end
|
44
65
|
end
|
45
|
-
end
|
46
66
|
|
47
|
-
|
48
|
-
|
67
|
+
private
|
68
|
+
|
69
|
+
def signed_params
|
70
|
+
Rails.application.message_verifier("futurism").generate(options)
|
71
|
+
end
|
49
72
|
end
|
50
73
|
end
|
51
74
|
end
|
data/lib/futurism/helpers.rb~
CHANGED
@@ -1,13 +1,73 @@
|
|
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
|
+
futurize_with_options(extends: extends, placeholder: placeholder, partial: records_or_string, **options)
|
8
10
|
else
|
9
|
-
|
11
|
+
futurize_with_options(extends: extends, placeholder: placeholder, **options)
|
10
12
|
end
|
11
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
def futurize_with_options(extends:, placeholder:, **options)
|
16
|
+
collection = options.delete(:collection)
|
17
|
+
if collection.nil?
|
18
|
+
Element.new(extends: extends, placeholder: placeholder, options: options).render
|
19
|
+
else
|
20
|
+
collection_class_name = collection.klass.name
|
21
|
+
as = options.delete(:as) || collection_class_name.downcase
|
22
|
+
collection.map { |record|
|
23
|
+
Element.new(extends: extends, placeholder: placeholder, options: options.deep_merge(locals: {as.to_sym => record})).render
|
24
|
+
}.join.html_safe
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def futurize_active_record(records, extends:, placeholder:, **options)
|
29
|
+
Array(records).map { |record|
|
30
|
+
Element.new(extends: extends, options: options.merge(model: record), placeholder: placeholder).render
|
31
|
+
}.join.html_safe
|
32
|
+
end
|
33
|
+
|
34
|
+
# wraps functionality for rendering a futurism element
|
35
|
+
class Element
|
36
|
+
include ActionView::Helpers
|
37
|
+
|
38
|
+
attr_reader :extends, :placeholder, :html_options, :model, :options
|
39
|
+
|
40
|
+
def initialize(extends:, placeholder:, options:)
|
41
|
+
@extends = extends
|
42
|
+
@placeholder = placeholder
|
43
|
+
@html_options = options.delete(:html_options) || {}
|
44
|
+
@model = options.delete(:model)
|
45
|
+
@options = options
|
46
|
+
end
|
47
|
+
|
48
|
+
def dataset
|
49
|
+
{
|
50
|
+
signed_params: signed_params,
|
51
|
+
sgid: model && model.to_sgid.to_s
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def render
|
56
|
+
case extends
|
57
|
+
when :li
|
58
|
+
content_tag :li, placeholder, {data: dataset, is: "futurism-li"}.merge(html_options)
|
59
|
+
when :tr
|
60
|
+
content_tag :tr, placeholder, {data: dataset, is: "futurism-table-row"}.merge(html_options)
|
61
|
+
else
|
62
|
+
content_tag :"futurism-element", placeholder, {data: dataset}.merge(html_options)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def signed_params
|
69
|
+
Rails.application.message_verifier("futurism").generate(options)
|
70
|
+
end
|
71
|
+
end
|
12
72
|
end
|
13
73
|
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.4.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-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|