sitepress-rails 4.0.9 → 4.1.0
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 +4 -4
- data/lib/sitepress/engine.rb +50 -23
- data/lib/sitepress/model.rb +19 -5
- data/lib/sitepress/models/collection.rb +8 -13
- data/rails/app/controllers/concerns/sitepress/site_pages.rb +3 -4
- data/rails/lib/generators/sitepress/install/install_generator.rb +16 -1
- data/rails/lib/generators/sitepress/install/templates/pages/index.html.erb +1 -1
- data/spec/dummy/log/test.log +6811 -0
- data/spec/sitepress/collection_spec.rb +281 -0
- data/spec/sitepress/model_spec.rb +118 -0
- data/spec/sitepress/sitepress_site_controller_spec.rb +23 -2
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: de65ed0cb60dae87a90fb914dd4dfd5183d4eccd6286e071d556533d1501e184
|
|
4
|
+
data.tar.gz: 4b0d4add465aea7037216b26dffbebf7ea000624740e8b5ab893acd97fa7cd65
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3895c25f0bba45c456c28e6204650d8d15034609b1f8b5c14e7f86126aa9f7b12acab20c9baacc93f667aa406fae24bdfbbc60c90b30224a9f5f843f19cf5491
|
|
7
|
+
data.tar.gz: 5769f5831e3039e05835e5fd1a308df25621d3ac947b36d1ae3b39b13a3c7dcd892d594d745070d6fdb4246e406b92b5249777bbcea5f415660634a89e132f41
|
data/lib/sitepress/engine.rb
CHANGED
|
@@ -13,7 +13,7 @@ module Sitepress
|
|
|
13
13
|
]
|
|
14
14
|
|
|
15
15
|
# Load the `config/site.rb` file so users can configure Sitepress.
|
|
16
|
-
initializer
|
|
16
|
+
initializer "sitepress.load_site_file", before: "sitepress.set_paths" do
|
|
17
17
|
site_file = paths["config/site.rb"].existent.first
|
|
18
18
|
load site_file if site_file
|
|
19
19
|
end
|
|
@@ -24,49 +24,76 @@ module Sitepress
|
|
|
24
24
|
"app/markdown" # When Sitepress is launched embedded in Rails project.
|
|
25
25
|
], autoload: true
|
|
26
26
|
|
|
27
|
-
# Load paths from `Sitepress#site` into
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
# Load paths from `Sitepress#site` into Rails.
|
|
28
|
+
#
|
|
29
|
+
# We configure two separate systems:
|
|
30
|
+
#
|
|
31
|
+
# 1. app.paths["app/*"] - Rails component path registry
|
|
32
|
+
# Tells ActionView where to find templates, ActionController where to find helpers, etc.
|
|
33
|
+
#
|
|
34
|
+
# 2. config.autoload_paths - Zeitwerk autoloader configuration
|
|
35
|
+
# Tells Zeitwerk what to autoload. Rails automatically includes these in
|
|
36
|
+
# config.eager_load_paths for production environments.
|
|
37
|
+
#
|
|
38
|
+
initializer "sitepress.set_paths", before: :set_autoload_paths do |app|
|
|
39
|
+
site = Sitepress.configuration.site
|
|
40
|
+
|
|
41
|
+
# Helpers: autoloadable and available to controllers
|
|
42
|
+
# Collapsed so app/content/helpers/sample_helper.rb defines SampleHelper (not Helpers::SampleHelper)
|
|
43
|
+
site.helpers_path.expand_path.tap do |path|
|
|
44
|
+
app.paths["app/helpers"].push path
|
|
45
|
+
app.config.autoload_paths << path
|
|
46
|
+
app.config.eager_load_paths << path
|
|
47
|
+
Rails.autoloaders.main.collapse(path)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Models: autoloadable
|
|
51
|
+
# Collapsed so models don't require namespace prefixes
|
|
52
|
+
site.models_path.expand_path.tap do |path|
|
|
53
|
+
app.paths["app/models"].push path
|
|
54
|
+
app.config.autoload_paths << path
|
|
55
|
+
app.config.eager_load_paths << path
|
|
56
|
+
Rails.autoloaders.main.collapse(path)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Assets: available to Sprockets (no autoloading needed)
|
|
30
60
|
app.paths["app/assets"].push site.assets_path.expand_path
|
|
61
|
+
|
|
62
|
+
# Views: available to ActionView (no autoloading needed - these are templates)
|
|
31
63
|
app.paths["app/views"].push site.root_path.expand_path
|
|
32
64
|
app.paths["app/views"].push site.pages_path.expand_path
|
|
33
|
-
app.paths["app/models"].push site.models_path.expand_path
|
|
34
65
|
|
|
35
|
-
#
|
|
66
|
+
# Components: autoloadable for view_components
|
|
36
67
|
app.config.autoload_paths << File.expand_path("./components")
|
|
37
68
|
end
|
|
38
69
|
|
|
39
70
|
# Configure sprockets paths for the site.
|
|
40
|
-
initializer
|
|
41
|
-
manifest_file =
|
|
71
|
+
initializer "sitepress.set_manifest_file_path", before: :append_assets_path do |app|
|
|
72
|
+
manifest_file = Sitepress.configuration.manifest_file_path.expand_path
|
|
42
73
|
app.config.assets.precompile << manifest_file.to_s if manifest_file.exist?
|
|
43
74
|
end
|
|
44
75
|
|
|
45
76
|
# Configure Sitepress with Rails settings.
|
|
46
|
-
initializer
|
|
47
|
-
|
|
77
|
+
initializer "sitepress.configure" do |app|
|
|
78
|
+
Sitepress.configuration.parent_engine = app
|
|
48
79
|
# Reloads entire site between requests for development environments.
|
|
49
|
-
|
|
80
|
+
Sitepress.configuration.cache_resources = if app.config.respond_to? :enable_reloading?
|
|
50
81
|
# Rails 7.1 changed the name of this setting to enable_reloading, so check if that exist and use it.
|
|
51
82
|
app.config.enable_reloading?
|
|
52
83
|
else
|
|
53
84
|
# Rails 7.0.x and lower all use this method to check if reloading is enabled.
|
|
54
85
|
app.config.cache_classes
|
|
55
86
|
end
|
|
56
|
-
|
|
57
|
-
config.to_prepare do
|
|
58
|
-
Sitepress::Path.handler_extensions = ActionView::Template::Handlers.extensions
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
private
|
|
63
|
-
|
|
64
|
-
def sitepress_configuration
|
|
65
|
-
Sitepress.configuration
|
|
66
87
|
end
|
|
67
88
|
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
# Set handler extensions once, after ActionView and all template engines are loaded.
|
|
90
|
+
initializer "sitepress.set_handler_extensions" do
|
|
91
|
+
ActiveSupport.on_load(:action_view) do
|
|
92
|
+
ActiveSupport.on_load(:after_initialize) do
|
|
93
|
+
Sitepress::Path.handler_extensions =
|
|
94
|
+
ActionView::Template::Handlers.extensions
|
|
95
|
+
end
|
|
96
|
+
end
|
|
70
97
|
end
|
|
71
98
|
end
|
|
72
99
|
end
|
data/lib/sitepress/model.rb
CHANGED
|
@@ -29,15 +29,23 @@ module Sitepress
|
|
|
29
29
|
# Defines a class method that may be called later to return a
|
|
30
30
|
# collection of objects. The default glob, for example, is named `:all`,
|
|
31
31
|
# which defines `MyModel.all` on the class.
|
|
32
|
-
def collection(name =
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
def collection(name = :all, glob: nil, **, &)
|
|
33
|
+
if block_given?
|
|
34
|
+
build_collection(&)
|
|
35
|
+
else
|
|
36
|
+
ActiveSupport::Deprecation.new.warn(
|
|
37
|
+
"The `collection :#{name}, glob: ...` macro is deprecated. " \
|
|
38
|
+
"Use `def self.#{name} = glob('#{glob}')` instead."
|
|
39
|
+
)
|
|
40
|
+
define_singleton_method name do
|
|
41
|
+
self.glob glob, **
|
|
42
|
+
end
|
|
35
43
|
end
|
|
36
44
|
end
|
|
37
45
|
|
|
38
46
|
# Adhoc querying of models via `Model.glob("foo/bar").all`
|
|
39
|
-
def glob(glob, **
|
|
40
|
-
|
|
47
|
+
def glob(glob, **)
|
|
48
|
+
build_collection(model: self, **){ site.glob(glob) }
|
|
41
49
|
end
|
|
42
50
|
|
|
43
51
|
# Wraps a page in a class if given a string that represents the path or
|
|
@@ -67,6 +75,12 @@ module Sitepress
|
|
|
67
75
|
def site
|
|
68
76
|
Sitepress.site
|
|
69
77
|
end
|
|
78
|
+
|
|
79
|
+
private
|
|
80
|
+
|
|
81
|
+
def build_collection(*, model: self, **, &)
|
|
82
|
+
Models::Collection.new(*, model:, **, &)
|
|
83
|
+
end
|
|
70
84
|
end
|
|
71
85
|
end
|
|
72
86
|
end
|
|
@@ -5,28 +5,23 @@ module Sitepress
|
|
|
5
5
|
class Collection
|
|
6
6
|
include Enumerable
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
DEFAULT_NAME = :all
|
|
8
|
+
attr_reader :model
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
DEFAULT_GLOB = "**/*.*".freeze
|
|
13
|
-
|
|
14
|
-
attr_reader :model, :glob, :site
|
|
15
|
-
|
|
16
|
-
def initialize(model:, site:, glob: DEFAULT_GLOB)
|
|
10
|
+
def initialize(model:, &resources)
|
|
17
11
|
@model = model
|
|
18
|
-
@
|
|
19
|
-
@site = site
|
|
12
|
+
@resources = resources
|
|
20
13
|
end
|
|
21
14
|
|
|
22
15
|
def resources
|
|
23
|
-
|
|
16
|
+
@resources.call
|
|
24
17
|
end
|
|
25
18
|
|
|
26
19
|
# Wraps each resource in a model object.
|
|
27
|
-
def each
|
|
20
|
+
def each(&block)
|
|
21
|
+
return to_enum(:each) unless block_given?
|
|
22
|
+
|
|
28
23
|
resources.each do |resource|
|
|
29
|
-
yield model.new
|
|
24
|
+
yield model.new(resource)
|
|
30
25
|
end
|
|
31
26
|
end
|
|
32
27
|
end
|
|
@@ -16,7 +16,6 @@ module Sitepress
|
|
|
16
16
|
|
|
17
17
|
included do
|
|
18
18
|
rescue_from Sitepress::ResourceNotFound, with: :resource_not_found
|
|
19
|
-
helper Sitepress::Engine.helpers
|
|
20
19
|
helper_method :current_page, :site
|
|
21
20
|
around_action :ensure_site_reload
|
|
22
21
|
end
|
|
@@ -125,10 +124,10 @@ module Sitepress
|
|
|
125
124
|
# For whatever reason, Rails can't stablize this API so we need to check
|
|
126
125
|
# the version of Rails to make the right call and stablize it.
|
|
127
126
|
def find_layout(formats:)
|
|
128
|
-
case
|
|
129
|
-
when
|
|
127
|
+
case method(:_layout).arity
|
|
128
|
+
when 3
|
|
130
129
|
_layout(lookup_context, formats, lookup_context.prefixes)
|
|
131
|
-
|
|
130
|
+
when 2
|
|
132
131
|
_layout(lookup_context, formats)
|
|
133
132
|
end
|
|
134
133
|
end
|
|
@@ -2,6 +2,8 @@ module Sitepress
|
|
|
2
2
|
class InstallGenerator < Rails::Generators::Base
|
|
3
3
|
source_root File.expand_path("templates", __dir__)
|
|
4
4
|
|
|
5
|
+
class_option :skip_markdown, type: :boolean, default: false, desc: "Skip adding markdown-rails gem"
|
|
6
|
+
|
|
5
7
|
def copy_files
|
|
6
8
|
directory ".", "app/content"
|
|
7
9
|
end
|
|
@@ -12,9 +14,22 @@ module Sitepress
|
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def append_sitepress_path_to_tailwind_config
|
|
17
|
+
# Tailwind v3
|
|
15
18
|
if File.exist? 'config/tailwind.config.js'
|
|
16
|
-
inject_into_file 'config/tailwind.config.js', ",\n './app/content
|
|
19
|
+
inject_into_file 'config/tailwind.config.js', ",\n './app/content/**/*.*'",
|
|
17
20
|
after: " './app/views/**/*.{erb,haml,html,slim}'"
|
|
21
|
+
# Tailwind v4
|
|
22
|
+
elsif File.exist? 'app/assets/tailwind/application.css'
|
|
23
|
+
inject_into_file 'app/assets/tailwind/application.css', "\n@source \"../../content/**/*.*\";",
|
|
24
|
+
after: "@import \"tailwindcss\";"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def add_markdown_rails_gem
|
|
29
|
+
unless options[:skip_markdown]
|
|
30
|
+
gem "markdown-rails"
|
|
31
|
+
say "Added markdown-rails gem to Gemfile", :green
|
|
32
|
+
say "Run 'bundle install' to install the gem", :yellow
|
|
18
33
|
end
|
|
19
34
|
end
|
|
20
35
|
end
|
|
@@ -45,7 +45,7 @@ title: Getting started with Sitepress in Rails
|
|
|
45
45
|
<p>This was generated by the <code>rails generate sitepress:install</code> command.</p>
|
|
46
46
|
|
|
47
47
|
<h2>Content</h2>
|
|
48
|
-
<p>Sitepress content files are in <code><%= site.root_path.expand_path %></code>. There you can edit site content, including this file at <code><%= current_page.asset.path %></code
|
|
48
|
+
<p>Sitepress content files are in <code><%= site.root_path.expand_path %></code>. There you can edit site content, including this file at <code><%= current_page.asset.path %></code>.</p>
|
|
49
49
|
|
|
50
50
|
<h2>Routes</h2>
|
|
51
51
|
<p>Sitepress defined a root route in <code><%= Rails.root.join("config/routes.rb") %></code>. If that conflicts with your routes configuration, you'll want to open it and edit accordingly.</p>
|