alchemy-json_api 0.21.0 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4f9847b4b3ba3f36b06e079974f16b12a7469513edc62a819669da8acd05d9a
4
- data.tar.gz: 9c3586a4aa8c5fb04aab2fd3bcfd9e535ef2e91b44fee242a8a2dd9e30ec92cc
3
+ metadata.gz: b099850c244a74a544ab7d649f40faee72d021abee257d55ae9061e55c594dfd
4
+ data.tar.gz: '029e828a551ab68cdc8d1e48d26135ddc43bda3c3aca7565012ed55e40b1f1f8'
5
5
  SHA512:
6
- metadata.gz: 4a097ebe662c11540dda9e3233549fe471cb19c17694dc8ba74577e789ca949b86439a2b488461bfc8355041575f7a8c8527b024a9d7e45448c5a91ecadb37de
7
- data.tar.gz: b8413c86022ec12c4193e8914ff2ad5c29fb0353409364eb445fbd78950d07c180a2c970138cf226eb40c328ac195fe1d8694b554cd1d5d0ead25841b6c3c4ae
6
+ metadata.gz: d9f1c8b7b5e8996ea8edc83d30aecb780d5ff782530f09e8aaf43fc2a38b01e34867e79fc52bac2ecb4be6e5cc5b6ce6cbd2b478fa1d294574d56ebebfe4cd2c
7
+ data.tar.gz: 4f7efea149006aad79e341939bfa946fa5e87939315eefdfff8ef22f3e4d83b4f9b9a480b4ba058497b1a8f85c3729a2453fd956dff9570debbe384ccfb846cb
@@ -10,15 +10,10 @@ module Alchemy
10
10
 
11
11
  jsonapi_filter(page_scope, allowed) do |filtered_pages|
12
12
  @pages = filtered_pages.result
13
- if stale?(last_modified: @pages.maximum(:published_at), etag: @pages.max_by(&:cache_key).cache_key)
14
- # Only load pages with all includes when browser cache is stale
15
- jsonapi_filter(page_scope_with_includes, allowed) do |filtered|
16
- # decorate with our page model that has a eager loaded elements collection
17
- filtered_pages = filtered.result.map { |page| api_page(page) }
18
- jsonapi_paginate(filtered_pages) do |paginated|
19
- render jsonapi: paginated
20
- end
21
- end
13
+ if !@pages.all?(&:cache_page?)
14
+ render_pages_json(allowed) && return
15
+ elsif stale?(last_modified: @pages.maximum(:published_at), etag: @pages.max_by(&:cache_key)&.cache_key)
16
+ render_pages_json(allowed)
22
17
  end
23
18
  end
24
19
 
@@ -26,6 +21,10 @@ module Alchemy
26
21
  end
27
22
 
28
23
  def show
24
+ if !@page.cache_page?
25
+ render(jsonapi: api_page(load_page)) && return
26
+ end
27
+
29
28
  if stale?(last_modified: last_modified_for(@page), etag: @page.cache_key)
30
29
  # Only load page with all includes when browser cache is stale
31
30
  render jsonapi: api_page(load_page)
@@ -36,6 +35,17 @@ module Alchemy
36
35
 
37
36
  private
38
37
 
38
+ def render_pages_json(allowed)
39
+ # Only load pages with all includes when browser cache is stale
40
+ jsonapi_filter(page_scope_with_includes, allowed) do |filtered|
41
+ # decorate with our page model that has a eager loaded elements collection
42
+ filtered_pages = filtered.result.map { |page| api_page(page) }
43
+ jsonapi_paginate(filtered_pages) do |paginated|
44
+ render jsonapi: paginated
45
+ end
46
+ end
47
+ end
48
+
39
49
  def cache_duration
40
50
  ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION", 3).to_i.hours
41
51
  end
@@ -33,6 +33,27 @@ module Alchemy
33
33
  }
34
34
  end
35
35
 
36
+ attribute :srcset do |essence|
37
+ essence.content.settings.fetch(:srcset, []).map do |src|
38
+ case src
39
+ when Hash
40
+ url = essence.picture_url(src)
41
+ size = src[:size]
42
+ else
43
+ url = essence.picture_url(size: src)
44
+ size = src
45
+ end
46
+ width, height = size.split("x", 2)
47
+
48
+ {
49
+ url: url,
50
+ desc: "#{width}w",
51
+ width: width,
52
+ height: height,
53
+ }
54
+ end
55
+ end
56
+
36
57
  attribute :image_name do |essence|
37
58
  essence.picture.name
38
59
  end
@@ -39,6 +39,27 @@ module Alchemy
39
39
  }
40
40
  end
41
41
 
42
+ attribute :srcset do |ingredient|
43
+ ingredient.settings.fetch(:srcset, []).map do |src|
44
+ case src
45
+ when Hash
46
+ url = ingredient.picture_url(src)
47
+ size = src[:size]
48
+ else
49
+ url = ingredient.picture_url(size: src)
50
+ size = src
51
+ end
52
+ width, height = size.split("x", 2)
53
+
54
+ {
55
+ url: url,
56
+ desc: "#{width}w",
57
+ width: width,
58
+ height: height,
59
+ }
60
+ end
61
+ end
62
+
42
63
  attribute :image_name do |ingredient|
43
64
  ingredient.picture.name
44
65
  end
@@ -9,6 +9,7 @@ module Alchemy
9
9
  attributes(
10
10
  :name,
11
11
  :urlname,
12
+ :url_path,
12
13
  :page_layout,
13
14
  :title,
14
15
  :language_code,
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Alchemy
3
3
  module JsonApi
4
- VERSION = "0.21.0"
4
+ VERSION = "0.25.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.21.0
4
+ version: 0.25.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-09-17 00:00:00.000000000 Z
11
+ date: 2021-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alchemy_cms
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  requirements: []
193
- rubygems_version: 3.2.26
193
+ rubygems_version: 3.1.6
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: A JSONAPI compliant API for AlchemyCMS