package com.xcong.farmer.cms.core.template;
|
|
import com.xcong.farmer.cms.core.node.PartNode;
|
import com.xcong.farmer.cms.core.node.Template;
|
import org.jsoup.nodes.Document;
|
|
import java.io.File;
|
import java.io.FileOutputStream;
|
import java.io.IOException;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author wzy
|
* @date 2022-07-01
|
**/
|
public class TemplateConfiguration extends Configuration{
|
|
private TemplateLoader templateLoader;
|
|
public TemplateConfiguration(String templatePath, String staticPath, String outputPath) {
|
super(templatePath, staticPath, outputPath);
|
}
|
|
public void templateLoader(TemplateLoader templateLoader) {
|
this.templateLoader = templateLoader;
|
}
|
|
public void process(Map<String, Object> map, String templateName) {
|
if (this.templateLoader == null) {
|
throw new RuntimeException("TemplateLoader do not able to be null");
|
}
|
|
this.templateLoader.data(map);
|
Template template = template(templateName);
|
template.output(this.outputPath);
|
|
// 判断是否有分页,有则执行。从第二页开始
|
int i = 2;
|
while(Template.HAS_PAGING) {
|
map.put("page", i);
|
this.templateLoader.data(map);
|
Template pageTemplate = template(templateName);
|
pageTemplate.output(this.outputPath);
|
i++;
|
}
|
}
|
|
public Template template(String templateName) {
|
return template(new File(path(this.templatePath) + templateName));
|
}
|
|
public Template template(File file) {
|
if (file == null) {
|
throw new RuntimeException("template not exist");
|
}
|
|
return this.templateLoader.template(file);
|
}
|
|
private String path(String path) {
|
if (!path.endsWith("/")) {
|
path = path + "/";
|
}
|
return path;
|
}
|
}
|