UrlBuilder has absolute(to) method.
This commit is contained in:
parent
111bdea286
commit
60f4c1415f
@ -5,10 +5,12 @@ import java.nio.file.Path
|
||||
class PathBasedUrlBuilder implements UrlBuilder {
|
||||
|
||||
private final String absolute
|
||||
private final String baseUrl
|
||||
private final Path fromDirectory
|
||||
|
||||
PathBasedUrlBuilder(String targetPath, String baseUrl) {
|
||||
this.absolute = baseUrl + '/' + targetPath
|
||||
this.baseUrl = baseUrl
|
||||
def fromFilePath = Path.of(targetPath)
|
||||
if (fromFilePath.parent) {
|
||||
this.fromDirectory = fromFilePath.parent
|
||||
@ -22,6 +24,11 @@ class PathBasedUrlBuilder implements UrlBuilder {
|
||||
this.absolute
|
||||
}
|
||||
|
||||
@Override
|
||||
String absolute(String to) {
|
||||
this.baseUrl + '/' + to
|
||||
}
|
||||
|
||||
@Override
|
||||
String relative(String to) {
|
||||
this.fromDirectory.relativize(Path.of(to)).toString()
|
||||
|
@ -2,5 +2,6 @@ package com.jessebrault.ssg.url
|
||||
|
||||
interface UrlBuilder {
|
||||
String getAbsolute()
|
||||
String absolute(String to)
|
||||
String relative(String to)
|
||||
}
|
@ -38,4 +38,12 @@ abstract class AbstractUrlBuilderTests {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
void absoluteToCorrect() {
|
||||
assertEquals(
|
||||
'https://test.com/images/test.jpg',
|
||||
this.getUrlBuilder('', 'https://test.com').absolute('images/test.jpg')
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user