alchemy-json_api 0.15.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (24) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/alchemy/json_api/pages_controller.rb +1 -0
  3. data/app/serializers/alchemy/json_api/element_serializer.rb +5 -0
  4. data/app/serializers/alchemy/json_api/essence_audio_serializer.rb +40 -0
  5. data/app/serializers/alchemy/json_api/essence_headline_serializer.rb +13 -0
  6. data/app/serializers/alchemy/json_api/essence_video_serializer.rb +42 -0
  7. data/app/serializers/alchemy/json_api/ingredient_audio_serializer.rb +40 -0
  8. data/app/serializers/alchemy/json_api/ingredient_boolean_serializer.rb +11 -0
  9. data/app/serializers/alchemy/json_api/ingredient_datetime_serializer.rb +11 -0
  10. data/app/serializers/alchemy/json_api/ingredient_file_serializer.rb +35 -0
  11. data/app/serializers/alchemy/json_api/ingredient_headline_serializer.rb +13 -0
  12. data/app/serializers/alchemy/json_api/ingredient_html_serializer.rb +11 -0
  13. data/app/serializers/alchemy/json_api/ingredient_link_serializer.rb +17 -0
  14. data/app/serializers/alchemy/json_api/ingredient_node_serializer.rb +35 -0
  15. data/app/serializers/alchemy/json_api/ingredient_page_serializer.rb +25 -0
  16. data/app/serializers/alchemy/json_api/ingredient_picture_serializer.rb +60 -0
  17. data/app/serializers/alchemy/json_api/ingredient_richtext_serializer.rb +18 -0
  18. data/app/serializers/alchemy/json_api/ingredient_select_serializer.rb +11 -0
  19. data/app/serializers/alchemy/json_api/ingredient_text_serializer.rb +22 -0
  20. data/app/serializers/alchemy/json_api/ingredient_video_serializer.rb +42 -0
  21. data/lib/alchemy/json_api/ingredient_serializer.rb +22 -0
  22. data/lib/alchemy/json_api/test_support/ingredient_serializer_behaviour.rb +33 -0
  23. data/lib/alchemy/json_api/version.rb +1 -1
  24. metadata +21 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 369f587874aab63134861d26c9b1babfc0d0ba7d25a981bd2a977bf00d847b48
4
- data.tar.gz: 3e3e10d5862df03767a538fe785b17d67d88a1e02151fa0a6b67b45370876960
3
+ metadata.gz: 3935cd3e895377d3abf8138b854c6aa54148da1a77d7fd7c9942b59a467117d9
4
+ data.tar.gz: 9c2c96ba95625c68e186558a5316eedf087d375784026d50ef93a7e4f2e4edec
5
5
  SHA512:
6
- metadata.gz: 7f7b3074e7c9e446e22c12f8f8fffe64a2548ede87af8a22515efe53edc9060e2446d8cf9e2bd4511941158920e55e9cce5478b876fe4e9438d2d63d60df8cb6
7
- data.tar.gz: c68a930b025975095291d0cf53d8f7cbba2a65e309ac4a0d24ef2db5966b4bc157cc35f199c2f69c3c2e8503de20517f19594a6ef3afac12f82eb124373ee170
6
+ metadata.gz: fceba1d386c35489b4145a0becdffccdd4f00614546b15781038df613b5dea27d5dad7104ff00ad2920f52728ddb729f184d40b97542b36d96c2b05b0fb77216
7
+ data.tar.gz: f01bfc78e0d1911abf74666a4b8f19a6e0288d287125f0072364263c8450038b4bf6b8a808bdab65ed49c8265fdcdb9db2df883f60674707298e173144e11992
@@ -61,6 +61,7 @@ module Alchemy
61
61
  elements: [
62
62
  :nested_elements,
63
63
  { contents: { essence: :ingredient_association } },
64
+ { ingredients: :related_object },
64
65
  ],
65
66
  },
66
67
  },
@@ -20,6 +20,11 @@ module Alchemy
20
20
  element.contents.map(&:essence)
21
21
  end
22
22
 
23
+ has_many :ingredients,
24
+ serializer: ->(record) do
25
+ "Alchemy::JsonApi::Ingredient#{record.type.demodulize}Serializer".constantize
26
+ end
27
+
23
28
  has_many :nested_elements, record_type: :element, serializer: self
24
29
  end
