alchemy-json_api 0.26.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +11 -0
  3. data/README.md +48 -8
  4. data/app/controllers/alchemy/json_api/nodes_controller.rb +54 -0
  5. data/app/serializers/alchemy/json_api/base_serializer.rb +9 -0
  6. data/app/serializers/alchemy/json_api/element_serializer.rb +1 -3
  7. data/app/serializers/alchemy/json_api/essence_audio_serializer.rb +1 -1
  8. data/app/serializers/alchemy/json_api/essence_boolean_serializer.rb +1 -1
  9. data/app/serializers/alchemy/json_api/essence_date_serializer.rb +1 -1
  10. data/app/serializers/alchemy/json_api/essence_file_serializer.rb +1 -1
  11. data/app/serializers/alchemy/json_api/essence_headline_serializer.rb +1 -1
  12. data/app/serializers/alchemy/json_api/essence_html_serializer.rb +1 -1
  13. data/app/serializers/alchemy/json_api/essence_link_serializer.rb +1 -1
  14. data/app/serializers/alchemy/json_api/essence_node_serializer.rb +1 -1
  15. data/app/serializers/alchemy/json_api/essence_page_serializer.rb +1 -1
  16. data/app/serializers/alchemy/json_api/essence_picture_serializer.rb +1 -1
  17. data/app/serializers/alchemy/json_api/essence_richtext_serializer.rb +1 -1
  18. data/app/serializers/alchemy/json_api/essence_select_serializer.rb +1 -1
  19. data/app/serializers/alchemy/json_api/essence_text_serializer.rb +1 -1
  20. data/app/serializers/alchemy/json_api/essence_video_serializer.rb +1 -1
  21. data/app/serializers/alchemy/json_api/ingredient_audio_serializer.rb +1 -1
  22. data/app/serializers/alchemy/json_api/ingredient_boolean_serializer.rb +1 -1
  23. data/app/serializers/alchemy/json_api/ingredient_datetime_serializer.rb +1 -1
  24. data/app/serializers/alchemy/json_api/ingredient_file_serializer.rb +1 -1
  25. data/app/serializers/alchemy/json_api/ingredient_headline_serializer.rb +1 -1
  26. data/app/serializers/alchemy/json_api/ingredient_html_serializer.rb +1 -1
  27. data/app/serializers/alchemy/json_api/ingredient_link_serializer.rb +1 -1
  28. data/app/serializers/alchemy/json_api/ingredient_node_serializer.rb +1 -1
  29. data/app/serializers/alchemy/json_api/ingredient_page_serializer.rb +1 -1
  30. data/app/serializers/alchemy/json_api/ingredient_picture_serializer.rb +1 -1
  31. data/app/serializers/alchemy/json_api/ingredient_richtext_serializer.rb +1 -1
  32. data/app/serializers/alchemy/json_api/ingredient_select_serializer.rb +1 -1
  33. data/app/serializers/alchemy/json_api/ingredient_text_serializer.rb +1 -1
  34. data/app/serializers/alchemy/json_api/ingredient_video_serializer.rb +1 -1
  35. data/app/serializers/alchemy/json_api/language_serializer.rb +1 -3
  36. data/app/serializers/alchemy/json_api/node_serializer.rb +10 -3
  37. data/app/serializers/alchemy/json_api/page_serializer.rb +1 -3
  38. data/config/routes.rb +1 -0
  39. data/lib/alchemy/json_api/essence_serializer.rb +0 -1
  40. data/lib/alchemy/json_api/ingredient_serializer.rb +0 -2
  41. data/lib/alchemy/json_api/test_support/ingredient_serializer_behaviour.rb +7 -3
  42. data/lib/alchemy/json_api/version.rb +1 -1
  43. data/lib/alchemy/json_api.rb +19 -1
  44. metadata +8 -5
  45. data/MIT-LICENSE +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71119435a938c25b6cf78cbeb274ff09adcf720054bb6ed4feff493dd75046f5
