lib/scrivito/cms_routing.rb in scrivito_sdk-1.8.1 vs lib/scrivito/cms_routing.rb in scrivito_sdk-1.9.0.rc1
- old
+ new
@@ -74,24 +74,36 @@
url = url + "##{link.fragment}" if link.fragment.present?
url
end
def path_or_url_for_objs(obj, path_or_url, options)
- permalink = obj.permalink
- if permalink && (route = find_route(:permalink)) && permalink.split('/').first != 'scrivito'
- route.generate(path_or_url, options.merge(:permalink => permalink))
- elsif homepage?(obj) && route = find_route(:homepage)
- route.generate(path_or_url, options)
- elsif obj.binary?
- binary_obj_url(obj) || LINK_TO_EMPTY_BLOB
- elsif route = find_route(:slug_id)
+ if permalink_route_applicable?(obj) && route = find_route(:permalink)
+ return route.generate(path_or_url, options.merge(permalink: obj.permalink))
+ end
+
+ if homepage?(obj) && route = find_route(:homepage)
+ return route.generate(path_or_url, options)
+ end
+
+ if obj.binary?
+ return binary_obj_url(obj) || LINK_TO_EMPTY_BLOB
+ end
+
+ if route = find_route(:slug_id)
slug = obj.slug.present? ? obj.slug.sub(/^\//, '') : nil
- route.generate(path_or_url, options.merge(id: obj.id, slug: slug))
- else
- raise ScrivitoError, "The required scrivito route 'slug_id' is not defined. "\
- "Please add a 'slug_id' definition to your routes.rb. See the documentation"\
- " of 'scrivito_route' for further details."
+
+ return route.generate(path_or_url, options.merge(id: obj.id, slug: slug))
end
+
+ raise ScrivitoError, "The required scrivito route 'slug_id' is not defined. "\
+ "Please add a 'slug_id' definition to your routes.rb. See the documentation"\
+ " of 'scrivito_route' for further details."
+ end
+
+ def permalink_route_applicable?(obj)
+ permalink = obj.permalink
+
+ permalink && permalink.split('/').first != 'scrivito' && !obj.deleted?
end
def find_route(name)
Route.find(context, name)
end