alchemy-json_api 0.1.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +8 -0
- data/app/controllers/alchemy/json_api/base_controller.rb +1 -0
- data/app/controllers/alchemy/json_api/pages_controller.rb +14 -4
- data/app/serializers/alchemy/json_api/element_serializer.rb +21 -18
- data/app/serializers/alchemy/json_api/essence_boolean_serializer.rb +5 -3
- data/app/serializers/alchemy/json_api/essence_date_serializer.rb +5 -3
- data/app/serializers/alchemy/json_api/essence_file_serializer.rb +19 -18
- data/app/serializers/alchemy/json_api/essence_html_serializer.rb +5 -3
- data/app/serializers/alchemy/json_api/essence_link_serializer.rb +9 -7
- data/app/serializers/alchemy/json_api/essence_node_serializer.rb +21 -20
- data/app/serializers/alchemy/json_api/essence_page_serializer.rb +24 -0
- data/app/serializers/alchemy/json_api/essence_picture_serializer.rb +29 -28
- data/app/serializers/alchemy/json_api/essence_richtext_serializer.rb +9 -7
- data/app/serializers/alchemy/json_api/essence_select_serializer.rb +5 -3
- data/app/serializers/alchemy/json_api/essence_text_serializer.rb +11 -9
- data/app/serializers/alchemy/json_api/node_serializer.rb +1 -1
- data/app/serializers/alchemy/json_api/page_serializer.rb +1 -0
- data/config/routes.rb +4 -2
- data/lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb +18 -0
- data/lib/alchemy/json_api/version.rb +1 -1
- metadata +25 -10
- data/lib/alchemy/json_api/link_helper.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb04c3210449c9689cc5d5f0a187492b6de5e53ad88928e878f564dfd10f6615
|
4
|
+
data.tar.gz: e856316ed3433935246e4fd1e33f37f5c9830bb6737fb37b02d55c441e66b91e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbb2638d53afbb1ccb330d65b0b7f2baec33b619c55992accdb58c457d10192a28459ad7520543cfc2fdbc921ca4dea09f992bf8fd532dd85f0fbedcc52504d7
|
7
|
+
data.tar.gz: a872add90f9bda24d3f0d3647ab01c0f2a5fd2707c3d83e596d21db66b9faf38bbfe587fe3179228fe9233ff921b22fe9e9c5c7954a2217c08354d5269e48668
|
data/Rakefile
CHANGED
@@ -26,3 +26,11 @@ task :test_setup do
|
|
26
26
|
exit($?.exitstatus) unless $?.success?
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
require "github_changelog_generator/task"
|
31
|
+
require "alchemy/json_api/version"
|
32
|
+
GitHubChangelogGenerator::RakeTask.new(:changelog) do |config|
|
33
|
+
config.user = "AlchemyCMS"
|
34
|
+
config.project = "alchemy-json_api"
|
35
|
+
config.future_release = "v#{Alchemy::JsonApi::VERSION}"
|
36
|
+
end
|
@@ -8,7 +8,9 @@ module Alchemy
|
|
8
8
|
allowed = [:page_layout]
|
9
9
|
|
10
10
|
jsonapi_filter(page_scope, allowed) do |filtered|
|
11
|
-
|
11
|
+
jsonapi_paginate(filtered.result) do |paginated|
|
12
|
+
render jsonapi: paginated
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
@@ -18,17 +20,25 @@ module Alchemy
|
|
18
20
|
|
19
21
|
private
|
20
22
|
|
23
|
+
def jsonapi_meta(pages)
|
24
|
+
pagination = jsonapi_pagination_meta(pages)
|
25
|
+
|
26
|
+
{
|
27
|
+
pagination: pagination.presence,
|
28
|
+
total: page_scope.count
|
29
|
+
}.compact
|
30
|
+
end
|
31
|
+
|
21
32
|
def load_page
|
22
33
|
@page = load_page_by_id || load_page_by_urlname || raise(ActiveRecord::RecordNotFound)
|
23
34
|
end
|
24
35
|
|
25
36
|
def load_page_by_id
|
26
|
-
page_scope.find_by(id: params[:
|
37
|
+
page_scope.find_by(id: params[:path])
|
27
38
|
end
|
28
39
|
|
29
40
|
def load_page_by_urlname
|
30
|
-
|
31
|
-
page_scope.find_by(urlname: params[:id])
|
41
|
+
page_scope.find_by(urlname: params[:path])
|
32
42
|
end
|
33
43
|
|
34
44
|
def page_scope
|
@@ -1,25 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module Alchemy
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
2
|
+
module Alchemy
|
3
|
+
module JsonApi
|
4
|
+
class ElementSerializer
|
5
|
+
include FastJsonapi::ObjectSerializer
|
6
|
+
attributes(
|
7
|
+
:name,
|
8
|
+
:fixed,
|
9
|
+
:position,
|
10
|
+
:created_at,
|
11
|
+
:updated_at,
|
12
|
+
)
|
13
|
+
belongs_to :parent_element, record_type: :element, serializer: self
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
belongs_to :page
|
16
|
+
has_many :essences, polymorphic: true do |element|
|
17
|
+
element.contents.map(&:essence)
|
18
|
+
end
|
17
19
|
|
18
|
-
|
20
|
+
has_many :nested_elements, record_type: :element, serializer: self
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
with_options if: ->(_, params) { params[:admin] == true } do
|
23
|
+
attribute :tag_list
|
24
|
+
attribute :display_name, &:display_name_with_preview_text
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "alchemy/json_api/essence_serializer"
|
3
3
|
|
4
|
-
module Alchemy
|
5
|
-
|
6
|
-
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssenceBooleanSerializer
|
7
|
+
include EssenceSerializer
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "alchemy/json_api/essence_serializer"
|
3
3
|
|
4
|
-
module Alchemy
|
5
|
-
|
6
|
-
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssenceDateSerializer
|
7
|
+
include EssenceSerializer
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
@@ -1,30 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "alchemy/json_api/essence_serializer"
|
3
|
-
require "alchemy/json_api/link_helper"
|
4
3
|
|
5
|
-
module Alchemy
|
6
|
-
|
7
|
-
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssenceFileSerializer
|
7
|
+
include EssenceSerializer
|
8
8
|
|
9
|
-
|
9
|
+
attribute :link_title, &:title
|
10
10
|
|
11
|
-
|
11
|
+
attribute :ingredient, &:attachment_url
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
with_options if: proc { |essence| essence.attachment.present? } do
|
14
|
+
attribute :attachment_name do |essence|
|
15
|
+
essence.attachment.name
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
attribute :attachment_file_name do |essence|
|
19
|
+
essence.attachment.file_name
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
attribute :attachment_mime_type do |essence|
|
23
|
+
essence.attachment.file_mime_type
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
attribute :attachment_file_size do |essence|
|
27
|
+
essence.attachment.file_size
|
28
|
+
end
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "alchemy/json_api/essence_serializer"
|
3
3
|
|
4
|
-
module Alchemy
|
5
|
-
|
6
|
-
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssenceHtmlSerializer
|
7
|
+
include EssenceSerializer
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "alchemy/json_api/essence_serializer"
|
3
3
|
|
4
|
-
module Alchemy
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssenceLinkSerializer
|
7
|
+
include EssenceSerializer
|
8
|
+
attributes(
|
9
|
+
:link_title,
|
10
|
+
:link_target,
|
11
|
+
)
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
@@ -1,32 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "alchemy/json_api/essence_serializer"
|
3
|
-
require "alchemy/json_api/link_helper"
|
4
3
|
|
5
|
-
module Alchemy
|
6
|
-
|
7
|
-
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssenceNodeSerializer
|
7
|
+
include EssenceSerializer
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
attribute :ingredient do |essence|
|
10
|
+
essence&.node&.name
|
11
|
+
end
|
12
12
|
|
13
|
-
|
13
|
+
belongs_to :node
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
with_options if: proc { |essence| essence.node.present? } do
|
16
|
+
attribute :name do |essence|
|
17
|
+
essence.node.name
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
attribute :link_url do |essence|
|
21
|
+
essence.node.url
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
attribute :link_title do |essence|
|
25
|
+
essence.node.title
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
attribute :link_nofollow do |essence|
|
29
|
+
essence.node.nofollow
|
30
|
+
end
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "alchemy/json_api/essence_serializer"
|
3
|
+
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssencePageSerializer
|
7
|
+
include EssenceSerializer
|
8
|
+
|
9
|
+
attribute :ingredient do |essence|
|
10
|
+
essence.page&.url_path
|
11
|
+
end
|
12
|
+
|
13
|
+
attribute :page_name do |essence|
|
14
|
+
essence.page&.name
|
15
|
+
end
|
16
|
+
|
17
|
+
attribute :page_url do |essence|
|
18
|
+
essence.page&.url_path
|
19
|
+
end
|
20
|
+
|
21
|
+
has_one :page, record_type: :page, serializer: PageSerializer
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,40 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "alchemy/json_api/essence_serializer"
|
3
|
-
require "alchemy/json_api/link_helper"
|
4
3
|
|
5
|
-
module Alchemy
|
6
|
-
|
7
|
-
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssencePictureSerializer
|
7
|
+
include EssenceSerializer
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
attributes(
|
10
|
+
:title,
|
11
|
+
:caption,
|
12
|
+
:link_title,
|
13
|
+
:link_target,
|
14
|
+
)
|
15
|
+
attribute :ingredient, &:picture_url
|
16
|
+
attribute :alt_text, &:alt_tag
|
17
|
+
attribute :link_url, &:link
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
with_options if: proc { |essence| essence.picture.present? } do
|
20
|
+
attribute :image_dimensions do |essence|
|
21
|
+
essence.sizes_from_string(essence.render_size)
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
attribute :image_name do |essence|
|
25
|
+
essence.picture.name
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
attribute :image_file_name do |essence|
|
29
|
+
essence.picture.image_file_name
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
attribute :image_mime_type do |essence|
|
33
|
+
"image/#{essence.picture.image_file_format}"
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
attribute :image_file_size do |essence|
|
37
|
+
essence.picture.image_file_size
|
38
|
+
end
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "alchemy/json_api/essence_serializer"
|
3
3
|
|
4
|
-
module Alchemy
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssenceRichtextSerializer
|
7
|
+
include EssenceSerializer
|
8
|
+
attributes(
|
9
|
+
:body,
|
10
|
+
:stripped_body,
|
11
|
+
)
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "alchemy/json_api/essence_serializer"
|
3
3
|
|
4
|
-
module Alchemy
|
5
|
-
|
6
|
-
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssenceSelectSerializer
|
7
|
+
include EssenceSerializer
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require "alchemy/json_api/essence_serializer"
|
3
3
|
|
4
|
-
module Alchemy
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
module Alchemy
|
5
|
+
module JsonApi
|
6
|
+
class EssenceTextSerializer
|
7
|
+
include EssenceSerializer
|
8
|
+
attributes(
|
9
|
+
:body,
|
10
|
+
:link_title,
|
11
|
+
:link_target,
|
12
|
+
)
|
13
|
+
attribute :link_url, &:link
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
@@ -18,6 +18,7 @@ module Alchemy
|
|
18
18
|
belongs_to :language
|
19
19
|
|
20
20
|
has_many :elements
|
21
|
+
has_many :fixed_elements, record_type: :element, serializer: ElementSerializer
|
21
22
|
|
22
23
|
has_many :all_elements, record_type: :element, serializer: ElementSerializer do |page|
|
23
24
|
page.all_elements.select { |e| e.public? && !e.trashed? }
|
data/config/routes.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
Alchemy::JsonApi::Engine.routes.draw do
|
3
|
-
resources :pages, only: [:
|
4
|
-
|
3
|
+
resources :pages, only: [:index]
|
4
|
+
get "pages/*path" => "pages#show", as: :page
|
5
|
+
resources :layout_pages, only: [:index]
|
6
|
+
get "layout_pages/*path" => "layout_pages#show", as: :layout_page
|
5
7
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
RSpec.shared_examples "an essence serializer" do
|
3
|
+
describe "attributes" do
|
4
|
+
subject { serializer.serializable_hash[:data][:attributes] }
|
5
|
+
|
6
|
+
it "has the right keys and values" do
|
7
|
+
expect(subject).to have_key(:ingredient)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "relationships" do
|
12
|
+
subject { serializer.serializable_hash[:data][:relationships] }
|
13
|
+
|
14
|
+
it "has the right keys and values" do
|
15
|
+
expect(subject[:element]).to eq(data: { id: essence.element.id.to_s, type: :element })
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alchemy-json_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Meyerhoff
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: alchemy_cms
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: fast_jsonapi
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: github_changelog_generator
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: jsonapi-rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,6 +128,7 @@ files:
|
|
114
128
|
- app/serializers/alchemy/json_api/essence_html_serializer.rb
|
115
129
|
- app/serializers/alchemy/json_api/essence_link_serializer.rb
|
116
130
|
- app/serializers/alchemy/json_api/essence_node_serializer.rb
|
131
|
+
- app/serializers/alchemy/json_api/essence_page_serializer.rb
|
117
132
|
- app/serializers/alchemy/json_api/essence_picture_serializer.rb
|
118
133
|
- app/serializers/alchemy/json_api/essence_richtext_serializer.rb
|
119
134
|
- app/serializers/alchemy/json_api/essence_select_serializer.rb
|
@@ -125,14 +140,14 @@ files:
|
|
125
140
|
- lib/alchemy/json_api.rb
|
126
141
|
- lib/alchemy/json_api/engine.rb
|
127
142
|
- lib/alchemy/json_api/essence_serializer.rb
|
128
|
-
- lib/alchemy/json_api/
|
143
|
+
- lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb
|
129
144
|
- lib/alchemy/json_api/version.rb
|
130
145
|
- lib/tasks/alchemy/json_api_tasks.rake
|
131
146
|
homepage: https://github.com/AlchemyCMS/alchemy-json_api
|
132
147
|
licenses:
|
133
148
|
- MIT
|
134
149
|
metadata: {}
|
135
|
-
post_install_message:
|
150
|
+
post_install_message:
|
136
151
|
rdoc_options: []
|
137
152
|
require_paths:
|
138
153
|
- lib
|
@@ -148,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
163
|
version: '0'
|
149
164
|
requirements: []
|
150
165
|
rubygems_version: 3.0.3
|
151
|
-
signing_key:
|
166
|
+
signing_key:
|
152
167
|
specification_version: 4
|
153
168
|
summary: A JSONAPI compliant API for AlchemyCMS
|
154
169
|
test_files: []
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module Alchemy
|
3
|
-
module JsonApi
|
4
|
-
module LinkHelper
|
5
|
-
def alchemy_link(path_base, object)
|
6
|
-
return unless object
|
7
|
-
|
8
|
-
if Rails.application.routes.default_url_options[:host]
|
9
|
-
Alchemy::Engine.routes.url_helpers.public_send("#{path_base}_url", object)
|
10
|
-
else
|
11
|
-
Alchemy::Engine.routes.url_helpers.public_send("#{path_base}_path", object)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|