rivet_cms 0.1.1.pre → 0.1.2.pre
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 +4 -4
- data/README.md +6 -0
- data/config/routes.rb +43 -43
- data/lib/rivet_cms/routes.rb +23 -13
- data/lib/rivet_cms/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 876703a8ca3148fbd0c7c01cbee963fc854e37c1efbc94375205c7a22d7cc78b
|
4
|
+
data.tar.gz: 369344dbf9c17af9ad639509a7cb78121314f1a26f80844ba16bce5b59d6311f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b19547659ff8ee822a41c7a4e28d4de0e8f9a8767e2576e4334f5bde2245e6b10c7d677fa1ae238ffac55b7d68d0eff0575eef87c26504ccbf9bc5dd4feae965
|
7
|
+
data.tar.gz: 8447100f98fa858d23667c2d686c357fa630a08d974a6595c9da4833eb4c2e8313cbcd2453ca5df686eddd6f6c6bd493fb2afd5cf9fea0f0f9282744c254d17d
|
data/README.md
CHANGED
@@ -26,3 +26,9 @@ Contribution directions go here.
|
|
26
26
|
|
27
27
|
## License
|
28
28
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
29
|
+
|
30
|
+
## Acknowledgments
|
31
|
+
|
32
|
+
This project includes code adapted from or inspired by:
|
33
|
+
|
34
|
+
- [Spree Commerce](https://github.com/spree/spree) - Route handling pattern for extensible engines (MIT License)
|
data/config/routes.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
RivetCms::
|
2
|
-
|
1
|
+
RivetCms::Engine.routes.draw do
|
2
|
+
RivetCms::Routes.add_routes do
|
3
|
+
get '/', to: "dashboard#index"
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
# Content Type Management
|
6
|
+
resources :content_types, path: 'content-types' do
|
7
|
+
resources :fields, except: [:show] do
|
8
|
+
collection do
|
9
|
+
post :update_positions
|
10
|
+
end
|
11
|
+
member do
|
12
|
+
patch :update_width
|
13
|
+
end
|
12
14
|
end
|
15
|
+
resources :contents
|
13
16
|
end
|
14
|
-
resources :contents
|
15
|
-
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
# Component Management
|
19
|
+
resources :components do
|
20
|
+
resources :fields, except: [:show] do
|
21
|
+
collection do
|
22
|
+
post :update_positions
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
# API Documentation
|
28
|
+
namespace :api do
|
29
|
+
resource :docs, only: [:show]
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
# Helper method to check if content type exists and matches the collection/single type
|
33
|
+
content_type_exists = ->(slug, is_collection) {
|
34
|
+
RivetCMS::ContentType.exists?(slug: slug, is_single: !is_collection)
|
35
|
+
}
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
# API routes with versioning
|
38
|
+
namespace :api do
|
39
|
+
namespace :v1 do
|
40
|
+
# Dynamic routes for content types
|
41
|
+
get ':slug', to: 'content#index', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
|
42
|
+
post ':slug', to: 'content#create', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
|
43
|
+
get ':slug/:id', to: 'content#show', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
|
44
|
+
put ':slug/:id', to: 'content#update', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
|
45
|
+
patch ':slug/:id', to: 'content#update', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
|
46
|
+
delete ':slug/:id', to: 'content#destroy', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
# Routes for single type content
|
49
|
+
get ':slug', to: 'single#show', constraints: ->(req) { content_type_exists.call(req.params[:slug], false) }
|
50
|
+
put ':slug', to: 'single#update', constraints: ->(req) { content_type_exists.call(req.params[:slug], false) }
|
51
|
+
patch ':slug', to: 'single#update', constraints: ->(req) { content_type_exists.call(req.params[:slug], false) }
|
52
|
+
post ':slug', to: 'single#update', constraints: ->(req) { content_type_exists.call(req.params[:slug], false) }
|
53
|
+
end
|
52
54
|
end
|
53
55
|
end
|
54
|
-
end
|
55
56
|
|
56
|
-
RivetCms::Engine.routes.draw do
|
57
57
|
RivetCms::Routes.draw_routes
|
58
58
|
end
|
data/lib/rivet_cms/routes.rb
CHANGED
@@ -1,39 +1,49 @@
|
|
1
|
+
# Route handling pattern adapted from Spree Commerce
|
2
|
+
# https://github.com/spree/spree/blob/839866a32845009d8a1fdf21cb7201e99f6ff49c/core/lib/spree/core/routes.rb
|
3
|
+
# License: MIT - https://github.com/spree/spree/blob/main/LICENSE.md
|
4
|
+
|
1
5
|
module RivetCms
|
2
6
|
module Routes
|
3
7
|
def self.draw_routes(&block)
|
4
8
|
@rivet_routes ||= []
|
5
9
|
@append_routes ||= []
|
6
10
|
|
7
|
-
# Evaluate
|
11
|
+
# Evaluate an immediate block if given
|
8
12
|
eval_block(block) if block_given?
|
9
13
|
|
10
|
-
#
|
11
|
-
@rivet_routes.each { |
|
12
|
-
|
13
|
-
#
|
14
|
-
@append_routes.each { |
|
14
|
+
# Evaluate stored main routes
|
15
|
+
@rivet_routes.each { |route_block| eval_block(&route_block) }
|
16
|
+
|
17
|
+
# Evaluate appended routes
|
18
|
+
@append_routes.each { |route_block| eval_block(&route_block) }
|
15
19
|
|
16
|
-
# Clear routes to
|
20
|
+
# Clear routes to avoid duplication on subsequent calls
|
17
21
|
@rivet_routes = []
|
18
22
|
@append_routes = []
|
19
23
|
end
|
20
24
|
|
21
25
|
def self.add_routes(&block)
|
22
26
|
@rivet_routes ||= []
|
23
|
-
|
24
|
-
@rivet_routes << block unless @rivet_routes.include?(block)
|
27
|
+
store_route(@rivet_routes, &block)
|
25
28
|
end
|
26
29
|
|
27
30
|
def self.append_routes(&block)
|
28
31
|
@append_routes ||= []
|
29
|
-
|
30
|
-
@append_routes << block unless @append_routes.include?(block)
|
32
|
+
store_route(@append_routes, &block)
|
31
33
|
end
|
32
34
|
|
33
35
|
private
|
34
36
|
|
37
|
+
# Helper method for safely storing a route block in the given collection.
|
38
|
+
def self.store_route(collection, &block)
|
39
|
+
collection << block unless collection.include?(block)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Evaluate a block within the context of the engine's routes.
|
35
43
|
def self.eval_block(&block)
|
36
|
-
RivetCms::Engine.routes.
|
44
|
+
RivetCms::Engine.routes.draw do
|
45
|
+
instance_exec(&block)
|
46
|
+
end
|
37
47
|
end
|
38
48
|
end
|
39
|
-
end
|
49
|
+
end
|
data/lib/rivet_cms/version.rb
CHANGED