From 48c917982c96d1a4247c3e6c9ac09bcd33059fbc Mon Sep 17 00:00:00 2001 From: Jacques Crocker Date: Tue, 21 Sep 2010 04:16:39 -0700 Subject: [PATCH 1/2] Reorganizing Admin layouts, and deleting home controller and views --- app/controllers/admin/base_controller.rb | 2 +- app/controllers/admin/cross_domain_sessions_controller.rb | 2 +- app/controllers/admin/passwords_controller.rb | 2 +- app/controllers/admin/sessions_controller.rb | 2 +- app/controllers/application_controller.rb | 2 +- app/controllers/home_controller.rb | 7 ------- .../{layouts/admin => admin/layouts}/application.html.haml | 0 app/views/{layouts/admin => admin/layouts}/box.html.haml | 0 app/views/home/show.html.haml | 4 ---- app/views/layouts/application.html.haml | 7 ------- lib/locomotive/render.rb | 2 +- 11 files changed, 6 insertions(+), 24 deletions(-) delete mode 100644 app/controllers/home_controller.rb rename app/views/{layouts/admin => admin/layouts}/application.html.haml (100%) rename app/views/{layouts/admin => admin/layouts}/box.html.haml (100%) delete mode 100644 app/views/home/show.html.haml delete mode 100644 app/views/layouts/application.html.haml diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 2bb86c14..11fde8c1 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -3,7 +3,7 @@ module Admin include Locomotive::Routing::SiteDispatcher - layout 'admin/application' + layout '/admin/layouts/application' before_filter :authenticate_admin! diff --git a/app/controllers/admin/cross_domain_sessions_controller.rb b/app/controllers/admin/cross_domain_sessions_controller.rb index dc184687..2f333801 100644 --- a/app/controllers/admin/cross_domain_sessions_controller.rb +++ b/app/controllers/admin/cross_domain_sessions_controller.rb @@ -1,7 +1,7 @@ module Admin class CrossDomainSessionsController < BaseController - layout 'admin/box' + layout '/admin/layouts/box' skip_before_filter :verify_authenticity_token diff --git a/app/controllers/admin/passwords_controller.rb b/app/controllers/admin/passwords_controller.rb index ec99d835..cc513ab7 100644 --- a/app/controllers/admin/passwords_controller.rb +++ b/app/controllers/admin/passwords_controller.rb @@ -3,7 +3,7 @@ module Admin include Locomotive::Routing::SiteDispatcher - layout 'admin/box' + layout '/admin/layouts/box' before_filter :require_site diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index f3b43c8b..7aa60f68 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -3,7 +3,7 @@ module Admin include Locomotive::Routing::SiteDispatcher - layout 'admin/box' + layout '/admin/layouts/box' before_filter :require_site diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6e5f9df7..6947e663 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,6 +6,6 @@ class ApplicationController < ActionController::Base # rescue_from Exception, :with => :render_error # # def render_error - # render :template => "/admin/errors/500", :layout => 'admin/box', :status => 500 + # render :template => "/admin/errors/500", :layout => '/admin/layouts/box', :status => 500 # end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb deleted file mode 100644 index 594b2ea5..00000000 --- a/app/controllers/home_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class HomeController < ApplicationController - - def show; end - - def unknown; end - -end diff --git a/app/views/layouts/admin/application.html.haml b/app/views/admin/layouts/application.html.haml similarity index 100% rename from app/views/layouts/admin/application.html.haml rename to app/views/admin/layouts/application.html.haml diff --git a/app/views/layouts/admin/box.html.haml b/app/views/admin/layouts/box.html.haml similarity index 100% rename from app/views/layouts/admin/box.html.haml rename to app/views/admin/layouts/box.html.haml diff --git a/app/views/home/show.html.haml b/app/views/home/show.html.haml deleted file mode 100644 index 86bb6f0a..00000000 --- a/app/views/home/show.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -%h2 Locomotive rocks !!! - -%p - = flash[:error] diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml deleted file mode 100644 index 639013e7..00000000 --- a/app/views/layouts/application.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -!!! XML -!!! -%html{ :xmlns => 'http://www.w3.org/1999/xhtml' } - %head - %body - %h1 Welcome to Locomotive - = yield diff --git a/lib/locomotive/render.rb b/lib/locomotive/render.rb index c41bfa1f..5b98aa19 100644 --- a/lib/locomotive/render.rb +++ b/lib/locomotive/render.rb @@ -9,7 +9,7 @@ module Locomotive def render_locomotive_page if request.fullpath =~ /^\/admin\// - render :template => "/admin/errors/404", :layout => 'admin/box', :status => 404 + render :template => "/admin/errors/404", :layout => '/admin/layouts/box', :status => 404 else @page = locomotive_page From 9097200339cbda55e24704d47f9aa5f838c88648 Mon Sep 17 00:00:00 2001 From: Jacques Crocker Date: Tue, 21 Sep 2010 04:45:34 -0700 Subject: [PATCH 2/2] Adding specific admin templates for the "no site" and "no page" errors. Goal should be to use these to allow someone to create a new site right here --- app/views/admin/errors/no_page.html.haml | 1 + app/views/admin/errors/no_site.html.haml | 1 + app/views/admin/layouts/error.html.haml | 1 + config/routes.rb | 6 +++--- lib/locomotive/render.rb | 6 +++++- lib/locomotive/routing/site_dispatcher.rb | 10 +++++----- 6 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 app/views/admin/errors/no_page.html.haml create mode 100644 app/views/admin/errors/no_site.html.haml create mode 100644 app/views/admin/layouts/error.html.haml diff --git a/app/views/admin/errors/no_page.html.haml b/app/views/admin/errors/no_page.html.haml new file mode 100644 index 00000000..d4948def --- /dev/null +++ b/app/views/admin/errors/no_page.html.haml @@ -0,0 +1 @@ +No Page! \ No newline at end of file diff --git a/app/views/admin/errors/no_site.html.haml b/app/views/admin/errors/no_site.html.haml new file mode 100644 index 00000000..5bee4fcc --- /dev/null +++ b/app/views/admin/errors/no_site.html.haml @@ -0,0 +1 @@ +No Site! \ No newline at end of file diff --git a/app/views/admin/layouts/error.html.haml b/app/views/admin/layouts/error.html.haml new file mode 100644 index 00000000..f1d0cc89 --- /dev/null +++ b/app/views/admin/layouts/error.html.haml @@ -0,0 +1 @@ += yield \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7578a6de..17847109 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,9 @@ # Locomotive::Application.routes.draw do |map| Rails.application.routes.draw do - constraints(Locomotive::Routing::DefaultConstraint) do - root :to => 'home#show' - end + # constraints(Locomotive::Routing::DefaultConstraint) do + # root :to => 'home#show' + # end # admin authentication devise_for :admin, :class_name => 'Account', :controllers => { :sessions => 'admin/sessions', :passwords => 'admin/passwords' } diff --git a/lib/locomotive/render.rb b/lib/locomotive/render.rb index 5b98aa19..16ffa99a 100644 --- a/lib/locomotive/render.rb +++ b/lib/locomotive/render.rb @@ -13,7 +13,7 @@ module Locomotive else @page = locomotive_page - redirect_to application_root_url and return if @page.nil? + render_no_page_error and return if @page.nil? output = @page.render(locomotive_context) @@ -21,6 +21,10 @@ module Locomotive end end + def render_no_page_error + render :template => "/admin/errors/no_page", :layout => false + end + def locomotive_page path = (params[:path] || request.fullpath).clone path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '') diff --git a/lib/locomotive/routing/site_dispatcher.rb b/lib/locomotive/routing/site_dispatcher.rb index 3836898f..9fa988f9 100644 --- a/lib/locomotive/routing/site_dispatcher.rb +++ b/lib/locomotive/routing/site_dispatcher.rb @@ -26,7 +26,11 @@ module Locomotive end def require_site - redirect_to application_root_url and return false if current_site.nil? + render_no_site_error and return false if current_site.nil? + end + + def render_no_site_error + render :template => "/admin/errors/no_site", :layout => false end def validate_site_membership @@ -34,10 +38,6 @@ module Locomotive sign_out_and_redirect(current_admin) end - def application_root_url - root_url(:host => Locomotive.config.default_domain, :port => request.port) - end - end end