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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4ab85871fd2fb7a01b149fb1d70b99e7683c87d22e028c337c3029257162dfa
4
- data.tar.gz: 7854daa20f72debd1f2efc10bb9f0593b7d4912629dad6ae0accb8ee04e32b88
3
+ metadata.gz: 876703a8ca3148fbd0c7c01cbee963fc854e37c1efbc94375205c7a22d7cc78b
4
+ data.tar.gz: 369344dbf9c17af9ad639509a7cb78121314f1a26f80844ba16bce5b59d6311f
5
5
  SHA512:
6
- metadata.gz: 73eedb4dbfb8dd8e456ac72c43cf7040965a0a2ce4418a4220ff54f60b6f054c203eeb3b5ffdd098812e836f707138006a47c349c30b36101a76f8646fad382e
7
- data.tar.gz: 818fe99cd5bcc199bbcc53763bceb1c4f460dce246dedf0aad1636fd3add63c3627abd3ccc57f37722448bef7f1f17a156b5dc37d677b2470bb335ce63d0920e
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::Routes.add_routes do
2
- get '/', to: "dashboard#index"
1
+ RivetCms::Engine.routes.draw do
2
+ RivetCms::Routes.add_routes do
3
+ get '/', to: "dashboard#index"
3
4
 
4
- # Content Type Management
5
- resources :content_types, path: 'content-types' do
6
- resources :fields, except: [:show] do
7
- collection do
8
- post :update_positions
9
- end
10
- member do
11
- patch :update_width
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
- # Component Management
18
- resources :components do
19
- resources :fields, except: [:show] do
20
- collection do
21
- post :update_positions
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
- # API Documentation
27
- namespace :api do
28
- resource :docs, only: [:show]
29
- end
27
+ # API Documentation
28
+ namespace :api do
29
+ resource :docs, only: [:show]
30
+ end
30
31
 
31
- # Helper method to check if content type exists and matches the collection/single type
32
- content_type_exists = ->(slug, is_collection) {
33
- RivetCMS::ContentType.exists?(slug: slug, is_single: !is_collection)
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
- # API routes with versioning
37
- namespace :api do
38
- namespace :v1 do
39
- # Dynamic routes for content types
40
- get ':slug', to: 'content#index', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
41
- post ':slug', to: 'content#create', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
42
- get ':slug/:id', to: 'content#show', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
43
- put ':slug/:id', to: 'content#update', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
44
- patch ':slug/:id', to: 'content#update', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
45
- delete ':slug/:id', to: 'content#destroy', constraints: ->(req) { content_type_exists.call(req.params[:slug], true) }
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
- # Routes for single type content
48
- get ':slug', to: 'single#show', constraints: ->(req) { content_type_exists.call(req.params[:slug], false) }
49
- put ':slug', to: 'single#update', constraints: ->(req) { content_type_exists.call(req.params[:slug], false) }
50
- patch ':slug', to: 'single#update', constraints: ->(req) { content_type_exists.call(req.params[:slug], false) }
51
- post ':slug', to: 'single#update', constraints: ->(req) { content_type_exists.call(req.params[:slug], false) }
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
@@ -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 the passed block first if given
11
+ # Evaluate an immediate block if given
8
12
  eval_block(block) if block_given?
9
13
 
10
- # Draw main routes
11
- @rivet_routes.each { |r| eval_block(&r) }
12
-
13
- # Draw appended routes
14
- @append_routes.each { |r| eval_block(&r) }
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 prevent drawing twice
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
- # Store the block unless it's already been added
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
- # Store the block unless it's already been added
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.send(:eval_block, block)
44
+ RivetCms::Engine.routes.draw do
45
+ instance_exec(&block)
46
+ end
37
47
  end
38
48
  end
39
- end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module RivetCms
2
- VERSION = "0.1.1.pre"
2
+ VERSION = "0.1.2.pre"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rivet_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.pre
4
+ version: 0.1.2.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Williams