2021-08-17

This commit is contained in:
2021-08-17 18:37:42 +09:00
parent ed54dbad52
commit d55894b614
20 changed files with 415 additions and 2 deletions

View File

@@ -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 {
}

View 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;
}

View File

@@ -0,0 +1,2 @@
<h1>Sample Mustache</h1>
<p>Hello, <span>{{person.name}}</span></p>

View 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);
}
}