mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-30 15:11:38 +00:00
added template support to echo
replaced HashMaps for templates with concrete models, so the interface is easier known added rendering method for objects directly added default parameters available for commands split up service beans for server/channel into management and service bean added server reference in AChannel refactored join/leave listener
This commit is contained in:
@@ -18,12 +18,7 @@ public class DatabaseTemplateLoader implements TemplateLoader {
|
||||
|
||||
@Override
|
||||
public Object findTemplateSource(String s) throws IOException {
|
||||
TemplateDto templateDtoByKey = templateService.getTemplateByKey(s);
|
||||
if(templateDtoByKey != null){
|
||||
return templateDtoByKey;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return templateService.getTemplateByKey(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.templating.TemplateDto;
|
||||
import dev.sheldan.abstracto.templating.TemplateService;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.TemplateException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -13,6 +14,7 @@ import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TemplateServiceBean implements TemplateService {
|
||||
|
||||
@@ -37,10 +39,18 @@ public class TemplateServiceBean implements TemplateService {
|
||||
public String renderTemplate(String key, HashMap<String, Object> parameters) {
|
||||
try {
|
||||
return FreeMarkerTemplateUtils.processTemplateIntoString(configuration.getTemplate(key), parameters);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (TemplateException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException | TemplateException e) {
|
||||
log.warn("Failed to render template: {}", e.getMessage());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String renderTemplate(String key, Object model) {
|
||||
try {
|
||||
return FreeMarkerTemplateUtils.processTemplateIntoString(configuration.getTemplate(key), model);
|
||||
} catch (IOException | TemplateException e) {
|
||||
log.warn("Failed to render template: {}", e.getMessage());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.sheldan.abstracto.templating.seeddata;
|
||||
package dev.sheldan.abstracto.templating.seeding;
|
||||
|
||||
import dev.sheldan.abstracto.templating.TemplateService;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
Reference in New Issue
Block a user