railspress-engine 1.3.2 → 1.3.3

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: 82835798c2b73d8f15e76d9883b911bfb7c7130c2ec54ca94b7c3b306112dc33
4
- data.tar.gz: 526d5a4c65204b09337e44265e0d7bfcab0aff08cbfd9e99f3094e7fec32647d
3
+ metadata.gz: b86ffa934cc6f5e0c3de52b2f5e8961a1ef6444e375eae8718d173575ae8f31b
4
+ data.tar.gz: 154b1e091d90518091624b61c4780ab52fddebc91e8ed304298c62449b8d72e6
5
5
  SHA512:
6
- metadata.gz: 9d78ecf917f7bb2550b8dda4eda224120c53297f345f9432b6a83705d2df97461f8caf2ea5eadc06a1396fcd59bd8a8d6c9578fb9f86caeffce295792f752866
7
- data.tar.gz: ebcde5bf787af266bf0439ad6a684fcad2484e5f6f800f31a1a2c0c4b09a52c0f503b419bd6648ff1a444a725ea50c88ef907e8fb6bd66f719c7eccd8d9bb343
6
+ metadata.gz: a43922645abd3f80aafb8ad88055e76e6f4a1ff807c39c3d0f49ab2709ef55d69783f0b04b33b6db357c14d722141009879f93814e98e020fd762ba52d799c99
7
+ data.tar.gz: 4a5bf1a0d8217ab1d802671f9c05aa8d608f707645ca918edf24ca33e20a60092fba23bb6863cff49f237178522120ee7b7e0c85a7010219e7a6014d00cb4338
@@ -29,52 +29,12 @@ module Railspress
29
29
  end
30
30
  end
31
31
 
32
- # Request-level cache to avoid repeated queries
33
32
  def self.cache
34
- @cache ||= {}
33
+ Railspress::CMS.cache
35
34
  end
36
35
 
37
36
  def self.clear_cache
38
- @cache = {}
39
- end
40
-
41
- # Chainable query class for content retrieval
42
- class CMSQuery
43
- def initialize
44
- @group_name = nil
45
- @element_name = nil
46
- end
47
-
48
- def find(group_name)
49
- @group_name = group_name
50
- self
51
- end
52
-
53
- def load(element_name)
54
- @element_name = element_name
55
- self
56
- end
57
-
58
- def element
59
- return nil unless @group_name && @element_name
60
-
61
- cache_key = "#{@group_name}:#{@element_name}"
62
- cached = CmsHelper.cache[cache_key]
63
- return cached if cached
64
-
65
- group = Railspress::ContentGroup.active.find_by(name: @group_name)
66
- return nil unless group
67
-
68
- found = group.content_elements.active.find_by(name: @element_name)
69
- CmsHelper.cache[cache_key] = found if found
70
- found
71
- rescue ActiveRecord::RecordNotFound
72
- nil
73
- end
74
-
75
- def value
76
- element&.value
77
- end
37
+ Railspress::CMS.clear_cache
78
38
  end
79
39
 
80
40
  # Get a content element's value by group and element name.
@@ -145,9 +105,9 @@ module Railspress
145
105
  end
146
106
 
147
107
  # Return a new CMSQuery instance for chainable API in views.
148
- # @return [CMSQuery]
108
+ # @return [Railspress::CMS::Query]
149
109
  def cms
150
- CmsHelper::CMSQuery.new
110
+ Railspress::CMS::Query.new
151
111
  end
152
112
 
153
113
  private
@@ -304,16 +264,4 @@ module Railspress
304
264
  .rp-inline-actions__admin-link:hover { color: #3b82f6; }
305
265
  CSS
306
266
  end
307
-
308
- # Global CMS module for chainable API access outside views.
309
- # Usage: Railspress::CMS.find("group").load("element").value
310
- module CMS
311
- def self.find(group_name)
312
- unless Railspress.cms_enabled?
313
- raise Railspress::ConfigurationError,
314
- "CMS is not enabled. Add `config.enable_cms` to your Railspress initializer."
315
- end
316
- CmsHelper::CMSQuery.new.find(group_name)
317
- end
318
- end
319
267
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Railspress
4
+ # Chainable API for content element retrieval.
5
+ #
6
+ # Usage:
7
+ # Railspress::CMS.find("Homepage").load("Hero H1").value
8
+ # Railspress::CMS.find("Homepage").load("Hero H1").element
9
+ module CMS
10
+ class Query
11
+ def initialize
12
+ @group_name = nil
13
+ @element_name = nil
14
+ end
15
+
16
+ def find(group_name)
17
+ @group_name = group_name
18
+ self
19
+ end
20
+
21
+ def load(element_name)
22
+ @element_name = element_name
23
+ self
24
+ end
25
+
26
+ def element
27
+ return nil unless @group_name && @element_name
28
+
29
+ cache_key = "#{@group_name}:#{@element_name}"
30
+ cached = CMS.cache[cache_key]
31
+ return cached if cached
32
+
33
+ group = Railspress::ContentGroup.active.find_by(name: @group_name)
34
+ return nil unless group
35
+
36
+ found = group.content_elements.active.find_by(name: @element_name)
37
+ CMS.cache[cache_key] = found if found
38
+ found
39
+ rescue ActiveRecord::RecordNotFound
40
+ nil
41
+ end
42
+
43
+ def value
44
+ element&.value
45
+ end
46
+ end
47
+
48
+ def self.cache
49
+ @cache ||= {}
50
+ end
51
+
52
+ def self.clear_cache
53
+ @cache = {}
54
+ end
55
+
56
+ def self.find(group_name)
57
+ unless Railspress.cms_enabled?
58
+ raise Railspress::ConfigurationError,
59
+ "CMS is not enabled. Add `config.enable_cms` to your Railspress initializer."
60
+ end
61
+
62
+ Query.new.find(group_name)
63
+ end
64
+ end
65
+ end
@@ -15,6 +15,8 @@ module Railspress
15
15
 
16
16
  # Make CMS helper available to host application views (or stub when disabled)
17
17
  initializer "railspress.cms_helper" do
18
+ ActiveSupport::Dependencies.require_dependency(root.join("app/helpers/railspress/cms_helper").to_s)
19
+
18
20
  ActiveSupport.on_load(:action_view) do
19
21
  if Railspress.cms_enabled?
20
22
  include Railspress::CmsHelper
@@ -1,3 +1,3 @@
1
1
  module Railspress
2
- VERSION = "1.3.2"
2
+ VERSION = "1.3.3"
3
3
  end
data/lib/railspress.rb CHANGED
@@ -6,6 +6,8 @@ require "lexxy"
6
6
  module Railspress
7
7
  class ConfigurationError < StandardError; end
8
8
 
9
+ require "railspress/cms"
10
+
9
11
  class Configuration
10
12
  attr_accessor :author_class_name,
11
13
  :current_author_method,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railspress-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avi Flombaum
@@ -307,6 +307,7 @@ files:
307
307
  - lib/generators/railspress/install/templates/initializer.rb
308
308
  - lib/railspress-engine.rb
309
309
  - lib/railspress.rb
310
+ - lib/railspress/cms.rb
310
311
  - lib/railspress/engine.rb
311
312
  - lib/railspress/entity.rb
312
313
  - lib/railspress/version.rb
@@ -351,7 +352,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
351
352
  - !ruby/object:Gem::Version
352
353
  version: '0'
353
354
  requirements: []
354
- rubygems_version: 4.0.6
355
+ rubygems_version: 4.0.14
355
356
  specification_version: 4
356
357
  summary: A mountable blog + CMS engine for Rails 8+
357
358
  test_files: []