-
-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathDocApp.java
More file actions
83 lines (67 loc) · 2.8 KB
/
DocApp.java
File metadata and controls
83 lines (67 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby.adoc;
import static org.slf4j.helpers.NOPLogger.NOP_LOGGER;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import io.jooby.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
import io.methvin.watcher.DirectoryWatcher;
public class DocApp extends Jooby {
static {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}
{
Path site = DocGenerator.basedir().resolve("asciidoc").resolve("site");
assets("/*", site);
onStarted(SneakyThrows.throwingRunnable(() ->
getLog().info("Access to maven properties is available from ascii files. If you want to access to `${avaje.inject.version}` uses the `{avaje_inject_version}` syntax and make sure to set the `subs` attribute, like:\n\n" +
"[source, xml, role = \"primary\", subs=\"verbatim,attributes\"]\n" +
" .... {avaje_inject_version}\n")
));
}
public static void main(String[] args) throws Exception {
// watch and block
LoggingService.configure(DocApp.class.getClassLoader(), List.of("dev"));
Path basedir = DocGenerator.basedir();
Logger log = LoggerFactory.getLogger(DocGenerator.class);
DocGenerator.generate(basedir, false, Arrays.asList(args).contains("v1"), true);
Server server = Server.loadServer(new ServerOptions().setPort(4000));
runApp(args, server, DocApp::new);
Path outdir = basedir.resolve("asciidoc").resolve("site");
Path themeCssDir = basedir.resolve("js").resolve("styles");
DirectoryWatcher watcher =
DirectoryWatcher.builder()
.path(basedir)
.logger(NOP_LOGGER)
.listener(
event -> {
Path file = event.path();
if (!file.startsWith(outdir)) {
if (file.toString().endsWith(".js")
|| file.toString().endsWith(".html")
|| file.toString().endsWith(".adoc")) {
try {
DocGenerator.generate(
basedir, false, false, file.toString().endsWith(".adoc"));
} catch (Exception x) {
log.error("Site build resulted in exception", x);
}
} else if (file.toString().endsWith("theme.css")) {
Files.copy(file, outdir.resolve("js").resolve("styles").resolve("theme.css"), StandardCopyOption.REPLACE_EXISTING);
}
}
})
.build();
watcher.watch();
}
}