25
30
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/essence_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class EssenceAudioSerializer
8
+ include EssenceSerializer
9
+
10
+ attributes(
11
+ :autoplay,
12
+ :controls,
13
+ :muted,
14
+ :loop,
15
+ )
16
+
17
+ attribute :ingredient do |essence|
18
+ essence.attachment&.url
19
+ end
20
+
21
+ with_options if: ->(essence) { essence.attachment } do
22
+ attribute :audio_name do |essence|
23
+ essence.attachment.name
24
+ end
25
+
26
+ attribute :audio_file_name do |essence|
27
+ essence.attachment.file_name
28
+ end
29
+
30
+ attribute :audio_mime_type do |essence|
31
+ essence.attachment.file_mime_type
32
+ end
33
+
34
+ attribute :audio_file_size do |essence|
35
+ essence.attachment.file_size
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/essence_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class EssenceHeadlineSerializer
8
+ include EssenceSerializer
9
+
10
+ attributes :level, :size
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/essence_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class EssenceVideoSerializer
8
+ include EssenceSerializer
9
+
10
+ attributes(
11
+ :width,
12
+ :height,
13
+ :allow_fullscreen,
14
+ :autoplay,
15
+ :controls,
16
+ :preload,
17
+ )
18
+
19
+ attribute :ingredient do |essence|
20
+ essence.attachment&.url
21
+ end
22
+
23
+ with_options if: ->(essence) { essence.attachment } do
24
+ attribute :video_name do |essence|
25
+ essence.attachment.name
26
+ end
27
+
28
+ attribute :video_file_name do |essence|
29
+ essence.attachment.file_name
30
+ end
31
+
32
+ attribute :video_mime_type do |essence|
33
+ essence.attachment.file_mime_type
34
+ end
35
+
36
+ attribute :video_file_size do |essence|
37
+ essence.attachment.file_size
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientAudioSerializer
8
+ include IngredientSerializer
9
+
10
+ attributes(
11
+ :autoplay,
12
+ :controls,
13
+ :muted,
14
+ :loop,
15
+ )
16
+
17
+ attribute :value do |ingredient|
18
+ ingredient.attachment&.url
19
+ end
20
+
21
+ with_options if: ->(ingredient) { ingredient.attachment } do
22
+ attribute :audio_name do |ingredient|
23
+ ingredient.attachment.name
24
+ end
25
+
26
+ attribute :audio_file_name do |ingredient|
27
+ ingredient.attachment.file_name
28
+ end
29
+
30
+ attribute :audio_mime_type do |ingredient|
31
+ ingredient.attachment.file_mime_type
32
+ end
33
+
34
+ attribute :audio_file_size do |ingredient|
35
+ ingredient.attachment.file_size
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientBooleanSerializer
8
+ include IngredientSerializer
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientDatetimeSerializer
8
+ include IngredientSerializer
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientFileSerializer
8
+ include IngredientSerializer
9
+
10
+ attribute :link_title, &:title
11
+
12
+ attribute :value do |ingredient|
13
+ ingredient.attachment&.url
14
+ end
15
+
16
+ with_options if: proc { |ingredient| ingredient.attachment } do
17
+ attribute :attachment_name do |ingredient|
18
+ ingredient.attachment.name
19
+ end
20
+
21
+ attribute :attachment_file_name do |ingredient|
22
+ ingredient.attachment.file_name
23
+ end
24
+
25
+ attribute :attachment_mime_type do |ingredient|
26
+ ingredient.attachment.file_mime_type
27
+ end
28
+
29
+ attribute :attachment_file_size do |ingredient|
30
+ ingredient.attachment.file_size
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientHeadlineSerializer
8
+ include IngredientSerializer
9
+
10
+ attributes :level, :size
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientHtmlSerializer
8
+ include IngredientSerializer
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientLinkSerializer
8
+ include IngredientSerializer
9
+
10
+ attributes(
11
+ :link_class_name,
12
+ :link_target,
13
+ :link_title
14
+ )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientNodeSerializer
8
+ include IngredientSerializer
9
+
10
+ attribute :value do |ingredient|
11
+ ingredient.node&.name
12
+ end
13
+
14
+ belongs_to :node, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer
15
+
16
+ with_options if: proc { |ingredient| ingredient.node } do
17
+ attribute :name do |ingredient|
18
+ ingredient.node.name
19
+ end
20
+
21
+ attribute :link_url do |ingredient|
22
+ ingredient.node.url
23
+ end
24
+
25
+ attribute :link_title do |ingredient|
26
+ ingredient.node.title
27
+ end
28
+
29
+ attribute :link_nofollow do |ingredient|
30
+ ingredient.node.nofollow
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientPageSerializer
8
+ include IngredientSerializer
9
+
10
+ attribute :value do |ingredient|
11
+ ingredient.page&.url_path
12
+ end
13
+
14
+ attribute :page_name do |ingredient|
15
+ ingredient.page&.name
16
+ end
17
+
18
+ attribute :page_url do |ingredient|
19
+ ingredient.page&.url_path
20
+ end
21
+
22
+ has_one :page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientPictureSerializer
8
+ include IngredientSerializer
9
+
10
+ attributes(
11
+ :title,
12
+ :caption,
13
+ :link_class_name,
14
+ :link_title,
15
+ :link_target,
16
+ )
17
+
18
+ attribute :value do |ingredient|
19
+ ingredient.picture&.url
20
+ end
21
+
22
+ attribute :alt_text, &:alt_tag
23
+ attribute :link_url, &:link
24
+
25
+ with_options if: proc { |ingredient| ingredient.picture.present? } do
26
+ attribute :image_dimensions do |ingredient|
27
+ sizes = ingredient.settings[:size]&.split("x", 2)&.map(&:to_i) || [
28
+ ingredient.image_file_width,
29
+ ingredient.image_file_height,
30
+ ]
31
+
32
+ ratio = ingredient.image_file_width.to_f / ingredient.image_file_height
33
+ width = sizes[0].zero? ? sizes[1] * ratio : sizes[0]
34
+ height = sizes[1].zero? ? sizes[0] / ratio : sizes[1]
35
+
36
+ {
37
+ width: width,
38
+ height: height,
39
+ }
40
+ end
41
+
42
+ attribute :image_name do |ingredient|
43
+ ingredient.picture.name
44
+ end
45
+
46
+ attribute :image_file_name do |ingredient|
47
+ ingredient.picture.image_file_name
48
+ end
49
+
50
+ attribute :image_mime_type do |ingredient|
51
+ "image/#{ingredient.picture.image_file_format}"
52
+ end
53
+
54
+ attribute :image_file_size do |ingredient|
55
+ ingredient.picture.image_file_size
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientRichtextSerializer
8
+ include IngredientSerializer
9
+
10
+ attributes(
11
+ :sanitized_body,
12
+ :stripped_body,
13
+ )
14
+
15
+ attribute :body, &:value
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientSelectSerializer
8
+ include IngredientSerializer
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientTextSerializer
8
+ include IngredientSerializer
9
+
10
+ attributes(
11
+ :link,
12
+ :link_class_name,
13
+ :link_target,
14
+ :link_title,
15
+ )
16
+
17
+ # maintain compatibility with EssenceText
18
+ attribute :body, &:value
19
+ attribute :link_url, &:link
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/json_api/ingredient_serializer"
4
+
5
+ module Alchemy
6
+ module JsonApi
7
+ class IngredientVideoSerializer
8
+ include IngredientSerializer
9
+
10
+ attributes(
11
+ :width,
12
+ :height,
13
+ :allow_fullscreen,
14
+ :autoplay,
15
+ :controls,
16
+ :preload,
17
+ )
18
+
19
+ attribute :value do |ingredient|
20
+ ingredient.attachment&.url
21
+ end
22
+
23
+ with_options if: ->(ingredient) { ingredient.attachment } do
24
+ attribute :video_name do |ingredient|
25
+ ingredient.attachment.name
26
+ end
27
+
28
+ attribute :video_file_name do |ingredient|
29
+ ingredient.attachment.file_name
30
+ end
31
+
32
+ attribute :video_mime_type do |ingredient|
33
+ ingredient.attachment.file_mime_type
34
+ end
35
+
36
+ attribute :video_file_size do |ingredient|
37
+ ingredient.attachment.file_size
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module JsonApi
5
+ module IngredientSerializer
6
+ def self.included(klass)
7
+ klass.include JSONAPI::Serializer
8
+
9
+ klass.has_one :element, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer
10
+
11
+ klass.attributes(
12
+ :role,
13
+ :value,
14
+ :created_at,
15
+ :updated_at
16
+ )
17
+
18
+ klass.attribute :deprecated, &:deprecated?
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples "an ingredient serializer" do
4
+ describe "attributes" do
5
+ subject { serializer.serializable_hash[:data][:attributes] }
6
+
7
+ it "has the right keys and values" do
8
+ expect(subject).to have_key(:role)
9
+ expect(subject).to have_key(:value)
10
+ expect(subject).to have_key(:created_at)
11
+ expect(subject).to have_key(:updated_at)
12
+ expect(subject[:deprecated]).to be(false)
13
+ end
14
+
15
+ context "a deprecated ingredient" do
16
+ before do
17
+ expect(ingredient).to receive(:deprecated?) { true }
18
+ end
19
+
20
+ it "has deprecated attribute set to true" do
21
+ expect(subject[:deprecated]).to eq(true)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "relationships" do
27
+ subject { serializer.serializable_hash[:data][:relationships] }
28
+
29
+ it "has one element" do
30
+ expect(subject[:element]).to eq(data: { id: ingredient.element_id.to_s, type: :element })
31
+ end
32
+ end
33
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Alchemy
3
3
  module JsonApi
