sitepress-rails 4.0.2 → 4.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sitepress/engine.rb +14 -6
- data/lib/sitepress/routing_mapper.rb +2 -2
- data/rails/app/controllers/concerns/sitepress/site_pages.rb +29 -18
- data/spec/dummy/log/test.log +44375 -8185
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e52a5129966fa3d7c603ae1ba2eecc190a5253341f727c1f50f63b091ca0f719
|
4
|
+
data.tar.gz: a2d1edec8406017193c328df2f79ad3c1e6a71b929071a0f7ba90fa7c3ba44f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03f239c1317da796ba12e152f41c242859ec254cca06591a848997de3ced52ff48176ee628eb4f89d51400e39d6108a7a575cf26d58a4f6f6adc10a1c5a44b7c
|
7
|
+
data.tar.gz: 6cfad8a7a9938ed295bcf8f2982ae6b6d61e792132e5bc44228ea756ed3c5682384d7a180b89ce4a974565d3e27c16b2bed097a49dde31ff008ae2763b6852e8
|
data/lib/sitepress/engine.rb
CHANGED
@@ -45,13 +45,21 @@ module Sitepress
|
|
45
45
|
# Configure Sitepress with Rails settings.
|
46
46
|
initializer :configure_sitepress do |app|
|
47
47
|
sitepress_configuration.parent_engine = app
|
48
|
-
# Reloads entire site between requests for development environments
|
49
|
-
sitepress_configuration.cache_resources = app.config.
|
50
|
-
|
48
|
+
# Reloads entire site between requests for development environments.
|
49
|
+
sitepress_configuration.cache_resources = if app.config.respond_to? :enable_reloading?
|
50
|
+
# Rails 7.1 changed the name of this setting to enable_reloading, so check if that exist and use it.
|
51
|
+
app.config.enable_reloading?
|
52
|
+
else
|
53
|
+
# Rails 7.0.x and lower all use this method to check if reloading is enabled.
|
54
|
+
app.config.cache_classes
|
55
|
+
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
57
|
+
# Setup Sitepress to handle Rails extensions.
|
58
|
+
ActiveSupport.on_load(:action_view) do
|
59
|
+
ActiveSupport.on_load(:after_initialize) do
|
60
|
+
Sitepress::Path.handler_extensions = ActionView::Template::Handlers.extensions
|
61
|
+
end
|
62
|
+
end
|
55
63
|
end
|
56
64
|
|
57
65
|
private
|
@@ -8,11 +8,11 @@ module ActionDispatch::Routing
|
|
8
8
|
ROUTE_GLOB_KEY = "/*resource_path".freeze
|
9
9
|
|
10
10
|
# Hook up all the Sitepress pages
|
11
|
-
def sitepress_pages(controller: DEFAULT_CONTROLLER, action: DEFAULT_ACTION, root: false, constraints: Sitepress::RouteConstraint.new)
|
11
|
+
def sitepress_pages(controller: DEFAULT_CONTROLLER, action: DEFAULT_ACTION, root: false, constraints: Sitepress::RouteConstraint.new, as: :page)
|
12
12
|
get ROUTE_GLOB_KEY,
|
13
13
|
controller: controller,
|
14
14
|
action: action,
|
15
|
-
as:
|
15
|
+
as: as,
|
16
16
|
format: false,
|
17
17
|
constraints: constraints
|
18
18
|
|
@@ -18,14 +18,13 @@ module Sitepress
|
|
18
18
|
rescue_from Sitepress::ResourceNotFound, with: :resource_not_found
|
19
19
|
helper Sitepress::Engine.helpers
|
20
20
|
helper_method :current_page, :site, :page_rendition
|
21
|
-
|
22
|
-
around_action :ensure_site_reload, only: :show
|
21
|
+
around_action :ensure_site_reload
|
23
22
|
end
|
24
23
|
|
25
24
|
# Public method that is primarily called by Rails to display the page. This should
|
26
25
|
# be hooked up to the Rails routes file.
|
27
26
|
def show
|
28
|
-
render_resource
|
27
|
+
render_resource requested_resource
|
29
28
|
end
|
30
29
|
|
31
30
|
protected
|
@@ -35,6 +34,9 @@ module Sitepress
|
|
35
34
|
# file and serve it up.
|
36
35
|
def render_resource(resource)
|
37
36
|
if resource.renderable?
|
37
|
+
# Set this as our "top-level" resource. We might change it again in the pre-render
|
38
|
+
# method to deal with rendering resources inside of resources.
|
39
|
+
@current_resource = resource
|
38
40
|
render_resource_with_handler resource
|
39
41
|
else
|
40
42
|
send_binary_resource resource
|
@@ -54,7 +56,10 @@ module Sitepress
|
|
54
56
|
# contained in a way that the end user can override, we coupled the resource, source
|
55
57
|
# and output within a `Rendition` object so that it may be processed via hooks.
|
56
58
|
def render_resource_with_handler(resource)
|
57
|
-
|
59
|
+
# Add the resource path to the view path so that partials can be rendered
|
60
|
+
append_relative_partial_path resource
|
61
|
+
|
62
|
+
rendition = page_rendition(resource, layout: controller_layout(resource))
|
58
63
|
|
59
64
|
# Fire a callback in the controller in case anybody needs it.
|
60
65
|
process_rendition rendition
|
@@ -65,9 +70,16 @@ module Sitepress
|
|
65
70
|
|
66
71
|
# This is where the actual rendering happens for the page source in Rails.
|
67
72
|
def pre_render(rendition)
|
68
|
-
|
69
|
-
|
70
|
-
|
73
|
+
original_resource = @current_resource
|
74
|
+
begin
|
75
|
+
# This sets the `current_page` and `current_resource` variable equal to the given resource.
|
76
|
+
@current_resource = rendition.resource
|
77
|
+
rendition.output = render_to_string inline: rendition.source,
|
78
|
+
type: rendition.handler,
|
79
|
+
layout: rendition.layout
|
80
|
+
ensure
|
81
|
+
@current_resource = original_resource
|
82
|
+
end
|
71
83
|
end
|
72
84
|
|
73
85
|
# This is to be used by end users if they need to do any post-processing on the rendering page.
|
@@ -84,9 +96,8 @@ module Sitepress
|
|
84
96
|
end
|
85
97
|
|
86
98
|
# A reference to the current resource that's being requested.
|
87
|
-
|
88
|
-
|
89
|
-
end
|
99
|
+
attr_reader :current_resource
|
100
|
+
|
90
101
|
# In templates resources are more naturally thought of as pages, so we call it `current_page` from
|
91
102
|
# there and from the controller.
|
92
103
|
alias :current_page :current_resource
|
@@ -108,8 +119,8 @@ module Sitepress
|
|
108
119
|
private
|
109
120
|
# This makes it possible to render partials from the current resource with relative
|
110
121
|
# paths. Without this the paths would have to be absolute.
|
111
|
-
def append_relative_partial_path
|
112
|
-
append_view_path
|
122
|
+
def append_relative_partial_path(resource)
|
123
|
+
append_view_path resource.asset.path.dirname
|
113
124
|
end
|
114
125
|
|
115
126
|
def send_binary_resource(resource)
|
@@ -132,7 +143,7 @@ module Sitepress
|
|
132
143
|
|
133
144
|
# Default finder of the resource for the current controller context. If the :resource_path
|
134
145
|
# isn't present, then its probably the root path so grab that.
|
135
|
-
def
|
146
|
+
def requested_resource
|
136
147
|
get resource_request_path
|
137
148
|
end
|
138
149
|
|
@@ -144,13 +155,13 @@ module Sitepress
|
|
144
155
|
# Returns the current layout for the inline Sitepress renderer. This is
|
145
156
|
# exposed via some really convoluted private methods inside of the various
|
146
157
|
# versions of Rails, so I try my best to hack out the path to the layout below.
|
147
|
-
def controller_layout
|
158
|
+
def controller_layout(resource)
|
148
159
|
private_layout_method = self.method(:_layout)
|
149
160
|
layout =
|
150
161
|
if Rails.version >= "6"
|
151
|
-
private_layout_method.call lookup_context,
|
162
|
+
private_layout_method.call lookup_context, resource_rails_formats(resource)
|
152
163
|
elsif Rails.version >= "5"
|
153
|
-
private_layout_method.call
|
164
|
+
private_layout_method.call resource_rails_formats(resource)
|
154
165
|
else
|
155
166
|
private_layout_method.call
|
156
167
|
end
|
@@ -170,8 +181,8 @@ module Sitepress
|
|
170
181
|
# method returns the intersection of the formats Rails supports from Mime::Types
|
171
182
|
# and the current page's node formats. If nothing intersects, HTML is returned
|
172
183
|
# as a default.
|
173
|
-
def
|
174
|
-
node_formats =
|
184
|
+
def resource_rails_formats(resource)
|
185
|
+
node_formats = resource.node.formats
|
175
186
|
supported_formats = node_formats & Mime::EXTENSION_LOOKUP.keys
|
176
187
|
|
177
188
|
if supported_formats.empty?
|