Skip to content

Commit b95f8d0

Browse files
committed
Fix bugs revealed by tests
1 parent c7a3b5d commit b95f8d0

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

jbake-core/src/main/java/org/jbake/app/DebugUtil.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
package org.jbake.app;
22

33
import java.io.PrintStream;
4+
import java.sql.SQLOutput;
45
import java.util.Map;
6+
import org.apache.commons.lang.StringUtils;
57

68
public class DebugUtil
79
{
8-
public static <T extends Object> void printMap(Map<String, T> map, PrintStream printStream){
10+
public static <T extends Object> void printMap(String label, Map<String, T> map, PrintStream printStream){
11+
if (null == map) {
12+
printStream.println("The Map is null.");
13+
return;
14+
}
15+
16+
if (null == printStream) {
17+
printStream = System.out;
18+
return;
19+
}
20+
if (!StringUtils.isBlank(label)) {
21+
printStream.println(label + ":");
22+
}
23+
924
printStream.println();
1025
for (Map.Entry<String, T> entry: map.entrySet()) {
1126
printStream.println(entry.getKey() + " :: " + entry.getValue());

jbake-core/src/main/java/org/jbake/app/Oven.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,11 @@ public void bake() {
140140
// render content
141141
renderContent();
142142

143-
{
144-
// copy assets
145-
asset.copy();
146-
asset.copyAssetsFromContent(config.getContentFolder());
143+
// copy assets
144+
asset.copy();
145+
asset.copyAssetsFromContent(config.getContentFolder());
147146

148-
errors.addAll(asset.getErrors());
149-
}
147+
errors.addAll(asset.getErrors());
150148

151149
LOGGER.info("Baking finished!");
152150
long end = new Date().getTime();

jbake-core/src/main/java/org/jbake/parser/MarkupEngine.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ public Map<String, Object> parse(JBakeConfiguration config, File file) {
124124
hasHeader);
125125

126126
Map<String, String> headersMap = parseHeaderBlock(context);
127-
DebugUtil.printMap(headersMap, System.out);
127+
DebugUtil.printMap("Headers of " + file, headersMap, System.out);
128128

129-
applyHeadersToDocument(headersMap, context.getDocumentModel());
129+
if (headersMap != null)
130+
applyHeadersToDocument(headersMap, context.getDocumentModel());
130131

131132
setModelDefaultsIfNotSetInHeader(context);
132133
sanitizeTags(context);
@@ -212,7 +213,14 @@ private boolean hasHeader(List<String> fileLines)
212213

213214

214215
/**
215-
* Process the header of the file.
216+
* Parse the headers of the file being parsed in given context.
217+
*
218+
* This method should parse the headers and return them for further processing.
219+
* Otherwise the implementation may opt to apply the headers to the document itself and return null.
220+
*
221+
* TODO: The processing should be flatter in general, IMHO.
222+
* Rather than nesting X levels deep to process a document, config overlays, an index, etc.,
223+
* the code blocks should pass packages of information around. Otherwise making JBake pluggable would be harder.
216224
*
217225
* @param context the parser context
218226
*/

0 commit comments

Comments
 (0)