Skip to content

Commit

Permalink
Fix bugs revealed by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraZizka committed Oct 31, 2018
1 parent c7a3b5d commit b95f8d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
17 changes: 16 additions & 1 deletion jbake-core/src/main/java/org/jbake/app/DebugUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
package org.jbake.app;

import java.io.PrintStream;
import java.sql.SQLOutput;
import java.util.Map;
import org.apache.commons.lang.StringUtils;

public class DebugUtil
{
public static <T extends Object> void printMap(Map<String, T> map, PrintStream printStream){
public static <T extends Object> void printMap(String label, Map<String, T> map, PrintStream printStream){
if (null == map) {
printStream.println("The Map is null.");
return;
}

if (null == printStream) {
printStream = System.out;
return;
}
if (!StringUtils.isBlank(label)) {
printStream.println(label + ":");
}

printStream.println();
for (Map.Entry<String, T> entry: map.entrySet()) {
printStream.println(entry.getKey() + " :: " + entry.getValue());
Expand Down
10 changes: 4 additions & 6 deletions jbake-core/src/main/java/org/jbake/app/Oven.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,11 @@ public void bake() {
// render content
renderContent();

{
// copy assets
asset.copy();
asset.copyAssetsFromContent(config.getContentFolder());
// copy assets
asset.copy();
asset.copyAssetsFromContent(config.getContentFolder());

errors.addAll(asset.getErrors());
}
errors.addAll(asset.getErrors());

LOGGER.info("Baking finished!");
long end = new Date().getTime();
Expand Down
14 changes: 11 additions & 3 deletions jbake-core/src/main/java/org/jbake/parser/MarkupEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ public Map<String, Object> parse(JBakeConfiguration config, File file) {
hasHeader);

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

applyHeadersToDocument(headersMap, context.getDocumentModel());
if (headersMap != null)
applyHeadersToDocument(headersMap, context.getDocumentModel());

setModelDefaultsIfNotSetInHeader(context);
sanitizeTags(context);
Expand Down Expand Up @@ -212,7 +213,14 @@ private boolean hasHeader(List<String> fileLines)


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

0 comments on commit b95f8d0

Please sign in to comment.