Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jh-boot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jan Hrabal
jh-boot
Commits
9f7ec9c0
Commit
9f7ec9c0
authored
Aug 08, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
templates
parent
13ec164f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
6 deletions
+27
-6
JhTemplateConfig.java
src/main/java/com/jh/common/template/JhTemplateConfig.java
+6
-2
TemplateLoader.java
src/main/java/com/jh/common/template/TemplateLoader.java
+1
-1
HandlebarsTemplateService.java
...common/template/handlebars/HandlebarsTemplateService.java
+20
-3
No files found.
src/main/java/com/jh/common/template/JhTemplateConfig.java
View file @
9f7ec9c0
...
...
@@ -2,16 +2,20 @@ package com.jh.common.template;
import
org.springframework.context.annotation.Bean
;
import
com.jh.common.template.handlebars.HandlebarsTemplateService
;
public
class
JhTemplateConfig
{
@Bean
public
Template
Engine
templateEngine
()
{
public
Template
Loader
templateLoader
()
{
return
null
;
}
@Bean
public
TemplateService
templateService
()
{
return
null
;
HandlebarsTemplateService
service
=
new
HandlebarsTemplateService
();
service
.
setTemplateLoader
(
templateLoader
());
return
service
;
}
...
...
src/main/java/com/jh/common/template/TemplateLoader.java
View file @
9f7ec9c0
...
...
@@ -3,6 +3,6 @@ package com.jh.common.template;
public
interface
TemplateLoader
{
String
loadTemplate
(
String
templateName
);
}
src/main/java/com/jh/common/template/handlebars/HandlebarsTemplateService.java
View file @
9f7ec9c0
package
com
.
jh
.
common
.
template
.
handlebars
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.Writer
;
import
java.text.MessageFormat
;
import
java.time.LocalDate
;
...
...
@@ -25,6 +23,7 @@ import com.github.jknack.handlebars.context.JavaBeanValueResolver;
import
com.github.jknack.handlebars.context.MapValueResolver
;
import
com.jh.common.i18n.I18nContext
;
import
com.jh.common.i18n.I18nUtils
;
import
com.jh.common.template.TemplateLoader
;
import
com.jh.common.template.TemplateService
;
...
...
@@ -74,6 +73,8 @@ public class HandlebarsTemplateService implements TemplateService {
private
Handlebars
handlebars
;
private
TemplateLoader
templateLoader
;
/**
* Initializes instance.
...
...
@@ -157,9 +158,18 @@ public class HandlebarsTemplateService implements TemplateService {
Template
template
=
useCache
?
templateCache
.
get
(
name
)
:
null
;
//TODO read template
if
(
template
==
null
)
{
if
(
templateLoader
==
null
)
{
throw
new
IllegalStateException
(
"No template loader set"
);
}
String
s
=
templateLoader
.
loadTemplate
(
templateCode
);
try
{
template
=
handlebars
.
compileInline
(
s
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Cannot compile template"
,
e
);
}
if
(
useCache
)
{
templateCache
.
put
(
name
,
template
);
}
...
...
@@ -219,4 +229,11 @@ public class HandlebarsTemplateService implements TemplateService {
}
public
void
setTemplateLoader
(
TemplateLoader
templateLoader
)
{
this
.
templateLoader
=
templateLoader
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment