Skip to content

Commit

Permalink
Website update 1.5.0 release (#204)
Browse files Browse the repository at this point in the history
* Updated new items to include 1.5.0.

- Adding short upgrade guide for incompatibilities between 1.4.0 and 1.5.0.
  • Loading branch information
sembler authored Jan 24, 2022
1 parent f083b2c commit 4bda363
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 40 deletions.
3 changes: 1 addition & 2 deletions website/src/main/java/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
public class Main {

public static void main(String[] args) {

Javalin app = Javalin.create(config ->
config.addStaticFiles("src/main/resources/public", Location.EXTERNAL)
config.addStaticFiles("website/src/main/resources/public", Location.EXTERNAL)
).start(8888);

app.get("/", PageController::serveIndex);
Expand Down
25 changes: 18 additions & 7 deletions website/src/main/java/app/views/pages/DownloadView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

import app.views.MainView;
import static app.views.Partials.codeSnippet;
import static j2html.TagCreator.a;
import static j2html.TagCreator.attrs;
import static j2html.TagCreator.fileAsEscapedString;
import static j2html.TagCreator.h2;
import static j2html.TagCreator.join;
import static j2html.TagCreator.p;
import static j2html.TagCreator.section;
import static j2html.TagCreator.*;

public class DownloadView {
public static String render() {
Expand All @@ -19,6 +13,23 @@ public static String render() {
h2("Maven dependency"),
p("To experience the joy of generating HTML with a Java HTML builder, add the j2html dependency to your POM:"),
codeSnippet("markup", fileAsEscapedString("/codeExamples/mavenDep.xml")),
a().withId("upgrade"),
h2("Steps for upgrading"),
p("From 1.4.0 to 1.5.0"),
ul(
li(
join("Change return types from", code("Tag"), ",", code("ContainerTag"), "or", code("EmptyTag"), "to the specific tag being returned.")
),
li(
join("Change missing method calls on tags, such as", code("withRole(\"value\")"), "to", code(".attr(\"role\", \"value\")"), ".")
),
li(
join("Method parameters of", code("Tag"), ",", code("ContainerTag"), "or", code("EmptyTag"), "should have a wildcard (<?>) added, or be changed to a specific tag.")
),
li(
join("Replace ambiguous method references like ", code("each(list, TagCreator::li)"), " with lambdas such as", code("each(list, str -> li(str))"), ".")
)
),
h2("Clone the repo on GitHub"),
p(join(
"Please clone and/or fork the repo on",
Expand Down
87 changes: 59 additions & 28 deletions website/src/main/java/app/views/pages/NewsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@

import app.views.MainView;
import j2html.TagCreator;
import j2html.tags.ContainerTag;
import j2html.tags.DomContent;
import j2html.tags.specialized.ArticleTag;

import java.util.Arrays;
import java.util.List;

import static app.views.Partials.mavenLink;
import static j2html.TagCreator.a;
import static j2html.TagCreator.article;
import static j2html.TagCreator.attrs;
import static j2html.TagCreator.br;
import static j2html.TagCreator.code;
import static j2html.TagCreator.dd;
import static j2html.TagCreator.dl;
import static j2html.TagCreator.dt;
import static j2html.TagCreator.each;
import static j2html.TagCreator.em;
import static j2html.TagCreator.h2;
import static j2html.TagCreator.join;
import static j2html.TagCreator.li;
import static j2html.TagCreator.p;
import static j2html.TagCreator.section;
import static j2html.TagCreator.text;
import static j2html.TagCreator.ul;
import static j2html.TagCreator.*;

public class NewsView {

private static ContainerTag newsPost(String title, String version, DomContent... listItems) {
private static ArticleTag newsPost(
String title,
String version,
boolean breaking,
DomContent... listItems
) {
List<DomContent> list = Arrays.asList(listItems);
return article(
h2(title).withId("j2html-" + version + "-released"),
mavenLink(version),
iff(breaking,
p(
a("This version contains breaking changes. Please view the upgrade guide.").withHref("download.html#upgrade")
)
),
p("Changes:"),
ul(
each(list, el -> TagCreator.li(el))
Expand All @@ -45,33 +41,60 @@ public static String render() {
section(attrs("#news"),

newsPost(
"j2html 1.4.0 adds a couple of convenient methods (Jan 2019)", "1.4.0",
"j2html 1.5.0 enhances factory methods and class types, overhauls HTML rendering, introduces support for Java modules and fixes several bugs (Jun 2021)",
"1.5.0",
true,
join("Added", code("Automatic-Module-Name"), "to manifest to support JDK 9+"),
join("Added", code("TagCreator::each(DomContent...)")),
join("Added", code("TagCreator::each(Collection, BiFunction)")),
join("Added", code("HtmlBuilder"), "interface, with implementations for ", code("FlatHtml"), "and", code("IndentedHtml")),
join("Added", code("Config.defaults()"), "for customizable configuration instances and", code("Config.global()"), "for (backwards-compatible) static global configuration"),
join("Deprecated old rendering methods. Libraries that use custom Tag implementations should switch to using ", code("HtmlBuilder")),
join("Fixed the use of", code("rawHtml()"), "when constructing the Tag tree"),
join("Fixed text escaping for", code("style()"), "and", code("script()")),
join("Fixed formatting of children for", code("textarea()"), "and", code("pre()")),
join("Fixed appending an unnecessary delimiter to the end of text with", code("join()")),
join("Thanks to", a("Oliver Becker").withHref("https://github.com/obecker"), "for many code improvements")
),

newsPost(
"j2html 1.4.0 adds a couple of convenient methods (Jan 2019)",
"1.4.0",
false,
join("Added", code("TagCreator::each(Map, BiFunction)")),
join("Added", code("Stream<DomContent>"), "variants of", code("each"), "and", code("with"))
),

newsPost(
"j2html 1.3.0 has a couple of features and fixes (May 2018)", "1.3.0",
"j2html 1.3.0 has a couple of features and fixes (May 2018)",
"1.3.0",
false,
join("Added support for", code("Map"), "in", code("each()")),
join("Added osgi metadata"),
join("Added support for", code("Optional"), "in", code("iff()")),
join("Fixed bugs in ", code("renderFormatted()"))
),

newsPost(
"j2html 1.2.2 has performance improvements (Dec 2017)", "1.2.2",
"j2html 1.2.2 has performance improvements (Dec 2017)",
"1.2.2",
false,
join("There have been some massive performance improvements. Big thanks to", a("kicktipp").withHref("https://github.com/kicktipp"), ".")
),

newsPost(
"j2html 1.2.1 fixes some bugs (Nov 2017)", "1.2.1",
"j2html 1.2.1 fixes some bugs (Nov 2017)",
"1.2.1",
false,
join("Fix", em("\"bad closing tag (<!DOCTYPE html/>) when closeEmptyTags is true\""), "bug"),
join("Fix", em("\"can't load static resources from jar\""), "bug"),
join("Fix", em("\"CSSMin stripping last character of CSS rule if rule doesn't end in semi-colon\""), "bug")
),

newsPost(
"j2html 1.2.0 already? (Sep 2017)", "1.2.0",
"j2html 1.2.0 already? (Sep 2017)",
"1.2.0",
false,
join("Added option to render formatted HTML, ex", code("body(...).renderFormatted()")),
join("Added option to configure HTML-formatting-indent via", code("Config.indenter = (int, string) -> {...}")),
join("Added option to configure CSS-minification via", code("Config.cssMinifier = string -> {...}")),
Expand All @@ -81,12 +104,16 @@ public static String render() {
),

newsPost(
"j2html 1.1.0 is out! (Aug 2017)", "1.1.0",
"j2html 1.1.0 is out! (Aug 2017)",
"1.1.0",
false,
join("Added a option to customize TextEscaper via", code("Config.textEscaper = text -> {}"))
),

newsPost(
"j2html 1.0.0 is here! (May 2017)", "1.0.0",
"j2html 1.0.0 is here! (May 2017)",
"1.0.0",
false,
join("v1 is officially done. We will be doing", a("semantic versioning").withHref("http://semver.org/").withTarget("_blank"), "from now on."),
join("All tag methods (", code("div()"), ",", code("p()"), "etc ) can now accept an arbitrary number of", code("DomContent"), "as arguments, eliminating the need for", code("with()"), "in most cases."),
join("Added a shorthand-attribute overloads to all TagCreator methods:", br(), code("div(attrs(\"#id.class\")"), "becomes", code("<div id=\"id\" class=\"class\"></div>")),
Expand All @@ -96,15 +123,19 @@ public static String render() {
),

newsPost(
"j2html 0.99 released! (Apr 2017)", "0.99",
"j2html 0.99 released! (Apr 2017)",
"0.99",
false,
join("Added generic", code("iff()"), "/", code("iffElse()"), "methods for performing if's in method calls."),
join("Added", code("withClasses()"), "to add multiple classes to element. Works well with", code("iff()"), "."),
join("HTML-escaping is now a lot faster (and a lot faster than StringUtils)"),
join("Static files can now be fetched from anywhere, not just classpath")
),

newsPost(
"j2html 0.88 released! (Jan 2017)", "0.88",
"j2html 0.88 released! (Jan 2017)",
"0.88",
false,
text("Closure and StringUtils dependencies removed in favor of custom implementations. Most users seem interested in a very lightweight library."),
code("unsafeHtml()"), text(" is now "), code("rawHtml()"),
text("Added "), code(".equals()"), text(" to Tag-class. Two Tags are equal if they render the same HTML")
Expand Down
19 changes: 17 additions & 2 deletions website/src/main/resources/codeExamples/coreConcepts.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
import static j2html.TagCreator.*; // Use static star import


Config.class // Static config class which holds all configuration
Config.closeEmptyTags = true // all options are public and static, assign using '=' operator
Config.class // Holds all configuration. Offers global configuration or customizable instances
Config.closeEmptyTags = true // Global options are public, static and mutable.
Config.global() // Copy all static Config fields into an instance. Instances are immutable
Config.defaults() // A Config with defaults that are independent of global options
Config.global().withEmptyTagsClosed(true) // A Config that is different from the global options
Config.defaults().withEmptyTagsClosed(true) // A Config that is different from the default options


TagCreator.join() // Method for joining small snippets, like:
Expand All @@ -21,3 +25,14 @@
Tag.class // Is extended by ContainerTag (ex <div></div> and EmptyTag (ex <br>)
Tag.attr(String attribute, Object value) // Set an attribute on the tag
Tag.withXyz(String value) // Calls attr with predefined attribute (ex .withId, .withClass, etc.)
Tag.render(HtmlBuilder builder) // Render HTML using the given builder.
Tag.render() // Shortcut for rendering flat HTML into a string using global Config.
ContainerTag.renderFormatted() // Shortcut for rendering indented HTML into a string using global Config.

HtmlBuilder.class // Interface for composing HTML. Implemented by FlatHtml and IndentedHtml
FlatHtml.into(Appendable) // Render into a stream, file, etc. without indentation or line breaks
FlatHtml.into(Appendable appendable, Config config) // Customize rendering of flat html
IndentedHtml.into(Appendable) // Render human-readable HTML into an stream, file, etc.
IndentedHtml.into(Appendable appendable, Config config) // Customize rendering of intended html
ul(li("one"), li("two")).render(IndentedHtml.inMemory()).toString() // Similar to renderFormatted()
ul(li("one"), li("two")).render(IndentedHtml.into(filewriter)) // Write HTML into a file
2 changes: 1 addition & 1 deletion website/src/main/resources/codeExamples/mavenDep.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<dependency>
<groupId>com.j2html</groupId>
<artifactId>j2html</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
</dependency>

0 comments on commit 4bda363

Please sign in to comment.