lib/scrivito/cms_routing.rb in scrivito_sdk-1.3.0.rc2 vs lib/scrivito/cms_routing.rb in scrivito_sdk-1.3.0.rc3
- old
+ new
@@ -75,41 +75,27 @@
url
end
def path_or_url_for_objs(obj, path_or_url, options)
permalink = obj.permalink
- if permalink && route_defined?(:permalink) && permalink.split('/').first != 'scrivito'
- use_route(:permalink, path_or_url, options.merge(:permalink => permalink))
- elsif homepage?(obj) && route_defined?(:homepage)
- use_route(:homepage, path_or_url, options)
+ 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_defined?(:slug_id)
+ elsif route = find_route(:slug_id)
slug = obj.slug.present? ? obj.slug.sub(/^\//, '') : nil
- id_path_or_url_for_objs(obj, path_or_url, options.merge(slug: slug))
+ 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."
end
end
- def id_path_or_url_for_objs(obj, path_or_url, options)
- options[:id] = obj.id
-
- # Options must have the key slug.
- # Otherwise Rails will use the slug from current request params.
- options[:slug] ||= nil
-
- use_route(:slug_id, path_or_url, options)
- end
-
- def route_defined?(name)
- Route.defined?(context._routes, name)
- end
-
- def use_route(name, path_or_url, options)
- Route.find(context._routes, name).generate(context, path_or_url, options)
+ def find_route(name)
+ Route.find(context, name)
end
def homepage?(obj)
RequestHomepage.call(request.env) == obj
end