url method on Document?
Closed this issue · 1 comments
Suddenly thinking, since now we can do documentLink.url(link_resolver(@maybe_ref))
instead of link_resolver(@maybe_ref).link_to(documentLink)
, maybe it would be cool to be able to do the same for Document
(document.url(link_resolver(@maybe_ref))
instead of link_resolver(@maybe_ref).link_to(documentLink)
)? It's a bold choice, not sure what the implications would be.
On a broader topic, since passing a function is very different depending on the technology, there is no unified way to build a front-office URL from a Document
or a DocumentLink
object. Maybe we should make it a requirement for the other kits to implement a url
method on Link
and Document
classes?
Today, the ways to do it seem to be (I didn't test those):
- In Java:
- for
DocumentLink
objects:prismic.linkResolver.resolveLink(documentLink);
- for
Document
objects:prismic.linkResolver.resolveDocument(document);
- for
- In JavaScript:
- for
DocumentLink
objects:ctx.linkResolver(ctx, docLink);
, ordocLink.url(ctx.linkResolver);
actually is already there. - for
Document
objects: actually, not possible easily today.
- for
- In PHP:
- for
DocumentLink
objects:$linkResolver.resolveLink($documentLink);
- for
Document
objects:$linkResolver.resolveDocument($document);
- for
- In Scala:
- for
DocumentLink
objects:ctx.linkResolver.apply(documentLink);
- for
Document
objects:ctx.linkResolver.apply(documentLink);
- for
Well, no matter what we do, we have to make all of them consistent. I say through a url
method in Document
and DocumentLink
objects is a nice way, but I'm opened to be challenged about it. :)
(Of course, once we stabilize a way to do this, that will allow me to document it on the cross-tech documentation on the developers portal; there's no word about it today)