renderIndex(indexFile); } else { PagingHelper pagingHelper = new PagingHelper(totalPosts, postsPerPage); model.put("nextFileName", nextFileName); Map<String, Object> contentModel = buildSimpleModel(MASTERINDEX_TEMPLATE_NAME); render(renderConfig);
@Override public int render(Renderer renderer, ContentStore db, JBakeConfiguration config) throws RenderingException { if (config.getRenderArchive()) { try { renderer.renderArchive(config.getArchiveFileName()); return 1; } catch (Exception e) { throw new RenderingException(e); } } else { return 0; } }
@Override public int render(Renderer renderer, ContentStore db, JBakeConfiguration config) throws RenderingException { if (config.getRenderFeed()) { try { //TODO: refactor this. the renderer has a reference to the configuration renderer.renderFeed(config.getFeedFileName()); return 1; } catch (Exception e) { throw new RenderingException(e); } } else { return 0; } }
try (Writer out = createWriter(outputFile)) { renderingEngine.renderDocument(model, findTemplateName(docType), out);
@Override public int render(Renderer renderer, ContentStore db, JBakeConfiguration config) throws RenderingException { if (config.getRenderIndex()) { try { String fileName = config.getIndexFileName(); //TODO: refactor this. the renderer has a reference to the configuration if (config.getPaginateIndex()) { renderer.renderIndexPaging(fileName); } else { renderer.renderIndex(fileName); } return 1; } catch (Exception e) { throw new RenderingException(e); } } else { return 0; } }
model.put("renderer", renderingEngine); model.put(Attributes.TAG, tag); Map<String, Object> map = buildSimpleModel(Attributes.TAG); model.put("content", map); map.put(Attributes.ROOTPATH, FileUtil.getUriPathToDestinationRoot(config, path)); render(new ModelRenderingConfig(path, Attributes.TAG, model, findTemplateName(Attributes.TAG))); Map<String, Object> map = buildSimpleModel(Attributes.TAGS); model.put("content", map); render(new ModelRenderingConfig(path, "tagindex", model, findTemplateName("tagsindex"))); renderedCount++; } catch (Exception e) {
/** * Render an XML feed file using the supplied content. * * @param feedFile The name of the output file * @throws Exception if default rendering configuration is not loaded correctly */ public void renderFeed(String feedFile) throws Exception { render(new DefaultRenderingConfig(feedFile, FEED_TEMPLATE_NAME)); }
@Override public int render(Renderer renderer, ContentStore db, JBakeConfiguration config) throws RenderingException { if (config.getRenderTags()) { try { //TODO: refactor this. the renderer has a reference to the configuration return renderer.renderTags(config.getTagPathName()); } catch (Exception e) { throw new RenderingException(e); } } else { return 0; } }
/** * See issue #300 * * @throws Exception */ @Test public void testRenderFileWorksWhenPathHasDotInButFileDoesNot() throws Exception { Assume.assumeFalse("Ignore running on Windows", TestUtils.isWindows()); String FOLDER = "real.path"; final String FILENAME = "about"; config.setOutputExtension(""); config.setTemplateFolder(folder.newFolder("templates")); Renderer renderer = new Renderer(db, config, renderingEngine); Map<String, Object> content = new HashMap<>(); content.put(Crawler.Attributes.TYPE, "page"); content.put(Crawler.Attributes.URI, "/" + FOLDER + "/" + FILENAME); content.put(Crawler.Attributes.STATUS, "published"); renderer.render(content); File outputFile = new File(outputPath.getAbsolutePath() + File.separatorChar + FOLDER + File.separatorChar + FILENAME); assertThat(outputFile).isFile(); } }
@Override public int render(Renderer renderer, ContentStore db, JBakeConfiguration config) throws RenderingException { if (config.getRenderSiteMap()) { try { //TODO: refactor this. the renderer has a reference to the configuration renderer.renderSitemap(config.getSiteMapFileName()); return 1; } catch (Exception e) { throw new RenderingException(e); } } else { return 0; } }
@Test(expected = RenderingException.class) public void propagatesRenderingException() throws Exception { IndexRenderer renderer = new IndexRenderer(); JBakeConfiguration configuration = mock(DefaultJBakeConfiguration.class); when(configuration.getRenderIndex()).thenReturn(true); when(configuration.getIndexFileName()).thenReturn("mockindex.html"); ContentStore contentStore = mock(ContentStore.class); Renderer mockRenderer = mock(Renderer.class); doThrow(new Exception()).when(mockRenderer).renderIndex(anyString()); renderer.render(mockRenderer, contentStore, configuration); verify(mockRenderer, never()).renderIndex(anyString()); }
@Test public void shouldRenderPaginatedIndex() throws Exception { IndexRenderer renderer = new IndexRenderer(); JBakeConfiguration configuration = mock(DefaultJBakeConfiguration.class); when(configuration.getRenderIndex()).thenReturn(true); when(configuration.getPaginateIndex()).thenReturn(true); when(configuration.getIndexFileName()).thenReturn("mockindex.html"); ContentStore contentStore = mock(ContentStore.class); Renderer mockRenderer = mock(Renderer.class); renderer.render(mockRenderer, contentStore, configuration); verify(mockRenderer, times(1)).renderIndexPaging(anyString()); } }
@Before public void setup() throws Exception { currentLocale = Locale.getDefault(); Locale.setDefault(Locale.ENGLISH); ModelExtractorsDocumentTypeListener listener = new ModelExtractorsDocumentTypeListener(); DocumentTypes.addListener(listener); templateFolder = new File(sourceFolder, templateDir); if (!templateFolder.exists()) { throw new Exception("Cannot find template folder!"); } destinationFolder = folder.getRoot(); config.setDestinationFolder(destinationFolder); config.setTemplateFolder(templateFolder); for (String docType : DocumentTypes.getDocumentTypes()) { File templateFile = config.getTemplateFileByDocType(docType); if (templateFile != null) { String fileName = templateFile.getName(); String fileBaseName = fileName.substring(0, fileName.lastIndexOf(".")); config.setTemplateFileNameForDocType(docType, fileBaseName + "." + templateExtension); } } Assert.assertEquals(".html", config.getOutputExtension()); Crawler crawler = new Crawler(db, config); crawler.crawl(); parser = new Parser(config); renderer = new Renderer(db, config); setupExpectedOutputStrings(); }
private void render(RenderingConfig renderConfig) throws Exception { File outputFile = renderConfig.getPath(); try { try (Writer out = createWriter(outputFile)) { renderingEngine.renderDocument(renderConfig.getModel(), renderConfig.getTemplate(), out); } LOGGER.info("Rendering {} [{}]... done!", renderConfig.getName(), outputFile); } catch (Exception e) { LOGGER.error("Rendering {} [{}]... failed!", renderConfig.getName(), outputFile, e); throw new Exception("Failed to render " + renderConfig.getName(), e); } }
/** * Render an index file using the supplied content. * * @param indexFile The name of the output file * @throws Exception if IOException or SecurityException are raised */ public void renderIndex(String indexFile) throws Exception { render(new DefaultRenderingConfig(indexFile, MASTERINDEX_TEMPLATE_NAME)); }
model.put("renderer", renderingEngine); model.put(Attributes.TAG, tag); Map<String, Object> map = buildSimpleModel(Attributes.TAG); model.put("content", map); map.put(Attributes.ROOTPATH, FileUtil.getUriPathToDestinationRoot(config, path)); render(new ModelRenderingConfig(path, Attributes.TAG, model, findTemplateName(Attributes.TAG))); Map<String, Object> map = buildSimpleModel(Attributes.TAGS); model.put("content", map); render(new ModelRenderingConfig(path, "tagindex", model, findTemplateName("tagsindex"))); renderedCount++; } catch (Exception e) {
@Test(expected = RenderingException.class) public void propogatesRenderingException() throws Exception { TagsRenderer renderer = new TagsRenderer(); JBakeConfiguration configuration = mock(DefaultJBakeConfiguration.class); when(configuration.getRenderTags()).thenReturn(true); when(configuration.getTagPathName()).thenReturn("mocktagpath/tag"); ContentStore contentStore = mock(ContentStore.class); Renderer mockRenderer = mock(Renderer.class); doThrow(new Exception()).when(mockRenderer).renderTags(anyString()); renderer.render(mockRenderer, contentStore, configuration); verify(mockRenderer, never()).renderTags(anyString()); } }
@Override public int render(Renderer renderer, ContentStore db, JBakeConfiguration config) throws RenderingException { if (config.getRenderIndex()) { try { String fileName = config.getIndexFileName(); //TODO: refactor this. the renderer has a reference to the configuration if (config.getPaginateIndex()) { renderer.renderIndexPaging(fileName); } else { renderer.renderIndex(fileName); } return 1; } catch (Exception e) { throw new RenderingException(e); } } else { return 0; } }
@Test public void renderCustomTypePaper() throws Exception { // setup config.setTemplateFileNameForDocType("paper", "paper." + templateExtension); DocumentTypes.addDocumentType("paper"); db.updateSchema(); Crawler crawler = new Crawler(db, config); crawler.crawl(); Parser parser = new Parser(config); Renderer renderer = new Renderer(db, config); String filename = "published-paper.html"; File sampleFile = new File(sourceFolder.getPath() + File.separator + "content" + File.separator + "papers" + File.separator + filename); Map<String, Object> content = parser.processFile(sampleFile); content.put(Crawler.Attributes.URI, "/" + filename); renderer.render(content); File outputFile = new File(destinationFolder, filename); Assert.assertTrue(outputFile.exists()); // verify String output = FileUtils.readFileToString(outputFile, Charset.defaultCharset()); for (String string : getOutputStrings("paper")) { assertThat(output).contains(string); } }
@Test(expected = RenderingException.class) public void propogatesRenderingException() throws Exception { SitemapRenderer renderer = new SitemapRenderer(); JBakeConfiguration configuration = mock(DefaultJBakeConfiguration.class); when(configuration.getRenderSiteMap()).thenReturn(true); when(configuration.getSiteMapFileName()).thenReturn("mocksitemap.html"); ContentStore contentStore = mock(ContentStore.class); Renderer mockRenderer = mock(Renderer.class); doThrow(new Exception()).when(mockRenderer).renderSitemap(anyString()); renderer.render(mockRenderer, contentStore, configuration); verify(mockRenderer, never()).renderSitemap(anyString()); }