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 +4 -4
- data/app/lib/panda_cms/demo_site_generator.rb +2 -18
- data/app/models/panda_cms/template.rb +31 -33
- data/lib/panda_cms/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66117a36fa0ee06ce08670baa4b54eae990054f9bc0c80091ca6e97a67b6ce28
|
4
|
+
data.tar.gz: a7d7c50fd4a0c65f157bde152fef22c6a632c8878f67de9c73fbeb91fa02acf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
23
|
+
PandaCms::Template.find_or_create_by!(template)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
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
|
-
|
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
|
data/lib/panda_cms/version.rb
CHANGED
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.
|
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-
|
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
|