sitepress-server 2.0.0 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c176021cf59c6299c842e43bbac69042450f429bfd5d11bf1f9df9c3a6f32818
4
- data.tar.gz: f67f47d0b6c2dfe4d67d73de13428051191fc1e3b93b749ef26441edfd615022
3
+ metadata.gz: b7cac4ef1fbb512ba1885c8a465d38b977ce6fa0cbf1e9fecf4f92922b64a3b2
4
+ data.tar.gz: 5af9fce05af1b7adb1b913746603024c95dd2e25fcaa4a91e09501317c1e2ad7
5
5
  SHA512:
6
- metadata.gz: e9d87521be924b21d5f36964a375ff4887780f2aabe00f727958770fd3553a3d1e30a645d4178377a61d3a95b577779cea0f4ed4bd516b1081091c234050831b
7
- data.tar.gz: ed5a741569cd7efaba7b8ad266094663c3fccccad94dc10aba1d7a38692cbc07b59a61a4f35908954181f2c91c92fecad7be08a296435eeae3eeae7437678ce8
6
+ metadata.gz: f17f6a7115af95036560f8c7e249f6b4d940d14b3b2aacb9832ffe6bd47b21a34c331481bcffc4686738abd9e47d1e6edeefc8dd5f5e5bc66cb16434ee4d2ee2
7
+ data.tar.gz: 74a9be4bbaaf26b5871ed19e954577aa794062d35ca03dbbc1000e94e74b0301ca85a59c4757b4fc39ce6bb0b448de7d47c08b0c3608cbe6ae5fd8df6e224f93
@@ -9,18 +9,41 @@ Bundler.require(*Rails.groups)
9
9
  # Configure the rails application.
10
10
  module Sitepress
11
11
  class Server < Rails::Application
12
- # Paths unique to Sitepress
13
- config.root = File.join(File.dirname(__FILE__), "../../rails")
12
+ # Control whether or not to display friendly error reporting messages
13
+ # in Sitepress. The development server turns this on an handles exception,
14
+ # while the compile and other environments would likely have this disabled.
15
+ config.enable_site_error_reporting = false
16
+
17
+ # When in a development environment, we'll want to reload the site between
18
+ # requests so we can see the latest changes; otherwise, load the site once
19
+ # and we're done.
20
+ config.enable_site_reloading = false
21
+
22
+ # Default to a development environment type of configuration, which would reload the site.
23
+ # This gets reset later depending on a preference in the `before_initialize` callback.
24
+ config.eager_load = true
25
+ config.cache_classes = true
14
26
 
15
- # Boilerplate required to get Rails to boot.
16
- config.eager_load = false # necessary to silence warning
17
- config.cache_classes = false # reload everything since this is dev env.
27
+ config.before_initialize do
28
+ # Eager load classes, content, etc. to boost performance when site reloading is disabled.
29
+ config.eager_load = !config.enable_site_reloading
30
+
31
+ # Cache classes for speed in production environments when site reloading is disabled.
32
+ config.cache_classes = !config.enable_site_reloading
33
+ end
34
+
35
+ # Path that points the the Sitepress UI rails app; which displays routes, error messages.
36
+ # etc. to the user if `enable_site_error_reporting` is enabled.
37
+ config.root = File.join(File.dirname(__FILE__), "../../rails")
18
38
 
19
- config.secret_key_base = SecureRandom.uuid # Rails won't start without this
39
+ # Rails won't start without this.
40
+ config.secret_key_base = SecureRandom.uuid
20
41
 
21
- # Setup routes
22
- routes.append { root to: "site#show" }
23
- routes.append { get "*resource_path", controller: "site", action: "show", as: :page, format: false }
42
+ # Setup routes. The `constraints` key is set to `nil` so the `SiteController` can
43
+ # treat a page not being found as an exception, which it then handles. If the constraint
44
+ # was set to the default, Sitepress would hand off routing back to rails if something isn't
45
+ # found and fail silently.
46
+ routes.append { sitepress_pages root: true, controller: "site", constraints: nil }
24
47
 
25
48
  # A logger without a formatter will crash when Sprockets is enabled.
26
49
  logger = ActiveSupport::Logger.new(STDOUT)
@@ -48,4 +71,4 @@ module Sitepress
48
71
  end
49
72
 
50
73
  # Load the SassC template handler if SassC is installed as part of this stand-alone server.
51
- require_relative "sass_template_handlers" if defined? SassC::Engine
74
+ require_relative "sass_template_handlers" if defined? SassC::Engine
@@ -1,22 +1,13 @@
1
1
  class SiteController < ApplicationController
2
- DEFAULT_SITE_LAYOUT = "layouts/layout".freeze
3
-
4
- # Control whether or not to display friendly error reporting messages
5
- # in Sitepress. The development server turns this on an handles exception,
6
- # while the compile and other environments would likely have this disabled.
7
- class_attribute :enable_sitepress_error_reporting, default: false
2
+ include Sitepress::SitePages
8
3
 
9
- # When in a development environment, we'll want to reload the site between
10
- # requests so we can see the latest changes; otherwise, load the site once
11
- # and we're done.
12
- class_attribute :enable_site_reloading, default: false
4
+ DEFAULT_SITE_LAYOUT = "layouts/layout".freeze
13
5
 
14
6
  # This `rescue_from` order is important; it must come before the
15
7
  # `include Sitepress::SitePages` statement; otherwise exceptions
16
8
  # won't be properly handled.
17
9
  rescue_from Exception, with: :sitepress_error
18
-
19
- include Sitepress::SitePages
10
+ rescue_from Sitepress::ResourceNotFoundError, with: :page_not_found
20
11
 
21
12
  layout :site_layout
22
13
 
@@ -28,23 +19,26 @@ class SiteController < ApplicationController
28
19
  def sitepress_error(exception)
29
20
  raise exception unless has_error_reporting_enabled?
30
21
 
31
- @title = "Sitepress error in #{current_page.asset.path}".html_safe
22
+ @title = "Error in resource #{current_page.asset.path}".html_safe
32
23
  @exception = exception
33
24
  render "error", layout: "sitepress", status: :internal_server_error
34
25
  end
35
26
 
36
27
  def page_not_found(exception)
37
28
  raise exception unless has_error_reporting_enabled?
29
+ not_found
30
+ end
38
31
 
39
- @title = "Sitepress page #{params[:resource_path].inspect} not found"
40
- render "page_not_found", layout: "sitepress", status: :not_found
32
+ def not_found
33
+ @title = "Could not find resource at #{request.path}"
34
+ render "not_found", layout: "sitepress", status: :not_found
41
35
  end
42
36
 
43
37
  def has_error_reporting_enabled?
44
- self.class.enable_sitepress_error_reporting
38
+ Sitepress::Server.config.enable_site_error_reporting
45
39
  end
46
40
 
47
41
  def reload_site?
48
- self.class.enable_site_reloading
42
+ Sitepress::Server.config.enable_site_reloading
49
43
  end
50
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitepress-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-02 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-test
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.0
33
+ version: 3.1.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.0
40
+ version: 3.1.2
41
41
  description:
42
42
  email:
43
43
  - bradgessler@gmail.com
@@ -54,7 +54,7 @@ files:
54
54
  - rails/app/helpers/application_helper.rb
55
55
  - rails/app/views/layouts/sitepress.html.erb
56
56
  - rails/app/views/site/error.html.erb
57
- - rails/app/views/site/page_not_found.html.erb
57
+ - rails/app/views/site/not_found.html.erb
58
58
  - rails/public/_sitepress/images/logo.svg
59
59
  - rails/public/_sitepress/stylesheets/site.css
60
60
  - sitepress-server.gemspec
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.2.3
80
+ rubygems_version: 3.3.7
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Sitepress rack app for stand-alone of embedded usage.