4
- VERSION = "0.15.0"
4
+ VERSION = "0.20.0"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy-json_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-19 00:00:00.000000000 Z
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alchemy_cms
@@ -131,9 +131,11 @@ files:
131
131
  - app/controllers/alchemy/json_api/pages_controller.rb
132
132
  - app/models/alchemy/json_api/page.rb
133
133
  - app/serializers/alchemy/json_api/element_serializer.rb
134
+ - app/serializers/alchemy/json_api/essence_audio_serializer.rb
134
135
  - app/serializers/alchemy/json_api/essence_boolean_serializer.rb
135
136
  - app/serializers/alchemy/json_api/essence_date_serializer.rb
136
137
  - app/serializers/alchemy/json_api/essence_file_serializer.rb
138
+ - app/serializers/alchemy/json_api/essence_headline_serializer.rb
137
139
  - app/serializers/alchemy/json_api/essence_html_serializer.rb
138
140
  - app/serializers/alchemy/json_api/essence_link_serializer.rb
139
141
  - app/serializers/alchemy/json_api/essence_node_serializer.rb
@@ -142,6 +144,21 @@ files:
142
144
  - app/serializers/alchemy/json_api/essence_richtext_serializer.rb
143
145
  - app/serializers/alchemy/json_api/essence_select_serializer.rb
