lukasjapan / koreander Goto Github PK
View Code? Open in Web Editor NEWKotlin HTML Template Engine
Kotlin HTML Template Engine
Include other files if template is rendered from files, etc
Ref:
More elegant fix for
https://stackoverflow.com/questions/61391828/how-to-unescape-html-in-string-in-koreander-templates
I am currently using Spring 5 and Koreander as the template engine. I am unfortunately getting a java.lang.ArrayIndexOutOfBoundsException: Index 10912 out of bounds for length 10912] error, at de.cvguy.kotlin.koreander.Koreander.compile(Koreander.kt:62) ~[koreander-0.1-WIP.jar:na].
I am using a fat JAR, which requires the Kotlin compiler to be unpacked at startup, via:
bootJar { requiresUnpack '**/kotlin-compiler-*.jar' }
My Spring application looks like:
@SpringBootApplication class TestApplication { @Bean fun koreanderViewResolver(): ViewResolver = KoreanderViewResolver() }
And the corresponding controller:
@Controller class DemoController { @GetMapping("/demo") fun demo(): String { return "example" } }
I'm using compile "de.cvguy.kotlin:koreander-spring:0.+" via Gradle.
<script type="test/javascript">
should probably be:
<script type="text/javascript">
- or even better solution for output:
<script>
as MDN Web Docs writes:
"The HTML5 specification urges authors to omit the attribute rather than provide a redundant MIME type."
-- developer.mozilla.org/en-US/docs/Web/HTML/Element/script
fun main() {
val kor = javaClass.getResource("/index.kor").readText()
Koreander().render(kor, Any())
}
src/main
folder of project and put the following code:
!!! 5
%html
%head
%body
%p.hello Hello World!
Expected to see the <!DOCTYPE html>
declaration instead of the exception.
de.cvguy.kotlin.koreander.exception.UnexpectedDocType: Parse error in tba at 0:4 - Unexpexted DocType 5
exception thrown
de.cvguy.kotlin.koreander.exception.UnexpectedDocType: Parse error in tba at 0:4 - Unexpexted DocType 5
at de.cvguy.kotlin.koreander.parser.KoreanderParseEngine.unshiftDocType(Parser.kt:169)
at de.cvguy.kotlin.koreander.parser.KoreanderParseEngine.parse(Parser.kt:79)
at de.cvguy.kotlin.koreander.parser.KoreanderParser.generateScriptCode(Parser.kt:17)
at de.cvguy.kotlin.koreander.Koreander.compile(Koreander.kt:81)
at com.github.animeshz.konvironment.http.RoutingKt$module$1$1.invokeSuspend(Routing.kt:27)
at com.github.animeshz.konvironment.http.RoutingKt$module$1$1.invoke(Routing.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:273)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:141)
at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:161)
at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:27)
at io.ktor.routing.Routing.executeResult(Routing.kt:147)
at io.ktor.routing.Routing.interceptor(Routing.kt:34)
at io.ktor.routing.Routing$Feature$install$1.invokeSuspend(Routing.kt:99)
at io.ktor.routing.Routing$Feature$install$1.invoke(Routing.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:273)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:141)
at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:161)
at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:27)
at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invokeSuspend(DefaultEnginePipeline.kt:118)
at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invoke(DefaultEnginePipeline.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:273)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:141)
at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:161)
at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:27)
at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invokeSuspend(NettyApplicationCallHandler.kt:40)
at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invoke(NettyApplicationCallHandler.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:55)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:111)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:158)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
at io.ktor.server.netty.NettyApplicationCallHandler.handleRequest(NettyApplicationCallHandler.kt:30)
at io.ktor.server.netty.NettyApplicationCallHandler.channelRead(NettyApplicationCallHandler.kt:24)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:56)
at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:365)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:510)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:518)
at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)
Heya Lukas,
The Japanese beers example from the readme seems to be closing the <head>
tag incorrectly.
Rather than:
<!DOCTYPE html>
<html>
<head>
...
</head>
<body>
...
</body>
</html>
The generated HTML looks like (inspect the payload, not the HTML inspector in the browser):
<!DOCTYPE html>
<html>
<head>
...
<body>
...
</body>
</head>
</html>
I've observed a similar issue with %p
tags that include a linebreak. For example:
!!! 5
%html
%body
%p
line 1
line 2
line 3
%div
Renders correctly, but introducing a linebreak in the paragraph:
!!! 5
%html
%body
%p
line 1
%br
line 2
%div
Instead results in:
<!DOCTYPE html>
<html>
<body>
<p>
line 1
<br>
line 2
<div></div>
</p>
</body>
</html>
Am I nesting the linebreak incorrectly in the paragraph or are there some inconsistencies in how the indentations are read?
Many thanks,
fish
Heya Lukas,
Love the syntax, but I've ran into an issue with the shortcut notation for assigning classes.
According to the readme it should be possible to use %tag.myclass โ <tag class="myclass"></tag>
.
However, when parsing %span.test test span with test class
the result is
<span.test>test span with test class</span.test>
instead.
Would be awesome if you could try to replicate,
Many thanks in advance and a fantastic holiday season,
fish
template.kor:
!!! 5
%html
%head
%title Test title
%body
.test
%p test div with test class
%span.test test span with test class
app.kt:
data class Model(val name: String = "")
class app {
fun generateHtml(): String {
val viewUrl = javaClass.getResource("template.kor")
return Koreander().render(viewUrl, Model())
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.