From 8c432521c0bee49c9be82f53c708814bb0be347d Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 23 Feb 2012 01:33:22 -0500 Subject: [PATCH 1/2] prepended the routes and added conditional restraints. Also added sanitation in the controller to get rid of any double slashed --- .../spree/static_content_controller.rb | 2 +- .../spree/static_content_controller.rb~ | 31 +++++++++++++++++++ config/routes.rb | 26 ++++++++++++++-- config/routes.rb~ | 9 ++++++ 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 app/controllers/spree/static_content_controller.rb~ create mode 100644 config/routes.rb~ diff --git a/app/controllers/spree/static_content_controller.rb b/app/controllers/spree/static_content_controller.rb index 58c5dded..36e8b9ed 100644 --- a/app/controllers/spree/static_content_controller.rb +++ b/app/controllers/spree/static_content_controller.rb @@ -12,7 +12,7 @@ def show request.path end - unless @page = Spree::Page.visible.find_by_slug(path) + unless @page = Spree::Page.visible.find_by_slug(path.gsub('//','/')) render_404 end end diff --git a/app/controllers/spree/static_content_controller.rb~ b/app/controllers/spree/static_content_controller.rb~ new file mode 100644 index 00000000..36e8b9ed --- /dev/null +++ b/app/controllers/spree/static_content_controller.rb~ @@ -0,0 +1,31 @@ +class Spree::StaticContentController < Spree::BaseController + caches_action :show + layout :determine_layout + + def show + path = case params[:path] + when Array + '/' + params[:path].join("/") + when String + '/' + params[:path] + when nil + request.path + end + + unless @page = Spree::Page.visible.find_by_slug(path.gsub('//','/')) + render_404 + end + end + + private + + def determine_layout + return @page.layout if @page and @page.layout.present? + 'spree/layouts/spree_application' + end + + def accurate_title + @page ? (@page.meta_title ? @page.meta_title : @page.title) : nil + end +end + diff --git a/config/routes.rb b/config/routes.rb index 980f8cb2..c7f41309 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,29 @@ -Spree::Core::Engine.routes.append do +class Spree::StaticPage + def self.matches?(request) + path = request.fullpath + count = Spree::Page.visible.where(:slug => path.gsub("//","/")).count + 0 < count + end +end + +class Spree::StaticRoot + def self.matches?(request) + path = request.fullpath.gsub("//","/") + (path == '/') && Spree::Page.visible.find_by_slug(path) + end +end + +Spree::Core::Engine.routes.prepend do namespace :admin do resources :pages end - match '/static/*path', :to => 'static_content#show', :via => :get, :as => 'static' - match '/*path', :to => 'static_content#show', :via => :get, :as => 'static' + constraints(Spree::StaticRoot) do + match '/', :to => 'static_content#show', :via => :get, :as => 'static' + end + + constraints(Spree::StaticPage) do + match '/*path', :to => 'static_content#show', :via => :get, :as => 'static' + end end diff --git a/config/routes.rb~ b/config/routes.rb~ new file mode 100644 index 00000000..980f8cb2 --- /dev/null +++ b/config/routes.rb~ @@ -0,0 +1,9 @@ +Spree::Core::Engine.routes.append do + + namespace :admin do + resources :pages + end + + match '/static/*path', :to => 'static_content#show', :via => :get, :as => 'static' + match '/*path', :to => 'static_content#show', :via => :get, :as => 'static' +end From cb8d779d6adf426aa6c5a9f02a9f5a86ce45f0bc Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 23 Feb 2012 02:23:15 -0500 Subject: [PATCH 2/2] Revert a couple of commits. Need second constraint for the root path and cleaning up some temp files --- .../spree/static_content_controller.rb~ | 31 ------------------- config/routes.rb~ | 9 ------ 2 files changed, 40 deletions(-) delete mode 100644 app/controllers/spree/static_content_controller.rb~ delete mode 100644 config/routes.rb~ diff --git a/app/controllers/spree/static_content_controller.rb~ b/app/controllers/spree/static_content_controller.rb~ deleted file mode 100644 index 36e8b9ed..00000000 --- a/app/controllers/spree/static_content_controller.rb~ +++ /dev/null @@ -1,31 +0,0 @@ -class Spree::StaticContentController < Spree::BaseController - caches_action :show - layout :determine_layout - - def show - path = case params[:path] - when Array - '/' + params[:path].join("/") - when String - '/' + params[:path] - when nil - request.path - end - - unless @page = Spree::Page.visible.find_by_slug(path.gsub('//','/')) - render_404 - end - end - - private - - def determine_layout - return @page.layout if @page and @page.layout.present? - 'spree/layouts/spree_application' - end - - def accurate_title - @page ? (@page.meta_title ? @page.meta_title : @page.title) : nil - end -end - diff --git a/config/routes.rb~ b/config/routes.rb~ deleted file mode 100644 index 980f8cb2..00000000 --- a/config/routes.rb~ +++ /dev/null @@ -1,9 +0,0 @@ -Spree::Core::Engine.routes.append do - - namespace :admin do - resources :pages - end - - match '/static/*path', :to => 'static_content#show', :via => :get, :as => 'static' - match '/*path', :to => 'static_content#show', :via => :get, :as => 'static' -end