panda_cms 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 625476035c61b37e617fe74e22deca62b77522d70c4776663ee0429453bc6ea2
4
- data.tar.gz: 0e5424b52179f8b3f6b0108763399ac65c7b2ed3fc12dc68c0f6721663526547
3
+ metadata.gz: 66117a36fa0ee06ce08670baa4b54eae990054f9bc0c80091ca6e97a67b6ce28
4
+ data.tar.gz: a7d7c50fd4a0c65f157bde152fef22c6a632c8878f67de9c73fbeb91fa02acf5
5
5
  SHA512:
6
- metadata.gz: 852b417dc7bea4ebe4f5c96edfe3937ab435f2a549722349f019b70a147d853b728a2951acebc95a9e67a28fbd907e5625e3b0d84e2b5d6ada7d0a31a1415f47
7
- data.tar.gz: 13c1b3692557a6f9768921029da41d93ba34f6664cb85a9967a2dc6e656cc0db1a56023f07bc28bd8ee23b15fd3a0efeeb2fdae32d3041fa9797e04d28558c28
6
+ metadata.gz: d7f66d163bbde65c92bf600bbd21432f7083b0ff302adef3284b99ea7e233b8309f7e8a022d4b06f5dc513d0e38b795a37aac47691d97fc50ad603f8f8efb9b5
7
+ data.tar.gz: b9cbbcc92f2774f780f50e7faf0b03950a3d87b1f643b783c33bc2514e445be240a090f9b985a7600ec31253b25a79942f4a8c72cf4e7a23703fdbe765f7968a
@@ -20,26 +20,10 @@ module PandaCms
20
20
  ]
21
21
 
22
22
  initial_templates.each do |template|
23
- @templates[template[:name].downcase.to_sym] = PandaCms::Template.find_or_create_by!(template)
23
+ PandaCms::Template.find_or_create_by!(template)
24
24
  end
25
25
 
26
- # Blocks
27
- initial_blocks = [
28
- {kind: "rich_text", name: "Introduction Text", key: "introduction_text", template: @templates[:homepage]},
29
- {kind: "rich_text", name: "Main Content", key: "main_content", template: @templates[:homepage]},
30
- {kind: "rich_text", name: "Main Content", key: "main_content", template: @templates[:page]}
31
- ]
32
-
33
- initial_blocks.each do |block_data|
34
- PandaCms::Block.find_or_create_by!(block_data)
35
- end
36
-
37
- # Empty block contents
38
- PandaCms::Block.find_each do |block|
39
- block.template.pages.each do |page|
40
- PandaCms::BlockContent.find_or_create_by!(page: page, block: block, content: "")
41
- end
42
- end
26
+ PandaCms::Template.generate_missing_blocks
43
27
  end
44
28
 
45
29
  #
@@ -27,38 +27,6 @@ module PandaCms
27
27
  scope :ordered, -> { order(:sort_order) }
28
28
  scope :available, -> { where("max_uses IS NULL OR (pages_count < max_uses)") }
29
29
 
30
- private
31
-
32
- # Custom validation method to check if the file_path is a valid layout file path
33
- # NB: Currently only supports .html.erb templates, may want to expand in future?
34
- # @return [void]
35
- def validate_template_file_exists
36
- # Remove any directory traversal attempts from the file_path
37
- safe_file_path = file_path.to_s.gsub("../", "")
38
- # Check if the file_path is an ERB template that exists in app/views
39
- template_path = Rails.root.join("app", "views", "#{safe_file_path}.html.erb")
40
- # NB: file? checks for files and excludes directories (unlike exist?)
41
- errors.add(:file_path, "must be an existing layout file path") unless File.file?(template_path)
42
- end
43
-
44
- # Import templates from the filesystem into the database
45
- # @return [void]
46
- def self.load_from_filesystem
47
- Rails.root.glob("app/views/layouts/**/*.html.erb").each do |file|
48
- # Extract the file path from the Rails root
49
- file_path = file.to_s.sub("#{Rails.root}/app/views/", "").sub(".html.erb", "")
50
-
51
- next if file_path == "layouts/application" || file_path == "layouts/mailer"
52
-
53
- # Find or create the template based on the file path
54
- find_or_create_by(file_path: file_path) do |t|
55
- t.name = file_path.sub("layouts/", "").titleize
56
- end
57
- end
58
- end
59
-
60
- private_class_method :load_from_filesystem
61
-
62
30
  # Generate missing blocks for all templates
63
31
  # @return [void]
64
32
  def self.generate_missing_blocks
@@ -112,6 +80,36 @@ module PandaCms
112
80
  end
113
81
  end
114
82
 
115
- private_class_method :generate_missing_blocks
83
+ private
84
+
85
+ # Custom validation method to check if the file_path is a valid layout file path
86
+ # NB: Currently only supports .html.erb templates, may want to expand in future?
87
+ # @return [void]
88
+ def validate_template_file_exists
89
+ # Remove any directory traversal attempts from the file_path
90
+ safe_file_path = file_path.to_s.gsub("../", "")
91
+ # Check if the file_path is an ERB template that exists in app/views
92
+ template_path = Rails.root.join("app", "views", "#{safe_file_path}.html.erb")
93
+ # NB: file? checks for files and excludes directories (unlike exist?)
94
+ errors.add(:file_path, "must be an existing layout file path") unless File.file?(template_path)
95
+ end
96
+
97
+ # Import templates from the filesystem into the database
98
+ # @return [void]
99
+ def self.load_from_filesystem
100
+ Rails.root.glob("app/views/layouts/**/*.html.erb").each do |file|
101
+ # Extract the file path from the Rails root
102
+ file_path = file.to_s.sub("#{Rails.root}/app/views/", "").sub(".html.erb", "")
103
+
104
+ next if file_path == "layouts/application" || file_path == "layouts/mailer"
105
+
106
+ # Find or create the template based on the file path
107
+ find_or_create_by(file_path: file_path) do |t|
108
+ t.name = file_path.sub("layouts/", "").titleize
109
+ end
110
+ end
111
+ end
112
+
113
+ private_class_method :load_from_filesystem
116
114
  end
117
115
  end
@@ -1,3 +1,3 @@
1
1
  module PandaCms
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panda_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Panda Software Limited
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-01 00:00:00.000000000 Z
11
+ date: 2024-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activestorage-office-previewer