aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/controllers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-08-18 16:22:05 +0300
committerGravatar Vitaly Takmazov2017-08-18 16:22:05 +0300
commitdf58ac0c9854cc33606e7379f1e87a00b0ef8a2d (patch)
tree569afb88c46c42b4bd633bfcdf55ed43f06e995c /juick-www/src/main/java/com/juick/www/controllers
parent332a6ff3074b5f432108be778e722ab12f3201c4 (diff)
www: render help from markdown
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/controllers')
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Help.java29
1 files changed, 13 insertions, 16 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Help.java b/juick-www/src/main/java/com/juick/www/controllers/Help.java
index 4198b23a..335f4b7a 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Help.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Help.java
@@ -18,23 +18,22 @@
package com.juick.www.controllers;
import com.juick.server.util.HttpNotFoundException;
-import com.juick.service.MessagesService;
import com.juick.server.util.UserUtils;
+import com.juick.service.MessagesService;
import com.juick.www.HelpService;
import com.juick.www.WebApp;
+import org.commonmark.parser.Parser;
+import org.commonmark.renderer.html.HtmlRenderer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Locale;
import java.util.Objects;
-import java.util.Optional;
/**
* Created by aalexeev on 11/21/16.
@@ -47,25 +46,23 @@ public class Help {
private MessagesService messagesService;
@Inject
private WebApp webApp;
+ @Inject
+ private Parser cmParser;
+ @Inject
+ private HtmlRenderer helpRenderer;
@GetMapping({"/help/", "/help", "/help/{langOrPage}", "/help/{lang}/{page}"})
public String showHelp(
- HttpServletRequest request,
- HttpServletResponse response,
Locale locale,
- @PathVariable("lang") Optional<String> langParam,
- @PathVariable("page") Optional<String> pageParam,
- @PathVariable("langOrPage") Optional<String> langOrPageParam,
+ @PathVariable(required = false, name = "lang") String lang,
+ @PathVariable(required = false, name = "page") String page,
+ @PathVariable(required = false, name = "langOrPage") String langOrPage,
Model model) throws IOException, URISyntaxException {
com.juick.User visitor = UserUtils.getCurrentUser();
- String page = pageParam.orElse("index");
- String lang = langParam.orElse(locale.getLanguage());
String navigation = null;
- if (langOrPageParam.isPresent()) {
- String langOrPage = langOrPageParam.get();
-
+ if (langOrPage != null) {
if (helpService.canBeLang(langOrPage)) {
navigation = helpService.getHelp("navigation", langOrPage);
if (navigation != null)
@@ -86,8 +83,8 @@ public class Help {
if (content == null || navigation == null)
throw new HttpNotFoundException();
- model.addAttribute("navigation", navigation);
- model.addAttribute("content", content);
+ model.addAttribute("navigation", helpRenderer.render(cmParser.parse(navigation)));
+ model.addAttribute("content", helpRenderer.render(cmParser.parse(content)));
model.addAttribute("visitor", visitor);
return "views/help";