Skip to content

Commit

Permalink
handle mount points other then '/'
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Berkenbosch <peter@pero-ict.nl>
  • Loading branch information
peterberkenbosch committed Mar 14, 2012
1 parent dbd57c5 commit be91eb5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/controllers/spree/static_content_controller.rb
Expand Up @@ -11,8 +11,9 @@ def show
when nil
request.path
end

unless @page = Spree::Page.visible.find_by_slug(path.gsub('//','/'))
path = StaticPage::remove_spree_mount_point(path) unless Rails.application.routes.named_routes[:spree].path.spec.to_s == "/"
path = path.gsub('//','/')
unless @page = Spree::Page.visible.find_by_slug(path)
render_404
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/spree/static_content/_static_content_list.html.erb
@@ -1 +1,2 @@
<li class=<%=(request.fullpath[1..-1] == page.slug) ? 'current' : 'not'%>><%= link_to page.title, page.slug %></li>
<% page_uri = Rails.application.routes.named_routes[:spree].path.spec.to_s == '/' ? page.slug : Rails.application.routes.named_routes[:spree].path.spec.to_s + page.slug %>
<li class=<%=(request.fullpath == page_uri) ? 'current' : 'not'%>><%= link_to page.title, page_uri %></li>
13 changes: 10 additions & 3 deletions config/routes.rb
@@ -1,14 +1,21 @@
module StaticPage
def self.remove_spree_mount_point(path)
regex = Regexp.new Rails.application.routes.named_routes[:spree].path.spec.to_s
path.sub( regex, '')
end
end

class Spree::StaticPage
def self.matches?(request)
path = request.fullpath
count = Spree::Page.visible.where(:slug => path.gsub("//","/")).count
path = StaticPage::remove_spree_mount_point(request.fullpath)
count = Spree::Page.visible.where(:slug => path).count
0 < count
end
end

class Spree::StaticRoot
def self.matches?(request)
path = request.fullpath.gsub("//","/")
path = StaticPage::remove_spree_mount_point(request.fullpath)
(path == '/') && Spree::Page.visible.find_by_slug(path)
end
end
Expand Down

0 comments on commit be91eb5

Please sign in to comment.