Skip to content

Commit

Permalink
Fetched and merged with upstream JBake/master
Browse files Browse the repository at this point in the history
  • Loading branch information
manikmagar committed Jun 26, 2016
2 parents 7aad1ad + 6e4a165 commit 8867064
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/jbake/parser/MarkupEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public Map<String, Object> parse(Configuration config, File file, String content
// then read engine specific headers
processHeader(context);

if (content.get(Crawler.Attributes.DATE) == null) {
content.put(Crawler.Attributes.DATE, new Date(file.lastModified()));
}

if (config.getString(Keys.DEFAULT_STATUS) != null) {
// default status has been set
if (content.get(Crawler.Attributes.STATUS) == null) {
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/org/jbake/template/ThymeleafTemplateEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ public class ThymeleafTemplateEngine extends AbstractTemplateEngine {
private TemplateEngine templateEngine;
private FileTemplateResolver templateResolver;

private String templateMode;

public ThymeleafTemplateEngine(final CompositeConfiguration config, final ContentStore db, final File destination, final File templatesPath) {
super(config, db, destination, templatesPath);
initializeTemplateEngine();
}

private void initializeTemplateEngine() {
private void initializeTemplateEngine(String mode) {
if (mode.equals(templateMode)) {
return;
}
templateMode = mode;
templateResolver = new FileTemplateResolver();
templateResolver.setPrefix(templatesPath.getAbsolutePath() + File.separatorChar);
templateResolver.setCharacterEncoding(config.getString(Keys.TEMPLATE_ENCODING));
templateResolver.setTemplateMode(mode);
templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
try {
Expand All @@ -66,7 +72,6 @@ public void renderDocument(final Map<String, Object> model, final String templat
Context context = new Context(locale, wrap(model));
lock.lock();
try {
initializeTemplateEngine();
@SuppressWarnings("unchecked")
Map<String, Object> config = (Map<String, Object>) model.get("config");
@SuppressWarnings("unchecked")
Expand All @@ -79,7 +84,7 @@ public void renderDocument(final Map<String, Object> model, final String templat
mode = configMode;
}
}
templateResolver.setTemplateMode(mode);
initializeTemplateEngine(mode);
templateEngine.process(templateName, context, writer);
} finally {
lock.unlock();
Expand Down
22 changes: 16 additions & 6 deletions src/test/java/org/jbake/app/CrawlerTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jbake.app;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
Expand All @@ -10,25 +8,29 @@
import java.util.List;
import java.util.Map;

import com.orientechnologies.orient.core.record.impl.ODocument;

import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.ConfigurationException;

import org.jbake.app.ConfigUtil.Keys;

import org.apache.commons.configuration.MapConfiguration;
import org.apache.commons.io.FilenameUtils;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.jbake.app.ConfigUtil.Keys;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.orientechnologies.orient.core.record.impl.ODocument;
import static org.assertj.core.api.Assertions.*;

public class CrawlerTest {
private CompositeConfiguration config;
private ContentStore db;
private File sourceFolder;

@Before
public void setup() throws Exception, IOException, URISyntaxException {
URL sourceUrl = this.getClass().getResource("/");
Expand All @@ -37,7 +39,7 @@ public void setup() throws Exception, IOException, URISyntaxException {
if (!sourceFolder.exists()) {
throw new Exception("Cannot find sample data structure!");
}

config = ConfigUtil.load(new File(this.getClass().getResource("/").getFile()));
Assert.assertEquals(".html", config.getString(Keys.OUTPUT_EXTENSION));
db = DBUtil.createDataStore("memory", "documents"+System.currentTimeMillis());
Expand Down Expand Up @@ -66,6 +68,14 @@ public void crawl() throws ConfigurationException {
.containsValue("../../");
}

List<ODocument> draftPosts = db.getAllContent("post");
DocumentList draftList = DocumentList.wrap(draftPosts.iterator());
for (Map<String,Object> content : list) {
if (content.get(Crawler.Attributes.TITLE).equals("Draft Post")) {
assertThat(content).containsKey(Crawler.Attributes.DATE);
}
}

// covers bug #213
List<ODocument> publishedPostsByTag = db.getPublishedPostsByTag("blog");
Assert.assertEquals(2, publishedPostsByTag.size());
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/content/blog/2016/draft-post.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
title=Draft Post
date=2016-06-22
type=post
tags=blog
status=draft
Expand Down

0 comments on commit 8867064

Please sign in to comment.