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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 490e77869b91685fe4335badd8006842871eaba8df9cab7998038c531f11e607
4
- data.tar.gz: 9bc29e824f7a1e8298942842d543e19eef1e2cf6e22d1b058109675b2d38ad15
3
+ metadata.gz: e4522cbff1a5893e2a977bf7a32236b1ad9425983ed38521f188c5696dbbfec1
4
+ data.tar.gz: 37cb1278ae994766170290f172aca2f4db3b8e2a801edcb77c1ce4632352d56a
5
5
  SHA512:
6
- metadata.gz: 55449d0339a7731cb8725459aca47b66ac8039600c4e8e24a5dbf3f7c9986466f949fc91042f1882dbc2332a61009f3cabbd3c76dda98d1a07bd7a4c9abdb111
7
- data.tar.gz: 315e1274d56647b26bd0a703759160f93fa75e8d302bf5cc6304835e74fabc727e68395cba3554bf7a2fa5174acfb11c481fdbe536df0af34870560a1aa54b54
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:
@@ -13,25 +13,32 @@ module Futurism
13
13
  end
14
14
 
15
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"
16
+ collection = options.delete(:collection)
17
+ if collection.nil?
18
+ render_element(extends: extends, placeholder: placeholder, options: options)
19
19
  else
20
- content_tag :"futurism-element", placeholder, data: {signed_params: futurism_signed_params(options)}
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
- case extends
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
@@ -1,3 +1,3 @@
1
1
  module Futurism
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.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-21 00:00:00.000000000 Z
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler