better error page when a page is not found (fix issue locomotivecms/steam#57)

did committed Feb 16, 2016
commit 64c472c4e1216a6ab737b279cd8a08131ade5889
Showing 2 changed files with 17 additions and 2 deletions
Gemfile +2 -2
@@ @@ -6,13 +6,13 @@ gemspec
gem 'rb-fsevent', '~> 0.9.1'
# Development
- # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'ea9cd18', require: false
+ gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'ee5b98e', require: false
# gem 'locomotivecms_coal', github: 'locomotivecms/coal', ref: '32b2844', require: false
# gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '3046b79893', require: false
# Local development
# gem 'locomotivecms_coal', path: '../gems/coal', require: false
- gem 'locomotivecms_steam', path: '../gems/steam', require: false
+ # gem 'locomotivecms_steam', path: '../gems/steam', require: false
# gem 'locomotivecms_common', path: '../gems/common', require: false
group :development, :test do
locomotive/wagon/commands/serve_command.rb b/lib/locomotive/wagon/commands/serve_command.rb +15 -0
@@ @@ -67,6 +67,8 @@ module Locomotive::Wagon
configure_logger
+ respond_to_notifications
+
Locomotive::Steam.configure do |config|
config.mode = :test
config.adapter = { name: :filesystem, path: File.expand_path(path) }
@@ @@ -137,6 +139,19 @@ module Locomotive::Wagon
end
end
+ def respond_to_notifications
+ # Page not found
+ ActiveSupport::Notifications.subscribe('steam.render.page_not_found') do |name, start, finish, id, payload|
+ fullpath, locale, default_locale = payload[:path], payload[:locale], payload[:default_locale]
+
+ filepath = File.join(File.expand_path(path), 'app', 'views', 'pages', fullpath + (locale != default_locale ? ".#{locale}" : '') + '.liquid')
+
+ message = "[Tip]".light_white + " add a new page in your Wagon site at this location: " + filepath.light_white
+
+ Locomotive::Common::Logger.info (' ' * 2) + message
+ end
+ end
+
def setup_signals
%w(INT TERM).each do |signal|
trap(signal) do