Skip to content

Commit

Permalink
Update freemarker renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
opoo committed Aug 5, 2015
1 parent bf9b65b commit f651fd1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ public boolean isRenderRequired(Site site, Page page, String content) {

@Override
public String render(Page base, Object rootMap) {
if (StringUtils.isBlank(base.getContent())) {
log.warn("Empty converted content, skip render: {}", base.getUrl());
return "";
}
return render(base, (Map<String, Object>) rootMap);
}

Expand Down
22 changes: 14 additions & 8 deletions core/src/main/java/org/opoo/press/renderer/FreeMarkerRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ public FreeMarkerRenderer(Site site) {
initializeTemplateModels();


renderMethod = (String) site.get(PROPERTY_PREFIX + "render_method");
renderMethod = site.get(PROPERTY_PREFIX + "render_method");

Boolean useMacroLayout = (Boolean) site.get(PROPERTY_PREFIX + "macro_layout");
Boolean useMacroLayout = site.get(PROPERTY_PREFIX + "macro_layout");
workingTemplateHolder = (useMacroLayout == null || useMacroLayout.booleanValue()) ?
new MacroWorkingTemplateHolder() : new NonMacroWorkingTemplateHolder();
}

private void initializeTemplateModels() {
templateModels = site.getFactory().getPluginManager().getObjectMap(TemplateModel.class);
Map<String, String> map = (Map<String, String>) site.get(TemplateModel.class.getName());
Map<String, String> map = site.get(TemplateModel.class.getName());
if (map != null) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String name = entry.getKey();
Expand All @@ -114,7 +114,7 @@ private void initializeTemplateModels() {
}

private void initializeAutoImportTemplates(Site site, Configuration configuration) {
Map<String, String> autoImportTemplates = (Map<String, String>) site.get(PROPERTY_PREFIX + "auto_import_templates");
Map<String, String> autoImportTemplates = site.get(PROPERTY_PREFIX + "auto_import_templates");
if (autoImportTemplates != null && !autoImportTemplates.isEmpty()) {
for (Map.Entry<String, String> en : autoImportTemplates.entrySet()) {
configuration.addAutoImport(en.getKey(), en.getValue());
Expand All @@ -124,7 +124,7 @@ private void initializeAutoImportTemplates(Site site, Configuration configuratio
}

private void initializeAutoIncludeTemplates(Site site, Configuration configuration) {
List<String> autoIncludeTemplates = (List<String>) site.get(PROPERTY_PREFIX + "auto_include_templates");
List<String> autoIncludeTemplates = site.get(PROPERTY_PREFIX + "auto_include_templates");
if (autoIncludeTemplates != null && !autoIncludeTemplates.isEmpty()) {
for (String template : autoIncludeTemplates) {
configuration.addAutoInclude(template);
Expand Down Expand Up @@ -172,6 +172,11 @@ public void prepare() {

@Override
public String render(Page base, Map<String, Object> rootMap) {
if(!(base.getSource().getOrigin() instanceof FileOrigin)){
log.debug("Origin is not FileOrigin, using recursive render method.");
return renderRecursive(base, rootMap);
}
else
//render methods: merge|recursive, default is merge
if (renderMethod == null || "merge".equalsIgnoreCase(renderMethod)) {
return renderMergedTemplate(base, rootMap);
Expand Down Expand Up @@ -242,7 +247,7 @@ public boolean isRenderRequired(Page base, String content) {
return isRenderRequired(site, base, content);
}

static interface WorkingTemplateHolder {
interface WorkingTemplateHolder {
String getMergedWorkingTemplate(String layout, String content, Source source);

String getLayoutWorkingTemplate(String layout);
Expand All @@ -251,9 +256,10 @@ static interface WorkingTemplateHolder {
abstract class AbstractWorkingTemplateHolder implements WorkingTemplateHolder {
@Override
public String getMergedWorkingTemplate(String layout, String content, Source source) {
Origin origin = source.getOrigin();
//must be FileOrigin
FileOrigin origin = (FileOrigin) source.getOrigin();
String workingTemplateName = origin.getPath() + "/" + origin.getName() + "." + layout + ".ftl";
File sourceFile = origin instanceof FileOrigin ? ((FileOrigin) origin).getFile() : null;
File sourceFile = origin.getFile();
prepareWorkingTemplate(workingTemplateName, sourceFile, layout, content);
return workingTemplateName;
}
Expand Down

0 comments on commit f651fd1

Please sign in to comment.