UrlBuilder now has absolute method.
This commit is contained in:
parent
2d00c6be2e
commit
0762dc6b8b
@ -4,10 +4,12 @@ import java.nio.file.Path
|
||||
|
||||
class PathBasedUrlBuilder implements UrlBuilder {
|
||||
|
||||
private final String absolute
|
||||
private final Path fromDirectory
|
||||
|
||||
PathBasedUrlBuilder(String fromFile) {
|
||||
def fromFilePath = Path.of(fromFile)
|
||||
PathBasedUrlBuilder(String absolute) {
|
||||
this.absolute = absolute
|
||||
def fromFilePath = Path.of(absolute)
|
||||
if (fromFilePath.parent) {
|
||||
this.fromDirectory = fromFilePath.parent
|
||||
} else {
|
||||
@ -15,6 +17,11 @@ class PathBasedUrlBuilder implements UrlBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
String getAbsolute() {
|
||||
this.absolute
|
||||
}
|
||||
|
||||
@Override
|
||||
String relative(String to) {
|
||||
this.fromDirectory.relativize(Path.of(to)).toString()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.jessebrault.ssg.url
|
||||
|
||||
interface UrlBuilder {
|
||||
String getAbsolute()
|
||||
String relative(String to)
|
||||
}
|
@ -3,8 +3,8 @@ package com.jessebrault.ssg.url
|
||||
class PathBasedUrlBuilderTests extends AbstractUrlBuilderTests {
|
||||
|
||||
@Override
|
||||
protected UrlBuilder getUrlBuilder(String fromFile) {
|
||||
new PathBasedUrlBuilder(fromFile)
|
||||
protected UrlBuilder getUrlBuilder(String targetPath) {
|
||||
new PathBasedUrlBuilder(targetPath)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals
|
||||
|
||||
abstract class AbstractUrlBuilderTests {
|
||||
|
||||
protected abstract UrlBuilder getUrlBuilder(String fromFile);
|
||||
protected abstract UrlBuilder getUrlBuilder(String targetPath);
|
||||
|
||||
@Test
|
||||
void upDownDown() {
|
||||
@ -30,4 +30,12 @@ abstract class AbstractUrlBuilderTests {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
void absoluteMatchesTargetPath() {
|
||||
assertEquals(
|
||||
'test/test.html',
|
||||
this.getUrlBuilder('test/test.html').absolute
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user