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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 768e64a38091a5087d3abd0ba5b1447828bb495f134b2cdcea072a1d77ccf706
4
- data.tar.gz: 34a4630e81bcf65f6b77f2ef0cfaca5ee0d2fa1ad56fad90fa4f67622b64bd02
3
+ metadata.gz: a19ae6fa84afd56632baf90af377e18dbe8374abf482622bd7830a1ed489e8d1
4
+ data.tar.gz: 86a015c072a56d17595588c5d6bd547e264054a5ed2c752dfdc0e2c07c058dcf
5
5
  SHA512:
6
- metadata.gz: 614aa9ad23721a172cbcb77f054936a3c388cc03f6fa8664188ddd7402500bc6e1e8cf796010d60181c11821d23e19aa86ab2357f8834a8a0043a260b5a8cbd5
7
- data.tar.gz: 3ee5f14a5ce1baae00c0ad6fbff3c6410e540acd5d1dc3d78791dd5fe6b78ea459bed95466d6de08dc301cc26b123a03a6d5a0df17f3a88051aaf80cfd3eb6d7
6
+ metadata.gz: e218c3abb19c61323938b506b8613bfac2e721e4dd62330c72ab19531110e73d1e3cd49812244a9a183911634b956c2a7c17006b9fe1e412fb6bf7dab05df351
7
+ data.tar.gz: 07c3d578d2bb4749f8087c7bb6958e3bc8d7e79d50b553a05f5d38f302aa1434629f19fca12a59b4a1503f8cafd29a3b3e33515339f20591c2a2c0425acb189a
@@ -54,11 +54,8 @@ module Sitepress
54
54
  app.config.cache_classes
55
55
  end
56
56
 
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
57
+ config.to_prepare do
58
+ Sitepress::Path.handler_extensions = ActionView::Template::Handlers.extensions
62
59
  end
63
60
  end
64
61
 
@@ -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, :page_rendition
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
- # 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))
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 controller_layout(resource)
159
- private_layout_method = self.method(:_layout)
160
- layout =
161
- if Rails.version >= "6"
162
- private_layout_method.call lookup_context, resource_rails_formats(resource)
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
- private_layout_method.call
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
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
  spec.test_files = Dir["spec/**/*"]
24
24
 
25
- rails_version = ">= 6.0"
25
+ rails_version = ">= 7.0"
26
26
 
27
27
  spec.add_development_dependency "rspec-rails"
28
28
  spec.add_development_dependency "pry"