2021-08-17
This commit is contained in:
14
mustache/build.gradle.kts
Normal file
14
mustache/build.gradle.kts
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("elex-java")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.github.spullara.mustache.java:compiler:0.9.7")
|
||||
}
|
||||
20
mustache/logback.xml
Normal file
20
mustache/logback.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Examples for Java
|
||||
~
|
||||
~ Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
~ https://www.elex-project.com/
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="TRACE">
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
public class MustacheSample {
|
||||
}
|
||||
18
mustache/src/main/java/kr/pe/elex/examples/Person.java
Normal file
18
mustache/src/main/java/kr/pe/elex/examples/Person.java
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Person {
|
||||
private String name;
|
||||
private int age;
|
||||
}
|
||||
2
mustache/src/main/resources/sample.mustache
Normal file
2
mustache/src/main/resources/sample.mustache
Normal file
@@ -0,0 +1,2 @@
|
||||
<h1>Sample Mustache</h1>
|
||||
<p>Hello, <span>{{person.name}}</span></p>
|
||||
41
mustache/src/test/java/kr/pe/elex/examples/MustacheTest.java
Normal file
41
mustache/src/test/java/kr/pe/elex/examples/MustacheTest.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import com.elex_project.abraxas.Console;
|
||||
import com.github.mustachejava.DefaultMustacheFactory;
|
||||
import com.github.mustachejava.Mustache;
|
||||
import com.github.mustachejava.MustacheFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class MustacheTest {
|
||||
|
||||
@Test
|
||||
void test(){
|
||||
MustacheFactory factory = new DefaultMustacheFactory();
|
||||
Mustache mustache = factory
|
||||
//.compile("/sample.mustache"); // 리소스로부터 템플릿을 불러온다.
|
||||
.compile(new InputStreamReader(getClass().getResourceAsStream("/sample.mustache")),
|
||||
"sample");
|
||||
|
||||
//Object context; // Object, List, Map 등 템플릿에 전달될 데이터
|
||||
Map<String, Object> context = new HashMap<>();
|
||||
context.put("person",new Person("Charlie", 14));
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
mustache.execute(writer, context);
|
||||
String result = writer.toString();
|
||||
|
||||
Console.writeLine(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user