4
- data.tar.gz: ceca5e80fb346ff9b6a0a72c977bb2bae09183c76ee4892a8aa0ed3953086aec
3
+ metadata.gz: 989f236e42f0befd106d6df29381ee52af0dded17f610cd3a25e138d18314a4d
4
+ data.tar.gz: c6c4ed4a63778083dcbe2f3812a5f6bdd27f0331f808356d31adcd4cb0fecba3
5
5
  SHA512:
6
- metadata.gz: 314bf831796cf8261d1bcbce0ad8fdc65e055946ee05e84006f5f3ca3204ca29b87501eaaf790c10bd7e0039ee435f2078c6d1762390c84a41326e8443b64d40
7
- data.tar.gz: afb5358fb2252f8accf35bc0b36e893d527ec6615b5a57313deaeecf5918d393ed791fc776b4e8632082c052728c072c1c5033213a20d3fea123c7711ed65abe
6
+ metadata.gz: 9f967f501bd18e6377e6299cbe042ea0414fadaa64cf8814479dfc30be2c664d31e142a1d4ec57df3dbfcebf68523e43149a85319468cd17b08f3f32086bc43e
7
+ data.tar.gz: 5e9f3d72009dc145b4e887c0b3674153f805154ae7e97f99352023411b7743094594759cdda723e63ec48d83317b64a3ec6b8fa675a05286b535b3efa49691ca
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Copyright 2020 Martin Meyerhoff, Thomas von Deyen
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -2,15 +2,10 @@
2
2
 
3
3
  A JSON-API based API for AlchemyCMS
4
4
 
5
- ## Usage
6
-
7
- Mount the engine in your `config/routes.rb` file where you want, like this:
5
+ ## Installation
8
6
 
9
- ```rb
10
- mount Alchemy::JsonApi::Engine => "/jsonapi/"
11
- ```
7
+ ### In your Alchemy Rails project
12
8
 
13
- ## Installation
14
9
  Add this line to your application's Gemfile:
15
10
 
16
11
  ```ruby
@@ -27,8 +22,53 @@ Or install it yourself as:
27
22
  $ gem install alchemy-json_api
28
23
  ```
29
24
 