144
146
  - app/serializers/alchemy/json_api/essence_text_serializer.rb
147
+ - app/serializers/alchemy/json_api/essence_video_serializer.rb
148
+ - app/serializers/alchemy/json_api/ingredient_audio_serializer.rb
149
+ - app/serializers/alchemy/json_api/ingredient_boolean_serializer.rb
150
+ - app/serializers/alchemy/json_api/ingredient_datetime_serializer.rb
151
+ - app/serializers/alchemy/json_api/ingredient_file_serializer.rb
152
+ - app/serializers/alchemy/json_api/ingredient_headline_serializer.rb
153
+ - app/serializers/alchemy/json_api/ingredient_html_serializer.rb
154
+ - app/serializers/alchemy/json_api/ingredient_link_serializer.rb
155
+ - app/serializers/alchemy/json_api/ingredient_node_serializer.rb
156
+ - app/serializers/alchemy/json_api/ingredient_page_serializer.rb
157
+ - app/serializers/alchemy/json_api/ingredient_picture_serializer.rb
158
+ - app/serializers/alchemy/json_api/ingredient_richtext_serializer.rb
159
+ - app/serializers/alchemy/json_api/ingredient_select_serializer.rb
160
+ - app/serializers/alchemy/json_api/ingredient_text_serializer.rb
161
+ - app/serializers/alchemy/json_api/ingredient_video_serializer.rb
145
162
  - app/serializers/alchemy/json_api/language_serializer.rb
146
163
  - app/serializers/alchemy/json_api/node_serializer.rb
147
164
  - app/serializers/alchemy/json_api/page_serializer.rb
@@ -149,7 +166,9 @@ files:
149
166
  - lib/alchemy/json_api.rb
150
167
  - lib/alchemy/json_api/engine.rb
151
168
  - lib/alchemy/json_api/essence_serializer.rb
169
+ - lib/alchemy/json_api/ingredient_serializer.rb
152
170
  - lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb
171
+ - lib/alchemy/json_api/test_support/ingredient_serializer_behaviour.rb
153
172
  - lib/alchemy/json_api/version.rb
154
173
  - lib/tasks/alchemy/json_api_tasks.rake
155
174
  homepage: https://github.com/AlchemyCMS/alchemy-json_api