From 984599ae251b7ce3226faba347d2a2bb8828266e Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Fri, 11 May 2018 16:48:54 +0200 Subject: [PATCH] Use tabs for indentation --- README.adoc | 163 +++++++++--------- src/main/kotlin/blog/BlogApplication.kt | 2 +- src/main/kotlin/blog/MarkdownConverter.kt | 16 +- src/main/resources/templates/article.mustache | 16 +- src/main/resources/templates/blog.mustache | 42 ++--- src/main/resources/templates/header.mustache | 2 +- 6 files changed, 120 insertions(+), 121 deletions(-) diff --git a/README.adoc b/README.adoc index 347eab7..ce0ce63 100644 --- a/README.adoc +++ b/README.adoc @@ -154,7 +154,7 @@ import org.springframework.boot.runApplication class BlogApplication fun main(args: Array) { - runApplication(*args) + runApplication(*args) } ---- @@ -205,7 +205,7 @@ We also need to create the associated Mustache templates. ---- - {{title}} + {{title}} ---- @@ -454,19 +454,19 @@ fun LocalDateTime.format() = this.format(englishDateFormatter) private val daysLookup = (1..31).associate { it.toLong() to getOrdinal(it) } private val englishDateFormatter = DateTimeFormatterBuilder() - .appendPattern("MMMM") - .appendLiteral(" ") - .appendText(ChronoField.DAY_OF_MONTH, daysLookup) - .appendLiteral(" ") - .appendPattern("yyyy") - .toFormatter(Locale.ENGLISH) + .appendPattern("MMMM") + .appendLiteral(" ") + .appendText(ChronoField.DAY_OF_MONTH, daysLookup) + .appendLiteral(" ") + .appendPattern("yyyy") + .toFormatter(Locale.ENGLISH) private fun getOrdinal(n: Int) = when { - n in 11..13 -> "${n}th" - n % 10 == 1 -> "${n}st" - n % 10 == 2 -> "${n}nd" - n % 10 == 3 -> "${n}rd" - else -> "${n}th" + n in 11..13 -> "${n}th" + n % 10 == 1 -> "${n}st" + n % 10 == 2 -> "${n}nd" + n % 10 == 3 -> "${n}rd" + else -> "${n}th" } ---- @@ -493,15 +493,15 @@ We introduce a `MarkdownConverter` bean, which leverages https://kotlinlang.org/ @Service class MarkdownConverter : (String?) -> String { - private val parser = Parser.builder().extensions(Arrays.asList(AutolinkExtension.create())).build() - private val renderer = HtmlRenderer.builder().build() + private val parser = Parser.builder().extensions(Arrays.asList(AutolinkExtension.create())).build() + private val renderer = HtmlRenderer.builder().build() - override fun invoke(input: String?): String { - if (input == null || input == "") { - return "" - } - return renderer.render(parser.parse(input)) - } + override fun invoke(input: String?): String { + if (input == null || input == "") { + return "" + } + return renderer.render(parser.parse(input)) + } } ---- @@ -516,7 +516,6 @@ class BlogApplication { @Bean fun mustacheCompiler(loader: Mustache.TemplateLoader?) = Mustache.compiler().escapeHTML(false).withLoader(loader) - } ---- @@ -531,17 +530,17 @@ We update the "blog" Mustache templates.
- {{#articles}} -
-
-

{{title}}

- -
-
- {{headline}} -
-
- {{/articles}} + {{#articles}} +
+
+

{{title}}

+ +
+
+ {{headline}} +
+
+ {{/articles}}
{{> footer}} @@ -555,16 +554,16 @@ And we create an "article new one". {{> header}}
-
-

{{article.title}}

- -
+
+

{{article.title}}

+ +
-
- {{article.headline}} +
+ {{article.headline}} - {{article.content}} -
+ {{article.content}} +
{{> footer}} @@ -580,40 +579,40 @@ class HtmlController(private val repository: ArticleRepository, private val markdownConverter: MarkdownConverter) { @GetMapping("/") - fun blog(model: Model): String { - model["title"] = properties.title - model["banner"] = properties.banner - model["articles"] = repository.findAllByOrderByAddedAtDesc().map { it.render() } - return "blog" - } + fun blog(model: Model): String { + model["title"] = properties.title + model["banner"] = properties.banner + model["articles"] = repository.findAllByOrderByAddedAtDesc().map { it.render() } + return "blog" + } - @GetMapping("/article/{id}") - fun article(@PathVariable id: Long, model: Model): String { - val article = repository - .findById(id) - .orElseThrow { IllegalArgumentException("Wrong article id provided") } - .render() - model["title"] = article.title - model["article"] = article - return "article" - } + @GetMapping("/article/{id}") + fun article(@PathVariable id: Long, model: Model): String { + val article = repository + .findById(id) + .orElseThrow { IllegalArgumentException("Wrong article id provided") } + .render() + model["title"] = article.title + model["article"] = article + return "article" + } - fun Article.render() = RenderedArticle( - title, - markdownConverter.invoke(headline), - markdownConverter.invoke(content), - author, - id, - addedAt.format() - ) + fun Article.render() = RenderedArticle( + title, + markdownConverter.invoke(headline), + markdownConverter.invoke(content), + author, + id, + addedAt.format() + ) - data class RenderedArticle( - val title: String, - val headline: String, - val content: String, - val author: User, - val id: Long?, - val addedAt: String) + data class RenderedArticle( + val title: String, + val headline: String, + val content: String, + val author: User, + val id: Long?, + val addedAt: String) } ---- @@ -855,16 +854,16 @@ Edit the template and the controller accordingly.
- {{#banner.title}} -
- - -
- {{/banner.title}} + {{#banner.title}} +
+ + +
+ {{/banner.title}} ... diff --git a/src/main/kotlin/blog/BlogApplication.kt b/src/main/kotlin/blog/BlogApplication.kt index 6fae682..6616e84 100644 --- a/src/main/kotlin/blog/BlogApplication.kt +++ b/src/main/kotlin/blog/BlogApplication.kt @@ -40,5 +40,5 @@ class BlogApplication { } fun main(args: Array) { - runApplication(*args) + runApplication(*args) } diff --git a/src/main/kotlin/blog/MarkdownConverter.kt b/src/main/kotlin/blog/MarkdownConverter.kt index 4dcc4e1..0002f97 100644 --- a/src/main/kotlin/blog/MarkdownConverter.kt +++ b/src/main/kotlin/blog/MarkdownConverter.kt @@ -24,13 +24,13 @@ import org.springframework.stereotype.Service @Service class MarkdownConverter : (String?) -> String { - private val parser = Parser.builder().extensions(listOf(AutolinkExtension.create())).build() - private val renderer = HtmlRenderer.builder().build() + private val parser = Parser.builder().extensions(listOf(AutolinkExtension.create())).build() + private val renderer = HtmlRenderer.builder().build() - override fun invoke(input: String?): String { - if (input == null || input == "") { - return "" - } - return renderer.render(parser.parse(input)) - } + override fun invoke(input: String?): String { + if (input == null || input == "") { + return "" + } + return renderer.render(parser.parse(input)) + } } diff --git a/src/main/resources/templates/article.mustache b/src/main/resources/templates/article.mustache index 57618e8..0ecbaa9 100644 --- a/src/main/resources/templates/article.mustache +++ b/src/main/resources/templates/article.mustache @@ -1,16 +1,16 @@ {{> header}}
-
-

{{article.title}}

- -
+
+

{{article.title}}

+ +
-
- {{article.headline}} +
+ {{article.headline}} - {{article.content}} -
+ {{article.content}} +
{{> footer}} \ No newline at end of file diff --git a/src/main/resources/templates/blog.mustache b/src/main/resources/templates/blog.mustache index 9db0095..0795ba0 100644 --- a/src/main/resources/templates/blog.mustache +++ b/src/main/resources/templates/blog.mustache @@ -2,28 +2,28 @@
- {{#banner.title}} -
- - -
- {{/banner.title}} + {{#banner.title}} +
+ + +
+ {{/banner.title}} - {{#articles}} -
-
-

{{title}}

- -
-
- {{headline}} -
-
- {{/articles}} + {{#articles}} +
+
+

{{title}}

+ +
+
+ {{headline}} +
+
+ {{/articles}}
{{> footer}} \ No newline at end of file diff --git a/src/main/resources/templates/header.mustache b/src/main/resources/templates/header.mustache index a616a5a..7c38147 100644 --- a/src/main/resources/templates/header.mustache +++ b/src/main/resources/templates/header.mustache @@ -1,6 +1,6 @@ - {{title}} + {{title}}

{{title}}