25
+ ### In your JS/Frontend app
26
+
27
+ Run this in your application:
28
+
29
+ ```
30
+ yarn add "@alchemy_cms/json_api"
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### In your Rails app
36
+
37
+ Mount the engine in your Alchemy Rails app like this:
38
+
39
+ ```rb
40
+ # config/routes.rb
41
+ mount Alchemy::JsonApi::Engine => "/jsonapi/"
42
+ ```
43
+
44
+ > __NOTE__ Pick any path you like. This will be the **prefix** of your API URLs
45
+
46
+ ### In your frontend app
47
+
48
+ This repo provides an NPM package with deserializers to help you convert the response into JS objects.
49
+
50
+ ```js
51
+ import { deserializePages } from "@alchemy_cms/json_api"
52
+
53
+ const response = await fetch("/jsonapi/pages.json")
54
+ const data = await response.json()
55
+ const pages = deserializePages(data)
56
+
57
+ console.log(pages[0].name) // => Homepage
58
+ ```
59
+
60
+ ## Key transforms
61
+
62
+ If you ever want to change how Alchemy serializes attributes you can set
63
+
64
+ ```rb
65
+ Alchemy::JsonApi.key_transform = :camel_lower
66
+ ```
67
+
68
+ It defaults to `:underscore`.
69
+
30
70
  ## Contributing
31
71
  Contribution directions go here.
32
72
 
33
73
  ## License
34
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
74
+ The gem is available as open source under the terms of the [BSD-3-Clause license](https://opensource.org/licenses/BSD-3-Clause).
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module JsonApi
5
+ class NodesController < JsonApi::BaseController
6
+ def index
7
+ @nodes = node_scope.select(:id, :updated_at)
8
+ if stale?(last_modified: @nodes.maximum(:updated_at), etag: @nodes)
9
+ jsonapi_paginate(node_scope_with_includes) do |paginated|
10
+ render jsonapi: paginated
11
+ end
12
+ end
13
+
14
+ expires_in cache_duration, { public: true, must_revalidate: true }
15
+ end
16
+
17
+ private
18
+
19
+ def cache_duration
20
+ ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION", 3).to_i.hours
21
+ end
22
+
23
+ def jsonapi_meta(nodes)
24
+ pagination = jsonapi_pagination_meta(nodes)
25
+
26
+ {
27
+ pagination: pagination.presence,
28
+ total: node_scope.count,
29
+ }.compact
30
+ end
31
+
32
+ def node_scope
33
+ Alchemy::Node.all
34
+ end
35
+
36
+ def node_scope_with_includes
37
+ if params[:include].present?
38
+ includes = params[:include].split(",").map do |association|
39
+ association.split(".").reverse.inject({}) do |value, key|
40
+ { key.to_sym => value }
41
+ end
42
+ end
43
+ node_scope.includes(includes)
44
+ else
45
+ node_scope
46
+ end
47
+ end
48
+
49
+ def jsonapi_serializer_class(*)
50
+ ::Alchemy::JsonApi::NodeSerializer
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,9 @@
1
+ module Alchemy
2
+ module JsonApi
3
+ class BaseSerializer
4
+ include JSONAPI::Serializer
5
+
6
+ set_key_transform Alchemy::JsonApi.key_transform
7
+ end
8
+ end
9
+ end
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Alchemy
3
3
  module JsonApi
4
- class ElementSerializer
5
- include JSONAPI::Serializer
6
-
4
+ class ElementSerializer < BaseSerializer
7
5
  attributes(
8
6
  :name,
9
7
  :fixed,
@@ -4,7 +4,7 @@ require "alchemy/json_api/essence_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class EssenceAudioSerializer
7
+ class EssenceAudioSerializer < BaseSerializer
8
8
  include EssenceSerializer
9
9
 
10
10
  attributes(
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssenceBooleanSerializer
6
+ class EssenceBooleanSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssenceDateSerializer
6
+ class EssenceDateSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssenceFileSerializer
6
+ class EssenceFileSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
 
9
9
  attribute :link_title, &:title
@@ -4,7 +4,7 @@ require "alchemy/json_api/essence_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class EssenceHeadlineSerializer
7
+ class EssenceHeadlineSerializer < BaseSerializer
8
8
  include EssenceSerializer
9
9
 
10
10
  attributes :level, :size
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssenceHtmlSerializer
6
+ class EssenceHtmlSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssenceLinkSerializer
6
+ class EssenceLinkSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
  attributes(
9
9
  :link_title,
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssenceNodeSerializer
6
+ class EssenceNodeSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
 
9
9
  attribute :ingredient do |essence|
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssencePageSerializer
6
+ class EssencePageSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
 
9
9
  attribute :ingredient do |essence|
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssencePictureSerializer
6
+ class EssencePictureSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
 
9
9
  attributes(
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssenceRichtextSerializer
6
+ class EssenceRichtextSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
  attributes(
9
9
  :body,
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssenceSelectSerializer
6
+ class EssenceSelectSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ require "alchemy/json_api/essence_serializer"
3
3
 
4
4
  module Alchemy
5
5
  module JsonApi
6
- class EssenceTextSerializer
6
+ class EssenceTextSerializer < BaseSerializer
7
7
  include EssenceSerializer
8
8
  attributes(
9
9
  :body,
@@ -4,7 +4,7 @@ require "alchemy/json_api/essence_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class EssenceVideoSerializer
7
+ class EssenceVideoSerializer < BaseSerializer
8
8
  include EssenceSerializer
9
9
 
10
10
  attributes(
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientAudioSerializer
7
+ class IngredientAudioSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
 
10
10
  attributes(
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientBooleanSerializer
7
+ class IngredientBooleanSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientDatetimeSerializer
7
+ class IngredientDatetimeSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientFileSerializer
7
+ class IngredientFileSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
 
10
10
  attribute :link_title, &:title
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientHeadlineSerializer
7
+ class IngredientHeadlineSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
 
10
10
  attributes :level, :size
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientHtmlSerializer
7
+ class IngredientHtmlSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientLinkSerializer
7
+ class IngredientLinkSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
 
10
10
  attributes(
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientNodeSerializer
7
+ class IngredientNodeSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
 
10
10
  attribute :value do |ingredient|
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientPageSerializer
7
+ class IngredientPageSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
 
10
10
  attribute :value do |ingredient|
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientPictureSerializer
7
+ class IngredientPictureSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
 
10
10
  attributes(
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientRichtextSerializer
7
+ class IngredientRichtextSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
 
10
10
  attributes(
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientSelectSerializer
7
+ class IngredientSelectSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientTextSerializer
7
+ class IngredientTextSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
 
10
10
  attributes(
@@ -4,7 +4,7 @@ require "alchemy/json_api/ingredient_serializer"
4
4
 
5
5
  module Alchemy
6
6
  module JsonApi
7
- class IngredientVideoSerializer
7
+ class IngredientVideoSerializer < BaseSerializer
8
8
  include IngredientSerializer
9
9
 
10
10
  attributes(
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Alchemy
3
3
  module JsonApi
4
- class LanguageSerializer
5
- include JSONAPI::Serializer
6
-
4
+ class LanguageSerializer < BaseSerializer
7
5
  attributes(
8
6
  :name,
9
7
  :language_code,
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Alchemy
3
3
  module JsonApi
4
- class NodeSerializer
5
- include JSONAPI::Serializer
6
-
4
+ class NodeSerializer < BaseSerializer
7
5
  attributes :name
8
6
  attribute :link_url, &:url
9
7
  attribute :link_title, &:title
@@ -11,6 +9,15 @@ module Alchemy
11
9
 
12
10
  belongs_to :parent, record_type: :node, serializer: self
13
11
 
12
+ belongs_to(
13
+ :page,
14
+ record_type: :page,
15
+ if: ->(node) { node.page },
16
+ serializer: ::Alchemy::JsonApi::PageSerializer,
17
+ ) do |node|
18
+ ::Alchemy::JsonApi::Page.new(node.page)
19
+ end
20
+
14
21
  has_many :children, record_type: :node, serializer: self
15
22
  end
16
23
  end
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Alchemy
3
3
  module JsonApi
4
- class PageSerializer
5
- include JSONAPI::Serializer
6
-
4
+ class PageSerializer < BaseSerializer
7
5
  ELEMENT_SERIALIZER = ::Alchemy::JsonApi::ElementSerializer
8
6
 
9
7
  attributes(
data/config/routes.rb CHANGED
@@ -4,6 +4,7 @@ Alchemy::JsonApi::Engine.routes.draw do
4
4
  get "pages/*path" => "pages#show", as: :page
5
5
  resources :layout_pages, only: [:index]
6
6
  get "layout_pages/*path" => "layout_pages#show", as: :layout_page
7
+ resources :nodes, only: [:index]
7
8
 
8
9
  namespace :admin do
9
10
  get "pages/*path" => "pages#show", as: :page
@@ -3,7 +3,6 @@ module Alchemy
3
3
  module JsonApi
4
4
  module EssenceSerializer
5
5
  def self.included(klass)
6
- klass.include JSONAPI::Serializer
7
6
  klass.has_one :element, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer do |essence|
8
7
  essence.content.element
9
8
  end
@@ -4,8 +4,6 @@ module Alchemy
4
4
  module JsonApi
5
5
  module IngredientSerializer
6
6
  def self.included(klass)
7
- klass.include JSONAPI::Serializer
8
-
9
7
  klass.has_one :element, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer
10
8
 
11
9
  klass.attributes(
@@ -4,11 +4,15 @@ RSpec.shared_examples "an ingredient serializer" do
4
4
  describe "attributes" do
5
5
  subject { serializer.serializable_hash[:data][:attributes] }
6
6
 
7
- it "has the right keys and values" do
7
+ it "has the right transformed keys and values" do
8
+ transform_method = FastJsonapi::ObjectSerializer::TRANSFORMS_MAPPING[Alchemy::JsonApi.key_transform]
9
+ transformed_keys = %w[created_at updated_at].map { |k| k.send(*transform_method).to_sym }
10
+
8
11
  expect(subject).to have_key(:role)
9
12
  expect(subject).to have_key(:value)
10
- expect(subject).to have_key(:created_at)
11
- expect(subject).to have_key(:updated_at)
13
+ transformed_keys.each do |transformed_key|
14
+ expect(subject).to have_key(transformed_key)
15
+ end
12
16
  expect(subject[:deprecated]).to be(false)
13
17
  end
14
18
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Alchemy
3
3
  module JsonApi
4
- VERSION = "0.26.0"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
@@ -1,10 +1,28 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "fast_jsonapi"
3
4
  require "alchemy_cms"
4
5
  require "alchemy/json_api/engine"
5
6
 
6
7
  module Alchemy
7
8
  module JsonApi
8
- # Your code goes here...
9
+ # Set FastJsonapi key_transform
10
+ #
11
+ # Supported transformations:
12
+ #
13
+ # :camel # "some_key" => "SomeKey"
14
+ # :camel_lower # "some_key" => "someKey"
15
+ # :dash # "some_key" => "some-key"
16
+ # :underscore # "some_key" => "some_key"
17
+ def self.key_transform=(value)
18
+ @_key_transform = value
19
+ end
20
+
21
+ # FastJsonapi key_transform
22
+ #
23
+ # Default :underscore # "some_key" => "some_key"
24
+ def self.key_transform
25
+ @_key_transform || :underscore
26
+ end
9
27
  end
10
28
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy-json_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
+ - Thomas von Deyen
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2022-05-10 00:00:00.000000000 Z
12
+ date: 2022-09-09 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: alchemy_cms
@@ -121,15 +122,17 @@ executables: []
121
122
  extensions: []
122
123
  extra_rdoc_files: []
123
124
  files:
124
- - MIT-LICENSE
125
+ - LICENSE
125
126
  - README.md
126
127
  - Rakefile
127
128
  - app/controllers/alchemy/json_api/admin/layout_pages_controller.rb
128
129
  - app/controllers/alchemy/json_api/admin/pages_controller.rb
129
130
  - app/controllers/alchemy/json_api/base_controller.rb
130
131
  - app/controllers/alchemy/json_api/layout_pages_controller.rb
132
+ - app/controllers/alchemy/json_api/nodes_controller.rb
131
133
  - app/controllers/alchemy/json_api/pages_controller.rb
132
134
  - app/models/alchemy/json_api/page.rb
135
+ - app/serializers/alchemy/json_api/base_serializer.rb
133
136
  - app/serializers/alchemy/json_api/element_serializer.rb
134
137
  - app/serializers/alchemy/json_api/essence_audio_serializer.rb
135
138
  - app/serializers/alchemy/json_api/essence_boolean_serializer.rb
@@ -173,7 +176,7 @@ files:
173
176
  - lib/tasks/alchemy/json_api_tasks.rake
174
177
  homepage: https://github.com/AlchemyCMS/alchemy-json_api
175
178
  licenses:
176
- - MIT
179
+ - BSD-3-Clause
177
180
  metadata: {}
178
181
  post_install_message:
179
182
  rdoc_options: []
@@ -190,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
193
  - !ruby/object:Gem::Version
191
194
  version: '0'
192
195
  requirements: []
193
- rubygems_version: 3.1.6
196
+ rubygems_version: 3.3.7
194
197
  signing_key:
195
198
  specification_version: 4
196
199
  summary: A JSONAPI compliant API for AlchemyCMS
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2020 Martin Meyerhoff
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.