-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from ia3andy/pagination-and-modification-api
Better pagination and introduce data modif api
- Loading branch information
Showing
22 changed files
with
273 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,6 @@ | ||
{@io.quarkiverse.roq.frontmatter.runtime.model.Site site} | ||
|
||
<div class="container"> | ||
<nav class="pagination" role="pagination"> | ||
<ul> | ||
{#if page.paginator.previous} | ||
{#if page.paginator.isSecond} | ||
<p><a class="newer-posts" href="{site.url}"><i class="fa fa-long-arrow-left" aria-hidden="true"></i></a></p> | ||
{#else} | ||
<p><a class="newer-posts" href="{page.paginator.previous}/"><i class="fa fa-long-arrow-left" aria-hidden="true"></i></a></p> | ||
{/if} | ||
{/if} | ||
|
||
{#if page.paginator.total > 1} | ||
<p><span class="page-number">Page {page.paginator.currentIndex} of {page.paginator.total}</span></p> | ||
{/if} | ||
|
||
{#if page.paginator.next} | ||
<p><a class="older-posts" href="{page.paginator.next}"><i class="fa fa-long-arrow-right" aria-hidden="true"></i></a></p> | ||
{/if} | ||
</ul> | ||
</nav> | ||
{#include fm/pagination.html} | ||
{#newer}<i class="fa fa-long-arrow-left" aria-hidden="true"></i>{/newer} | ||
{#older}<i class="fa fa-long-arrow-right" aria-hidden="true"></i>{/older} | ||
{/include} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../quarkiverse/roq/frontmatter/deployment/data/RoqFrontMatterDataModificationBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.quarkiverse.roq.frontmatter.deployment.data; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
/** | ||
* Allow to modify the FrontMatter data just before it is produced (and before it is merged with parents). | ||
*/ | ||
public final class RoqFrontMatterDataModificationBuildItem extends MultiBuildItem { | ||
private final DataModifier modifier; | ||
|
||
/** | ||
* Modifiers with the highest priority will run last. | ||
*/ | ||
private final int order; | ||
|
||
public RoqFrontMatterDataModificationBuildItem(DataModifier modifier, int order) { | ||
this.modifier = modifier; | ||
this.order = order; | ||
} | ||
|
||
public RoqFrontMatterDataModificationBuildItem(DataModifier modifier) { | ||
this.modifier = modifier; | ||
this.order = 0; | ||
} | ||
|
||
public DataModifier modifier() { | ||
return modifier; | ||
} | ||
|
||
public int order() { | ||
return order; | ||
} | ||
|
||
public interface DataModifier { | ||
|
||
JsonObject modify(String id, String templatePath, JsonObject fm); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...est/java/io/quarkiverse/roq/frontmatter/deployment/RoqFrontMatterApiModificationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.quarkiverse.roq.frontmatter.deployment; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.roq.frontmatter.deployment.data.RoqFrontMatterDataModificationBuildItem; | ||
import io.quarkus.builder.BuildContext; | ||
import io.quarkus.builder.BuildStep; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class RoqFrontMatterApiModificationTest { | ||
|
||
// Start unit test with your extension loaded | ||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.roq.resource-dir", "simple-site") | ||
.addBuildChainCustomizer(buildChainBuilder -> { | ||
buildChainBuilder.addBuildStep(new BuildStep() { | ||
|
||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(new RoqFrontMatterDataModificationBuildItem((id, path, data) -> { | ||
if (id.equals("pages/some-page")) { | ||
final JsonObject newData = data.copy(); | ||
newData.put("some-text", "modified text"); | ||
newData.put("link", "/somewhere-else"); | ||
return newData; | ||
} | ||
return data; | ||
})); | ||
} | ||
}).produces(RoqFrontMatterDataModificationBuildItem.class).build(); | ||
|
||
}) | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource("simple-site")); | ||
|
||
@Test | ||
public void testPage() { | ||
RestAssured.when().get("/somewhere-else").then().statusCode(200).log().ifValidationFails() | ||
.body("html.body.article.p", equalTo("modified text")); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...ent/src/test/java/io/quarkiverse/roq/frontmatter/deployment/RoqFrontMatterSimpleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.quarkiverse.roq.frontmatter.deployment; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class RoqFrontMatterSimpleTest { | ||
|
||
// Start unit test with your extension loaded | ||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.roq.resource-dir", "simple-site") | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource("simple-site")); | ||
|
||
@Test | ||
public void testPage() { | ||
RestAssured.when().get("/page/some-page").then().statusCode(200).log().ifValidationFails() | ||
.body("html.head.title", equalTo("Some page - Simple Site")) | ||
.body("html.body.article.h1", equalTo("Some page")) | ||
.body("html.body.article.p", equalTo("We can also use data")); | ||
} | ||
|
||
@Test | ||
public void testIndex() { | ||
RestAssured.when().get("/").then().statusCode(200).log().ifValidationFails() | ||
.body("html.head.title", equalTo("Simple Site")) | ||
.body("html.body.div.h1[0]", containsString("New Post")) | ||
.body("html.body.div.h1[1]", containsString("Some Post")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
roq-frontmatter/deployment/src/test/resources/simple-site/_includes/header.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{#seo page site/} |
Oops, something went wrong.