panda_cms 0.5.1 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/app/lib/panda_cms/demo_site_generator.rb +13 -21
- data/app/models/panda_cms/template.rb +34 -34
- data/config/initializers/panda_cms.rb +5 -3
- 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: a11f50a60d457d8a5b4eba37c270535516599a39d78c242f9711990d8f810799
|
4
|
+
data.tar.gz: 4f33c57dcb79a3b2eeaafbf58584221a1000e05b05e0058abd401a80eb530c6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4203b15127f62ef99db77ddd54f1f6c5b5c0c47d3754957be010474aeaa11918e3efbe9d293946dd35cdbbb0fa83515c5797c3e1286c900a1a46a1a5fc159cc3
|
7
|
+
data.tar.gz: efdccb2f2ab99172a1b30e73dfa85ca59bed4f616bb67d1fe613bb50f1fe8d63c4333029eb8834b126f2ed68c41436edef535451f99ee27d4cb00e2fa6d332c3
|
data/README.md
CHANGED
@@ -16,7 +16,9 @@ Better websites, on Rails.
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
|
19
|
+
### New applications
|
20
|
+
|
21
|
+
To create a new Rails app, run the command below, replacing `demo` with the name of the application you want to create:
|
20
22
|
|
21
23
|
```
|
22
24
|
rails new demo $(curl -fsSL https://raw.githubusercontent.com/pandacms/generator/main/.railsrc) -m https://raw.githubusercontent.com/pandacms/generator/main/template.rb
|
@@ -26,6 +28,8 @@ rails new demo $(curl -fsSL https://raw.githubusercontent.com/pandacms/generator
|
|
26
28
|
|
27
29
|
The easiest way for you to get started is to visit http://localhost:3000/admin and login with your GitHub credentials. As the first user, you'll automatically have an administrator account created.
|
28
30
|
|
31
|
+
When you're ready to configure further, you can set your own configuration in `config/initializers/panda_cms.rb`. Make sure to turn off the default `github` account creation options!
|
32
|
+
|
29
33
|
### Existing applications
|
30
34
|
|
31
35
|
Add the following to `Gemfile`:
|
@@ -45,7 +49,7 @@ rails db:seed
|
|
45
49
|
|
46
50
|
You may want to check this does not re-run any of your existing seeds!
|
47
51
|
|
48
|
-
If you don't want to use GitHub to login, you'll need to configure a user provider (in `config/initializers/panda_cms.rb`), and then set your user's `admin` attribute to `true` once you've first tried to login.
|
52
|
+
If you don't want to use GitHub to login (or are at a URL other than http://localhost:3000/), you'll need to configure a user provider (in `config/initializers/panda_cms.rb`), and then set your user's `admin` attribute to `true` once you've first tried to login.
|
49
53
|
|
50
54
|
## Gotchas
|
51
55
|
|
@@ -53,7 +57,6 @@ This is a non-exhuastive list (there will be many more):
|
|
53
57
|
|
54
58
|
* To date, this has only been tested with Rails 7.1 and 7.2.
|
55
59
|
* There may be conflicts if you're not using Tailwind CSS on the frontend. Please report this.
|
56
|
-
* If you change your login path from `/admin` the GitHub application we supply won't work on first login, so probably don't do that until you're setup!
|
57
60
|
|
58
61
|
## Contributing
|
59
62
|
|
@@ -68,5 +71,3 @@ See [Credits](https://github.com/pandacms/panda_cms/blob/main/CREDITS.md) for th
|
|
68
71
|
The gem is available as open source under the terms of the [BSD-3-Clause License](https://opensource.org/licenses/bsd-3-clause).
|
69
72
|
|
70
73
|
Copyright © 2024, Panda Software Limited.
|
71
|
-
|
72
|
-
[^1]: You can of course use an existing Rails app, but on your head be it – we haven't tested this at all yet!
|
@@ -11,7 +11,7 @@ module PandaCms
|
|
11
11
|
#
|
12
12
|
# Creates initial templates and empty blocks
|
13
13
|
#
|
14
|
-
# @return
|
14
|
+
# @return void
|
15
15
|
def create_templates
|
16
16
|
# Templates
|
17
17
|
initial_templates = [
|
@@ -20,26 +20,13 @@ module PandaCms
|
|
20
20
|
]
|
21
21
|
|
22
22
|
initial_templates.each do |template|
|
23
|
-
|
23
|
+
key = template[:name].downcase.to_sym
|
24
|
+
@templates[key] = PandaCms::Template.find_or_create_by!(template)
|
24
25
|
end
|
25
26
|
|
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
|
27
|
+
PandaCms::Template.generate_missing_blocks
|
36
28
|
|
37
|
-
|
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
|
29
|
+
@templates
|
43
30
|
end
|
44
31
|
|
45
32
|
#
|
@@ -50,21 +37,26 @@ module PandaCms
|
|
50
37
|
@pages[:home] = PandaCms::Page.find_or_create_by!({path: "/", title: "Home", template: @templates[:homepage]})
|
51
38
|
@pages[:about] = PandaCms::Page.find_or_create_by!({path: "/about", title: "About", template: @templates[:page], parent: @pages[:home]})
|
52
39
|
@pages[:terms] = PandaCms::Page.find_or_create_by!({path: "/terms-and-conditions", title: "Terms & Conditions", template: @templates[:page], parent: @pages[:home]})
|
40
|
+
|
41
|
+
@pages
|
53
42
|
end
|
54
43
|
|
55
44
|
#
|
56
45
|
# Creates initial menus
|
57
46
|
#
|
58
47
|
# @return [Hash] A hash containing the created menus
|
59
|
-
#
|
60
48
|
def create_menus
|
61
49
|
@menus = {}
|
62
50
|
@menus[:main] = PandaCms::Menu.find_or_create_by!(name: "Main Menu")
|
63
51
|
@menus[:footer] = PandaCms::Menu.find_or_create_by!(name: "Footer Menu")
|
64
52
|
|
65
53
|
# Automatically create main menu from homepage
|
66
|
-
|
67
|
-
|
54
|
+
unless @pages[:home].nil?
|
55
|
+
@menus[:main].update(kind: :auto, start_page: @pages[:home])
|
56
|
+
@menus[:main].generate_auto_menu_items
|
57
|
+
end
|
58
|
+
|
59
|
+
@menus
|
68
60
|
end
|
69
61
|
end
|
70
62
|
end
|
@@ -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
|
@@ -71,7 +39,6 @@ module PandaCms
|
|
71
39
|
# PandaCms::RichTextComponent.new(key: :value)
|
72
40
|
# PandaCms::RichTextComponent.new key: :value, key: value
|
73
41
|
line.match(/PandaCms::([a-zA-Z]+)Component\.new[ \(]+([^\)]+)[\)]*/) do |match|
|
74
|
-
puts "- #{match[0]}"
|
75
42
|
# Extract the hash values
|
76
43
|
template_path = file.gsub("app/views/", "").gsub(".html.erb", "")
|
77
44
|
template_name = template_path.gsub("layouts/", "").titleize
|
@@ -81,6 +48,9 @@ module PandaCms
|
|
81
48
|
template.name = template_name
|
82
49
|
end
|
83
50
|
|
51
|
+
next if match[1] == "PageMenu" # Skip PageMenu blocks
|
52
|
+
next if match[1] == "Menu" # Skip Menu blocks
|
53
|
+
|
84
54
|
# Previously used match[1].underscore but this supports more complex database
|
85
55
|
# operations, and is more secure as it'll force the usage of a class
|
86
56
|
block_kind = "PandaCms::#{match[1]}Component".constantize::KIND
|
@@ -112,6 +82,36 @@ module PandaCms
|
|
112
82
|
end
|
113
83
|
end
|
114
84
|
|
115
|
-
|
85
|
+
private
|
86
|
+
|
87
|
+
# Custom validation method to check if the file_path is a valid layout file path
|
88
|
+
# NB: Currently only supports .html.erb templates, may want to expand in future?
|
89
|
+
# @return [void]
|
90
|
+
def validate_template_file_exists
|
91
|
+
# Remove any directory traversal attempts from the file_path
|
92
|
+
safe_file_path = file_path.to_s.gsub("../", "")
|
93
|
+
# Check if the file_path is an ERB template that exists in app/views
|
94
|
+
template_path = Rails.root.join("app", "views", "#{safe_file_path}.html.erb")
|
95
|
+
# NB: file? checks for files and excludes directories (unlike exist?)
|
96
|
+
errors.add(:file_path, "must be an existing layout file path") unless File.file?(template_path)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Import templates from the filesystem into the database
|
100
|
+
# @return [void]
|
101
|
+
def self.load_from_filesystem
|
102
|
+
Rails.root.glob("app/views/layouts/**/*.html.erb").each do |file|
|
103
|
+
# Extract the file path from the Rails root
|
104
|
+
file_path = file.to_s.sub("#{Rails.root}/app/views/", "").sub(".html.erb", "")
|
105
|
+
|
106
|
+
next if file_path == "layouts/application" || file_path == "layouts/mailer"
|
107
|
+
|
108
|
+
# Find or create the template based on the file path
|
109
|
+
find_or_create_by(file_path: file_path) do |t|
|
110
|
+
t.name = file_path.sub("layouts/", "").titleize
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
private_class_method :load_from_filesystem
|
116
116
|
end
|
117
117
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# Base URL
|
2
|
-
PandaCms.url = "http://localhost:3000"
|
3
1
|
# The main title of your website
|
4
2
|
# The default is "Demo Site"
|
5
3
|
PandaCms.title = "Demo Site"
|
@@ -41,7 +39,11 @@ PandaCms.authentication = {
|
|
41
39
|
github: {
|
42
40
|
enabled: true,
|
43
41
|
create_account_on_first_login: true,
|
44
|
-
create_admin_account_on_first_login:
|
42
|
+
create_admin_account_on_first_login: true,
|
43
|
+
# client_id: Rails.application.credentials.dig(:github, :client_id),
|
44
|
+
# client_secret: Rails.application.credentials.dig(:github, :client_secret),
|
45
|
+
client_id: "Ov23li9k0LpMXtq8FShb", # Will only work on localhost
|
46
|
+
client_secret: "07233b63472b7f287ac11854e627670ddc096a22", # Will only work on localhost
|
45
47
|
redirect_uri: Rails.application.credentials.dig(:github, :redirect_uri)
|
46
48
|
}
|
47
49
|
}
|
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.3
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activestorage-office-previewer
|