-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from ancho/feature/test-documents-renderer
Add tests for DocumentsRenderer
- Loading branch information
Showing
21 changed files
with
375 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
package org.jbake.render; | ||
|
||
import java.io.File; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.configuration.CompositeConfiguration; | ||
import org.jbake.app.ContentStore; | ||
import org.jbake.app.DocumentIterator; | ||
import org.jbake.app.DocumentList; | ||
import org.jbake.app.Renderer; | ||
import org.jbake.model.DocumentTypes; | ||
import org.jbake.template.RenderingException; | ||
|
||
import java.io.File; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class DocumentsRenderer implements RenderingTool { | ||
|
||
@Override | ||
public int render(Renderer renderer, ContentStore db, File destination, File templatesPath, CompositeConfiguration config) throws RenderingException { | ||
int renderedCount = 0; | ||
final List<String> errors = new LinkedList<String>(); | ||
for (String docType : DocumentTypes.getDocumentTypes()) { | ||
DocumentIterator pagesIt = new DocumentIterator(db.getUnrenderedContent(docType).iterator()); | ||
while (pagesIt.hasNext()) { | ||
Map<String, Object> page = pagesIt.next(); | ||
try { | ||
renderer.render(page); | ||
renderedCount++; | ||
} catch (Exception e) { | ||
errors.add(e.getMessage()); | ||
} | ||
} | ||
} | ||
@Override | ||
public int render(Renderer renderer, ContentStore db, File destination, File templatesPath, CompositeConfiguration config) throws RenderingException { | ||
int renderedCount = 0; | ||
final List<String> errors = new LinkedList<String>(); | ||
for (String docType : DocumentTypes.getDocumentTypes()) { | ||
DocumentList documentList = db.getUnrenderedContent(docType); | ||
for (Map<String, Object> page : documentList) { | ||
try { | ||
renderer.render(page); | ||
renderedCount++; | ||
} catch (Exception e) { | ||
errors.add(e.getMessage()); | ||
} | ||
} | ||
} | ||
if (!errors.isEmpty()) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("Failed to render documents. Cause(s):"); | ||
for(String error: errors) { | ||
sb.append("\n" + error); | ||
} | ||
throw new RenderingException(sb.toString()); | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("Failed to render documents. Cause(s):"); | ||
for (String error : errors) { | ||
sb.append("\n" + error); | ||
} | ||
throw new RenderingException(sb.toString()); | ||
} else { | ||
return renderedCount; | ||
return renderedCount; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.