futurism 0.2.0 → 0.3.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 +13 -2
- data/lib/futurism/helpers.rb +17 -10
- 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: e4522cbff1a5893e2a977bf7a32236b1ad9425983ed38521f188c5696dbbfec1
|
4
|
+
data.tar.gz: 37cb1278ae994766170290f172aca2f4db3b8e2a801edcb77c1ce4632352d56a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83742f96cb378d99ddc8d51bb95b8734fcdec0d9e22d0f3ac2b17122977dedf518942ed38664d715ec2b6890017269a301c31ebe3489d1e10d2176412970c13e
|
7
|
+
data.tar.gz: 42a03c5aa611bd415ecfc33b76b9242ce2c4d1e2c06cab8bf50ee06e6e7fe67fb14bad078f4c36bf9b0cd2e242eeefdd3f79581a5f50d47e2c89f5c184f12e40
|
data/README.md
CHANGED
@@ -77,7 +77,7 @@ That way you get maximal flexibility when just specifying a single resource.
|
|
77
77
|
Call `futurize` with a `partial` keyword:
|
78
78
|
|
79
79
|
```erb
|
80
|
-
<%= futurize partial: "items/card", locals: {card: @card}, extends: :div %>
|
80
|
+
<%= futurize partial: "items/card", locals: {card: @card}, extends: :div do %>
|
81
81
|
<div class="spinner"></div>
|
82
82
|
<% end %>
|
83
83
|
```
|
@@ -85,9 +85,20 @@ Call `futurize` with a `partial` keyword:
|
|
85
85
|
You can also use the shorthand syntax:
|
86
86
|
|
87
87
|
```erb
|
88
|
-
<%= futurize "items/card", card: @card, extends: :div %>
|
88
|
+
<%= futurize "items/card", card: @card, extends: :div do %>
|
89
89
|
<div class="spinner"></div>
|
90
90
|
<% end %>
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Collections
|
94
|
+
|
95
|
+
Collection rendering is also possible:
|
96
|
+
|
97
|
+
```erb
|
98
|
+
<%= futurize partial: "items/card", collection: @cards, extends: :div do %>
|
99
|
+
<div class="spinner"></div>
|
100
|
+
<% end %>
|
101
|
+
```
|
91
102
|
|
92
103
|
## Installation
|
93
104
|
Add this line to your application's Gemfile:
|
data/lib/futurism/helpers.rb
CHANGED
@@ -13,25 +13,32 @@ module Futurism
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def futurize_with_options(extends:, placeholder:, **options)
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
collection = options.delete(:collection)
|
17
|
+
if collection.nil?
|
18
|
+
render_element(extends: extends, placeholder: placeholder, options: options)
|
19
19
|
else
|
20
|
-
|
20
|
+
collection_class_name = collection.first.class.name
|
21
|
+
collection.map { |record|
|
22
|
+
render_element(extends: extends, placeholder: placeholder, options: options.merge(locals: {collection_class_name.downcase.to_sym => record}))
|
23
|
+
}.join.html_safe
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
27
|
def futurize_active_record(records, extends:, placeholder:)
|
25
28
|
Array(records).map { |record|
|
26
|
-
|
27
|
-
when :tr
|
28
|
-
content_tag :tr, placeholder, data: {signed_params: futurism_signed_params(record)}, is: "futurism-table-row"
|
29
|
-
else
|
30
|
-
content_tag :"futurism-element", placeholder, data: {signed_params: futurism_signed_params(record)}
|
31
|
-
end
|
29
|
+
render_element(extends: extends, placeholder: placeholder, options: record)
|
32
30
|
}.join.html_safe
|
33
31
|
end
|
34
32
|
|
33
|
+
def render_element(extends:, options:, placeholder:)
|
34
|
+
case extends
|
35
|
+
when :tr
|
36
|
+
content_tag :tr, placeholder, data: {signed_params: futurism_signed_params(options)}, is: "futurism-table-row"
|
37
|
+
else
|
38
|
+
content_tag :"futurism-element", placeholder, data: {signed_params: futurism_signed_params(options)}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
35
42
|
def futurism_signed_params(params)
|
36
43
|
Rails.application.message_verifier("futurism").generate(params)
|
37
44
|
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.3.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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|