lib/scrivito/cms_routing.rb in scrivito_sdk-0.66.0 vs lib/scrivito/cms_routing.rb in scrivito_sdk-0.70.0.rc1

- old
+ new

@@ -16,11 +16,11 @@ end end def convert_links(html) if html - html.gsub(%r{\bobjid:([a-f0-9]{16})\b([^"']*)}) do + html.to_str.gsub(%r{\bobjid:([a-f0-9]{16})\b([^"']*)}) do if obj = Obj.find_by_id($1) options = {} if $2.present? begin @@ -60,11 +60,11 @@ path_or_url_for_links(target.first, path_or_url, options) else return LINK_TO_EMPTY_LINKLIST end elsif target.is_a?(Binary) - binary_url(target, path_or_url) + binary_url(target) else raise "scrivito_path or scrivito_url was called with an instance of #{target.class}. "+ "It must only be called with an Obj or a Link or a non-empty LinkList." end end @@ -79,18 +79,14 @@ def path_or_url_for_objs(obj, path_or_url, options) permalink = obj.permalink if permalink main_app .public_send("scrivito_permalink_#{path_or_url}", options.merge(:permalink => permalink)) - elsif obj.homepage? + elsif homepage?(obj) main_app.public_send("scrivito_root_#{path_or_url}", options) elsif obj.binary? - if binary = obj.binary - binary_url(binary, path_or_url) - else - LINK_TO_EMPTY_BLOB - end + binary_obj_url(obj) || LINK_TO_EMPTY_BLOB else slug = obj.slug.present? ? obj.slug.sub(/^\//, '') : nil id_path_or_url_for_objs(obj, path_or_url, options.merge(slug: slug)) end end @@ -103,10 +99,14 @@ end main_app.public_send(method_name, options.merge(id: obj.id)) end + def homepage?(obj) + RequestHomepage.call(request.env) == obj + end + def editor_authenticated? editing_context.authenticated_editor? end def editing_context @@ -139,29 +139,17 @@ def extract_query(uri) Rack::Utils.parse_query(uri.query) end - def binary_url(binary, path_or_url) - binary = transform_binary(binary) - if url_from_cache = binary.url_from_cache - BinaryRewrite.call(request, url_from_cache) - else - encrypted_params = BinaryParamVerifier.generate(binary) - scrivito_engine.public_send("binary_#{path_or_url}", encrypted_params: encrypted_params) - end + def binary_url(binary) + BinaryRouting.new(request, scrivito_engine).binary_url(binary) end - def transform_binary(binary) - if transformation_definition = image_options[:transform] - binary.transform(transformation_definition) - else - binary + def binary_obj_url(obj) + if binary = obj.binary + BinaryRouting.new(request, scrivito_engine).binary_obj_url(obj, binary, image_options || {}) end - end - - def image_options - super || {} end end end