diff options
author | Marvin Borner | 2019-04-04 15:57:07 +0200 |
---|---|---|
committer | Marvin Borner | 2019-04-04 15:57:07 +0200 |
commit | fb58f161a5036e3f1fdc040679b6ee9efe22ade2 (patch) | |
tree | 03affd2c35249e98220dd238390984033c18f593 | |
parent | b71c055a8a198a1071b5905904096630aba98361 (diff) |
Added hot reloading of rocker templates
-rw-r--r-- | build.gradle | 6 | ||||
-rw-r--r-- | src/main/kotlin/App.kt | 8 | ||||
-rw-r--r-- | src/main/resources/compiled-views/rocker-compiler.conf | 11 | ||||
-rw-r--r-- | src/main/resources/generated-views/files.java (renamed from src/main/resources/compiled-views/files.java) | 9 | ||||
-rw-r--r-- | src/main/resources/generated-views/fileview.java (renamed from src/main/resources/compiled-views/fileview.java) | 25 | ||||
l--------- | src/main/resources/rocker-compiler.conf | 1 | ||||
-rw-r--r-- | src/main/resources/views/fileview.rocker.html | 2 |
7 files changed, 39 insertions, 23 deletions
diff --git a/build.gradle b/build.gradle index 2a504de..b3f570a 100644 --- a/build.gradle +++ b/build.gradle @@ -13,9 +13,10 @@ repositories { rocker { main { - optimize = true + optimize = false templateDir = file('src/main/resources/views') - outputDir = file('src/main/resources/compiled-views') + outputDir = file('src/main/resources/generated-views') + classDir = file('src/main/resources/compiled-views') } } @@ -27,6 +28,7 @@ dependencies { compile 'org.jetbrains.exposed:exposed:0.13.2' compile "org.xerial:sqlite-jdbc:3.21.0.1" compile "org.thymeleaf:thymeleaf:3.0.9.RELEASE" + compile group: 'com.fizzed', name: 'rocker-compiler', version: '1.2.1' } compileKotlin { diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt index a9e2018..327dec4 100644 --- a/src/main/kotlin/App.kt +++ b/src/main/kotlin/App.kt @@ -1,6 +1,7 @@ package space.anity import com.fizzed.rocker.* +import com.fizzed.rocker.runtime.* import io.javalin.* import io.javalin.core.util.* import io.javalin.rendering.* @@ -14,6 +15,8 @@ val db = DatabaseController() fun main() { val app = Javalin.create().enableStaticFiles("../resources/").start(7000) + // Set up templating + RockerRuntime.getInstance().isReloading = true JavalinRenderer.register( FileRenderer { filepath, model -> Rocker.template(filepath).bind(model).render().toString() }, ".rocker.html" ) @@ -77,8 +80,3 @@ fun upload(ctx: Context) { throw BadRequestResponse("Error: Please enter a filename.") } } - - - - - diff --git a/src/main/resources/compiled-views/rocker-compiler.conf b/src/main/resources/compiled-views/rocker-compiler.conf new file mode 100644 index 0000000..a8998bd --- /dev/null +++ b/src/main/resources/compiled-views/rocker-compiler.conf @@ -0,0 +1,11 @@ +#rocker.output.dir +#Thu Apr 04 15:51:56 CEST 2019 +rocker.class.dir=/home/melvin/Coding/kloud/src/main/resources/compiled-views +rocker.option.extendsClass=com.fizzed.rocker.runtime.DefaultRockerTemplate +rocker.option.optimize=false +rocker.output.dir=/home/melvin/Coding/kloud/src/main/resources/generated-views +rocker.option.targetCharset=UTF-8 +rocker.template.dir=/home/melvin/Coding/kloud/src/main/resources/views +rocker.option.combineAdjacentPlain=true +rocker.option.javaVersion=1.8 +rocker.option.extendsModelClass=com.fizzed.rocker.runtime.DefaultRockerModel diff --git a/src/main/resources/compiled-views/files.java b/src/main/resources/generated-views/files.java index b37859f..935aca1 100644 --- a/src/main/resources/compiled-views/files.java +++ b/src/main/resources/generated-views/files.java @@ -1,4 +1,3 @@ - import com.fizzed.rocker.RenderingException; import com.fizzed.rocker.runtime.DefaultRockerTemplate; import com.fizzed.rocker.runtime.PlainTextUnloadedClassLoader; @@ -31,6 +30,10 @@ public class files extends com.fizzed.rocker.runtime.DefaultRockerModel { return "-1618097059"; } + static public long getModifiedAt() { + return 1554383637000L; + } + static public String[] getArgumentNames() { return new String[]{"files"}; } @@ -54,8 +57,8 @@ public class files extends com.fizzed.rocker.runtime.DefaultRockerModel { @Override protected DefaultRockerTemplate buildTemplate() throws RenderingException { - // optimized for performance (via rocker.optimize flag; no auto reloading) - return new Template(this); + // optimized for convenience (runtime auto reloading enabled if rocker.reloading=true) + return com.fizzed.rocker.runtime.RockerRuntime.getInstance().getBootstrap().template(this.getClass(), this); } static public class Template extends com.fizzed.rocker.runtime.DefaultRockerTemplate { diff --git a/src/main/resources/compiled-views/fileview.java b/src/main/resources/generated-views/fileview.java index 67de59f..94785ca 100644 --- a/src/main/resources/compiled-views/fileview.java +++ b/src/main/resources/generated-views/fileview.java @@ -1,4 +1,3 @@ - import com.fizzed.rocker.RenderingException; import com.fizzed.rocker.runtime.DefaultRockerTemplate; import com.fizzed.rocker.runtime.PlainTextUnloadedClassLoader; @@ -28,6 +27,10 @@ public class fileview extends com.fizzed.rocker.runtime.DefaultRockerModel { return "868254209"; } + static public long getModifiedAt() { + return 1554384470000L; + } + static public String[] getArgumentNames() { return new String[]{"content"}; } @@ -51,15 +54,15 @@ public class fileview extends com.fizzed.rocker.runtime.DefaultRockerModel { @Override protected DefaultRockerTemplate buildTemplate() throws RenderingException { - // optimized for performance (via rocker.optimize flag; no auto reloading) - return new Template(this); + // optimized for convenience (runtime auto reloading enabled if rocker.reloading=true) + return com.fizzed.rocker.runtime.RockerRuntime.getInstance().getBootstrap().template(this.getClass(), this); } static public class Template extends com.fizzed.rocker.runtime.DefaultRockerTemplate { - // <!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\"\n name=\"viewport\">\n <meta content=\"ie=edge\" http-equiv=\"X-UA-Compatible\">\n <title>Fileview</title>\n</head>\n<body>\n<textarea disabled style=\"border: none; background-color: white; width: 100vw; height: 100vh\">\n + // <!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\"\n name=\"viewport\">\n <meta content=\"ie=edge\" http-equiv=\"X-UA-Compatible\">\n <title>Fileview</title>\n</head>\n<body>\n static private final byte[] PLAIN_TEXT_0_0; - // \n</textarea>\n</body>\n</html>\n + // \n</body>\n</html>\n static private final byte[] PLAIN_TEXT_1_0; static { @@ -85,19 +88,19 @@ public class fileview extends com.fizzed.rocker.runtime.DefaultRockerModel { // PlainText @ [1:23] __internal.aboutToExecutePosInTemplate(1, 23); __internal.writeValue(PLAIN_TEXT_0_0); - // ValueExpression @ [14:5] - __internal.aboutToExecutePosInTemplate(14, 5); + // ValueExpression @ [13:5] + __internal.aboutToExecutePosInTemplate(13, 5); __internal.renderValue(content, false); - // PlainText @ [14:13] - __internal.aboutToExecutePosInTemplate(14, 13); + // PlainText @ [13:13] + __internal.aboutToExecutePosInTemplate(13, 13); __internal.writeValue(PLAIN_TEXT_1_0); } } private static class PlainText { - static private final String PLAIN_TEXT_0_0 = "<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\"\n name=\"viewport\">\n <meta content=\"ie=edge\" http-equiv=\"X-UA-Compatible\">\n <title>Fileview</title>\n</head>\n<body>\n<textarea disabled style=\"border: none; background-color: white; width: 100vw; height: 100vh\">\n "; - static private final String PLAIN_TEXT_1_0 = "\n</textarea>\n</body>\n</html>\n"; + static private final String PLAIN_TEXT_0_0 = "<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\"\n name=\"viewport\">\n <meta content=\"ie=edge\" http-equiv=\"X-UA-Compatible\">\n <title>Fileview</title>\n</head>\n<body>\n "; + static private final String PLAIN_TEXT_1_0 = "\n</body>\n</html>\n"; } diff --git a/src/main/resources/rocker-compiler.conf b/src/main/resources/rocker-compiler.conf new file mode 120000 index 0000000..07c7588 --- /dev/null +++ b/src/main/resources/rocker-compiler.conf @@ -0,0 +1 @@ +compiled-views/rocker-compiler.conf
\ No newline at end of file diff --git a/src/main/resources/views/fileview.rocker.html b/src/main/resources/views/fileview.rocker.html index 910bdf2..250f34f 100644 --- a/src/main/resources/views/fileview.rocker.html +++ b/src/main/resources/views/fileview.rocker.html @@ -10,8 +10,6 @@ <title>Fileview</title> </head> <body> -<textarea disabled style="border: none; background-color: white; width: 100vw; height: 100vh"> @content -</textarea> </body> </html> |