Skip to content

Commit

Permalink
Everything works!
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schuehly committed Sep 1, 2023
1 parent c1210a8 commit e055a95
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ interface IViewContext {
companion object {
var componentBean: Any? = null
var componentTemplate: String? = null
var jteTemplateEngine: Any? = null
var templateSuffx: String = ""
fun getAttributes(context: IViewContext): Map<String, Any> {
return context::class.java.declaredFields.map { field ->
context::class.java.getDeclaredField(field.name).let {
Expand All @@ -12,7 +14,11 @@ interface IViewContext {
}
}.toMap()
}
}
}

class EmptyViewContext() : IViewContext
fun getTemplate(context: IViewContext): String {
val componentName = context.javaClass.enclosingClass.simpleName.substringBefore("$$")
val componentPackage = context.javaClass.enclosingClass.`package`.name.replace(".", "/") + "/"
return "$componentPackage$componentName$templateSuffx"
}
}
}
30 changes: 8 additions & 22 deletions examples/jte-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,18 @@ plugins {
kotlin("jvm") version "1.8.21"
kotlin("plugin.spring") version "1.8.21"
kotlin("kapt") version "1.8.21"
id("gg.jte.gradle") version("3.0.2")
// id("gg.jte.gradle") version("3.0.2")
}

group = "de.tschuehly"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

jte{
generate()
}
repositories {
mavenCentral()
maven("https://jitpack.io")
}

//jte {
// sourceDirectory.set(Path.of("src/main/kotlin"))
// generate()
//}
dependencies {
// implementation("de.tschuehly:spring-view-component-jte:0.6.0")
implementation("de.tschuehly:spring-view-component-jte:0.6.2-SNAPSHOT")
Expand Down Expand Up @@ -54,17 +47,10 @@ tasks.withType<KotlinCompile> {
tasks.withType<Test> {
useJUnitPlatform()
}
//sourceSets {
// main {
// resources {
// srcDir("src/main/kotlin")
// exclude("**/*.kt")
// }
// }
// test {
// resources {
// srcDir("src/test/kotlin")
// exclude("**/*.kt")
// }
// }
//}
sourceSets{
main{
java{
srcDir("build/generated-sources/jte")
}
}
}
50 changes: 0 additions & 50 deletions examples/jte-example/src/main/jte/TestViewComponent.jte

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
@param de.tschuehly.jteviewcomponentdemo.web.action.ActionViewComponent.Person person
@param java.util.HashMap<Integer,String> itemList
@param Integer counter

<div>TEST12
<script defer src="/webjars/htmx.org/dist/htmx.min.js"></script>
<html>
<head>
<script src="http://localhost:35729/livereload.js"></script>
<script defer src="/webjars/htmx.org/dist/htmx.min.js"></script>
</head>
<body>
<h2>ViewAction Get CountUp</h2>

<button view:action="countUp">Default ViewAction [GET]</button>
<h3>${counter}</h3>


<h2>ViewAction Post AddItem</h2>
<form view:action="addItem">
<input type="text" name="item">
Expand All @@ -36,15 +38,16 @@

<form style="display: inline-grid; gap: 0.5rem">
<label>
Name <input type="text" name="name" value="${person.getName()}">
Name <input type="text" id="name" name="name" value="${person.getName()}">
</label>
<label>
Age: <input type="number" name="age" value="${person.getAge()}">
Age: <input type="number" id="age" name="age" value="${person.getAge()}">
</label>
<label>
Location: <input type="text" name="location" value="${person.getLocation()}">
Location: <input type="text" id="location" name="location" value="${person.getLocation()}">
</label>
<button type="submit" view:action="savePersonPut">Save Changes using Put</button>
<button type="submit" view:action="savePersonPatch">Save Changes using Patch</button>
</form>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import de.tschuehly.jteviewcomponentdemo.core.ExampleService
import de.tschuehly.spring.viewcomponent.core.IViewContext
import de.tschuehly.spring.viewcomponent.core.action.*
import de.tschuehly.spring.viewcomponent.core.component.ViewComponent
import de.tschuehly.spring.viewcomponent.jte.ViewContext

@ViewComponent
class ActionViewComponent(
val exampleService: ExampleService
) {
data class ActionView(val itemList: MutableMap<Int, String>, val counter: Int, val person: Person) : IViewContext
data class ActionView(val itemList: MutableMap<Int, String>, val counter: Int, val person: Person) : ViewContext

fun render() = ActionView(exampleService.itemList, counter, person)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<html>
<div>
<div>
<h1>This is the IndexViewComponent</h1>
</div>
<a href="/">IndexViewComponent</a><br>
<a href="/simple">SimpleViewComponent</a><br>
<a href="/layout">LayoutViewComponent</a><br>
<a href="/action">ActionViewComponent</a><br>
<a href="/nested-action">NestedActionViewComponent</a>
</div>
<h1>This is the IndexViewComponent</h1>

</div>
<a href="/">IndexViewComponent</a><br>
<a href="/simple">SimpleViewComponent</a><br>
<a href="/layout">LayoutViewComponent</a><br>
<a href="/action">ActionViewComponent</a><br>
<a href="/nested-action">NestedActionViewComponent</a><br>

</html>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package de.tschuehly.jteviewcomponentdemo.web.index

import de.tschuehly.spring.viewcomponent.core.component.ViewComponent
import de.tschuehly.spring.viewcomponent.jte.EmptyViewContext

@ViewComponent
class IndexViewComponent {
fun render() = de.tschuehly.spring.viewcomponent.core.EmptyViewContext()
fun render() = EmptyViewContext()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import de.tschuehly.spring.viewcomponent.jte.ViewContext
@param ViewContext nestedViewComponent
@param de.tschuehly.spring.viewcomponent.jte.ViewContext nestedViewComponent
<html>

<nav>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package de.tschuehly.jteviewcomponentdemo.web.layout

import de.tschuehly.spring.viewcomponent.core.IViewContext
import de.tschuehly.spring.viewcomponent.core.component.ViewComponent
import de.tschuehly.spring.viewcomponent.jte.ViewContext

@ViewComponent
class LayoutViewComponent {
data class LayoutView(val nestedViewComponent: IViewContext) : IViewContext
data class LayoutView(val nestedViewComponent: ViewContext) : ViewContext

fun render(nestedViewComponent: IViewContext) = LayoutView(nestedViewComponent)
fun render(nestedViewComponent: ViewContext) = LayoutView(nestedViewComponent)

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import de.tschuehly.jteviewcomponentdemo.core.ExampleService
import de.tschuehly.spring.viewcomponent.core.IViewContext
import de.tschuehly.spring.viewcomponent.core.action.PostViewAction
import de.tschuehly.spring.viewcomponent.core.component.ViewComponent
import de.tschuehly.spring.viewcomponent.core.toProperty
import de.tschuehly.spring.viewcomponent.jte.ViewContext

@ViewComponent
class SimpleViewComponent(
val exampleService: ExampleService
) {
fun render(): IViewContext {
return HelloWorldView(exampleService.getHelloWorld())
}
fun render() = HelloWorldView(exampleService.getHelloWorld())

data class HelloWorldView(val helloWorld: String) : IViewContext
data class HelloWorldView(val helloWorld: String) : ViewContext

@PostViewAction
fun testAction(): IViewContext {
Expand Down
Loading

0 comments on commit e055a95

Please sign in to comment.