sitepress-rails 4.0.5 → 4.0.6
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 +2 -5
- data/lib/sitepress/rails.rb +0 -1
- data/rails/app/controllers/concerns/sitepress/site_pages.rb +8 -78
- data/rails/lib/generators/sitepress/controller/templates/controllers/site_controller.rb +0 -11
- data/sitepress-rails.gemspec +1 -1
- data/spec/dummy/log/test.log +12983 -40632
- data/spec/sitepress/sitepress_site_controller_spec.rb +1 -5
- metadata +11 -16
- data/lib/sitepress/rendition.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a19ae6fa84afd56632baf90af377e18dbe8374abf482622bd7830a1ed489e8d1
|
4
|
+
data.tar.gz: 86a015c072a56d17595588c5d6bd547e264054a5ed2c752dfdc0e2c07c058dcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e218c3abb19c61323938b506b8613bfac2e721e4dd62330c72ab19531110e73d1e3cd49812244a9a183911634b956c2a7c17006b9fe1e412fb6bf7dab05df351
|
7
|
+
data.tar.gz: 07c3d578d2bb4749f8087c7bb6958e3bc8d7e79d50b553a05f5d38f302aa1434629f19fca12a59b4a1503f8cafd29a3b3e33515339f20591c2a2c0425acb189a
|
data/lib/sitepress/engine.rb
CHANGED
@@ -54,11 +54,8 @@ module Sitepress
|
|
54
54
|
app.config.cache_classes
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
ActiveSupport.on_load(:after_initialize) do
|
60
|
-
Sitepress::Path.handler_extensions = ActionView::Template::Handlers.extensions
|
61
|
-
end
|
57
|
+
config.to_prepare do
|
58
|
+
Sitepress::Path.handler_extensions = ActionView::Template::Handlers.extensions
|
62
59
|
end
|
63
60
|
end
|
64
61
|
|
data/lib/sitepress/rails.rb
CHANGED
@@ -11,7 +11,6 @@ module Sitepress
|
|
11
11
|
autoload :Controller, "sitepress/renderers/controller"
|
12
12
|
autoload :Server, "sitepress/renderers/server"
|
13
13
|
end
|
14
|
-
autoload :Rendition, "sitepress/rendition"
|
15
14
|
autoload :RouteConstraint, "sitepress/route_constraint"
|
16
15
|
module BuildPaths
|
17
16
|
autoload :RootPath, "sitepress/build_paths/root_path"
|
@@ -17,7 +17,7 @@ module Sitepress
|
|
17
17
|
included do
|
18
18
|
rescue_from Sitepress::ResourceNotFound, with: :resource_not_found
|
19
19
|
helper Sitepress::Engine.helpers
|
20
|
-
helper_method :current_page, :site
|
20
|
+
helper_method :current_page, :site
|
21
21
|
around_action :ensure_site_reload
|
22
22
|
end
|
23
23
|
|
@@ -43,56 +43,12 @@ module Sitepress
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
# Renders the markup within a resource that can be rendered.
|
47
|
-
def page_rendition(resource, layout: nil)
|
48
|
-
Rendition.new(resource).tap do |rendition|
|
49
|
-
rendition.layout = layout
|
50
|
-
pre_render rendition
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
46
|
# If a resource has a handler (e.g. erb, haml, etc.) we use the Rails renderer to
|
55
47
|
# process templates, layouts, partials, etc. To keep the whole rendering process
|
56
48
|
# contained in a way that the end user can override, we coupled the resource, source
|
57
49
|
# and output within a `Rendition` object so that it may be processed via hooks.
|
58
50
|
def render_resource_with_handler(resource)
|
59
|
-
|
60
|
-
append_relative_partial_path resource
|
61
|
-
|
62
|
-
rendition = page_rendition(resource, layout: controller_layout(resource))
|
63
|
-
|
64
|
-
# Fire a callback in the controller in case anybody needs it.
|
65
|
-
process_rendition rendition
|
66
|
-
|
67
|
-
# Now we finally render the output of the processed rendition to the client.
|
68
|
-
post_render rendition
|
69
|
-
end
|
70
|
-
|
71
|
-
# This is where the actual rendering happens for the page source in Rails.
|
72
|
-
def pre_render(rendition)
|
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
|
83
|
-
end
|
84
|
-
|
85
|
-
# This is to be used by end users if they need to do any post-processing on the rendering page.
|
86
|
-
# For example, the user may use Nokogiri to parse static HTML pages and hook it into the asset pipeline.
|
87
|
-
# They may also use tools like `HTMLPipeline` to process links from a markdown renderer.
|
88
|
-
def process_rendition(rendition)
|
89
|
-
# Do nothing unless the user extends this method.
|
90
|
-
end
|
91
|
-
|
92
|
-
# Send the inline rendered, post-processed string into the Rails rendering method that actually sends
|
93
|
-
# the output to the end-user as a web response.
|
94
|
-
def post_render(rendition)
|
95
|
-
render body: rendition.output, content_type: rendition.mime_type
|
51
|
+
render resource, layout: resource_layout(resource)
|
96
52
|
end
|
97
53
|
|
98
54
|
# A reference to the current resource that's being requested.
|
@@ -155,40 +111,14 @@ module Sitepress
|
|
155
111
|
# Returns the current layout for the inline Sitepress renderer. This is
|
156
112
|
# exposed via some really convoluted private methods inside of the various
|
157
113
|
# versions of Rails, so I try my best to hack out the path to the layout below.
|
158
|
-
def
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
elsif Rails.version >= "5"
|
164
|
-
private_layout_method.call resource_rails_formats(resource)
|
114
|
+
def resource_layout(resource)
|
115
|
+
resource.data.fetch "layout" do
|
116
|
+
case template = _layout(lookup_context, resource.node.formats)
|
117
|
+
when ActionView::Template
|
118
|
+
template.virtual_path
|
165
119
|
else
|
166
|
-
|
120
|
+
template
|
167
121
|
end
|
168
|
-
|
169
|
-
if layout.instance_of? String # Rails 4 and 5 return a string from above.
|
170
|
-
layout
|
171
|
-
elsif layout # Rails 3 and older return an object that gives us a file name
|
172
|
-
File.basename(layout.identifier).split('.').first
|
173
|
-
else
|
174
|
-
# If none of the conditions are met, then no layout was
|
175
|
-
# specified, so nil is returned.
|
176
|
-
nil
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# Rails 5 requires an extension, like `:html`, to resolve a template. This
|
181
|
-
# method returns the intersection of the formats Rails supports from Mime::Types
|
182
|
-
# and the current page's node formats. If nothing intersects, HTML is returned
|
183
|
-
# as a default.
|
184
|
-
def resource_rails_formats(resource)
|
185
|
-
node_formats = resource.node.formats
|
186
|
-
supported_formats = node_formats & Mime::EXTENSION_LOOKUP.keys
|
187
|
-
|
188
|
-
if supported_formats.empty?
|
189
|
-
DEFAULT_PAGE_RAILS_FORMATS
|
190
|
-
else
|
191
|
-
supported_formats.map?(&:to_sym)
|
192
122
|
end
|
193
123
|
end
|
194
124
|
|
@@ -3,15 +3,4 @@ class SiteController < Sitepress::SiteController
|
|
3
3
|
def show
|
4
4
|
render_resource current_resource
|
5
5
|
end
|
6
|
-
|
7
|
-
protected
|
8
|
-
|
9
|
-
# This is to be used by end users if they need to do any post-processing on the rendering page.
|
10
|
-
# For example, the user may use Nokogiri to parse static HTML pages and hook it into the asset pipeline.
|
11
|
-
# They may also use tools like `HTMLPipeline` to process links from a markdown renderer.
|
12
|
-
#
|
13
|
-
# For example, the rendition could be modified via `Nokogiri::HTML5::DocumentFragment(rendition)`.
|
14
|
-
def process_rendition(rendition)
|
15
|
-
# Do nothing unless the user extends this method.
|
16
|
-
end
|
17
6
|
end
|
data/sitepress-rails.gemspec
CHANGED