private void setupDefaultTemplateFolder() { String destinationPath = getAsString(JBakeProperty.TEMPLATE_FOLDER); setTemplateFolder(new File(getSourceFolder(), destinationPath)); }
/** * @param db The database holding the content * @param destination The destination folder * @param templatesPath The templates folder * @param config Project configuration * @deprecated Use {@link #Renderer(ContentStore, JBakeConfiguration)} instead. * Creates a new instance of Renderer with supplied references to folders. */ @Deprecated public Renderer(ContentStore db, File destination, File templatesPath, CompositeConfiguration config) { this(db, new JBakeConfigurationFactory().createDefaultJbakeConfiguration(templatesPath.getParentFile(), config)); DefaultJBakeConfiguration configuration = ((DefaultJBakeConfiguration) this.config); configuration.setDestinationFolder(destination); configuration.setTemplateFolder(templatesPath); }
/** * @param db The database holding the content * @param destination The destination folder * @param templatesPath The templates folder * @param config Project configuration * @param renderingEngine The instance of DelegatingTemplateEngine to use * @deprecated Use {@link #Renderer(ContentStore, JBakeConfiguration, DelegatingTemplateEngine)} instead. * Creates a new instance of Renderer with supplied references to folders and the instance of DelegatingTemplateEngine to use. */ @Deprecated public Renderer(ContentStore db, File destination, File templatesPath, CompositeConfiguration config, DelegatingTemplateEngine renderingEngine) { this(db, new JBakeConfigurationFactory().createDefaultJbakeConfiguration(templatesPath.getParentFile(), config), renderingEngine); DefaultJBakeConfiguration configuration = ((DefaultJBakeConfiguration) this.config); configuration.setDestinationFolder(destination); configuration.setTemplateFolder(templatesPath); }
@Test public void bakeWithAbsolutePaths() { configuration.setTemplateFolder( new File(sourceFolder, "freemarkerTemplates") ); configuration.setContentFolder( new File(sourceFolder, "content") ); configuration.setAssetFolder( new File(sourceFolder, "assets") ); final Oven oven = new Oven(configuration); oven.bake(); assertThat(oven.getErrors()).isEmpty(); }
@Test public void shouldHandleCustomTemplateFolder() throws Exception { File source = TestUtils.getTestResourcesAsSourceFolder(); DefaultJBakeConfiguration config = (DefaultJBakeConfiguration) util.loadConfig(source); config.setTemplateFolder(TestUtils.newFolder(sourceFolder.toFile(), "my_custom_templates")); assertThat(config.getTemplateFolderName()).isEqualTo("my_custom_templates"); }
@Test public void shouldInstantiateNeededUtensils() throws Exception { configuration.setTemplateFolder( folder.newFolder("template") ); configuration.setContentFolder( folder.newFolder("content") ); configuration.setAssetFolder( folder.newFolder("assets") ); Oven oven = new Oven(configuration); assertThat(oven.getUtensils().getContentStore()).isNotNull(); assertThat(oven.getUtensils().getCrawler()).isNotNull(); assertThat(oven.getUtensils().getRenderer()).isNotNull(); assertThat(oven.getUtensils().getAsset()).isNotNull(); assertThat(oven.getUtensils().getConfiguration()).isEqualTo(configuration); }
/** * 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(); } }
@Test public void shouldCrawlRenderAndCopyAssets() throws Exception { configuration.setTemplateFolder( folder.newFolder("template") ); configuration.setContentFolder( folder.newFolder("content") ); configuration.setAssetFolder( folder.newFolder("assets") ); contentStore = spy(new ContentStore("memory", "documents"+ System.currentTimeMillis())); Crawler crawler = mock(Crawler.class); Renderer renderer = mock(Renderer.class); Asset asset = mock(Asset.class); Utensils utensils = new Utensils(); utensils.setConfiguration(configuration); utensils.setContentStore(contentStore); utensils.setRenderer(renderer); utensils.setCrawler(crawler); utensils.setAsset(asset); Oven oven = new Oven(utensils); oven.bake(); verify(contentStore, times(1)).startup(); verify(renderer,atLeastOnce()).renderIndex(anyString()); verify(crawler,times(1)).crawl(); verify(asset,times(1)).copy(); } }
@Test public void shouldHandleNonExistingFiles() throws Exception { File source = TestUtils.getTestResourcesAsSourceFolder(); File expectedTemplateFolder = new File(source, "templates"); File expectedAssetFolder = new File(source, "assets"); File expectedContentFolder = new File(source, "content"); File expectedDestinationFolder = new File(source, "output"); DefaultJBakeConfiguration config = (DefaultJBakeConfiguration) util.loadConfig(source); config.setTemplateFolder(null); config.setAssetFolder(null); config.setContentFolder(null); config.setDestinationFolder(null); File templateFolder = config.getTemplateFolder(); File assetFolder = config.getAssetFolder(); File contentFolder = config.getContentFolder(); File destinationFolder = config.getDestinationFolder(); assertThat(templateFolder).isEqualTo(expectedTemplateFolder); assertThat(assetFolder).isEqualTo(expectedAssetFolder); assertThat(contentFolder).isEqualTo(expectedContentFolder); assertThat(destinationFolder).isEqualTo(expectedDestinationFolder); }
@Before public void setUp() throws Exception { // reset values to known state otherwise previous test case runs can affect the success of this test case DocumentTypes.resetDocumentTypes(); sourceFolder = TestUtils.getTestResourcesAsSourceFolder(); configuration = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(sourceFolder); configuration.setDestinationFolder(folder.newFolder("output")); configuration.setTemplateFolder(new File(sourceFolder,"freemarkerTemplates")); }
@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 setupDefaultTemplateFolder() { String destinationPath = getAsString(JBakeProperty.TEMPLATE_FOLDER); setTemplateFolder(new File(getSourceFolder(), destinationPath)); }
/** * @param db The database holding the content * @param destination The destination folder * @param templatesPath The templates folder * @param config Project configuration * @param renderingEngine The instance of DelegatingTemplateEngine to use * @deprecated Use {@link #Renderer(ContentStore, JBakeConfiguration, DelegatingTemplateEngine)} instead. * Creates a new instance of Renderer with supplied references to folders and the instance of DelegatingTemplateEngine to use. */ @Deprecated public Renderer(ContentStore db, File destination, File templatesPath, CompositeConfiguration config, DelegatingTemplateEngine renderingEngine) { this(db, new JBakeConfigurationFactory().createDefaultJbakeConfiguration(templatesPath.getParentFile(), config), renderingEngine); DefaultJBakeConfiguration configuration = ((DefaultJBakeConfiguration) this.config); configuration.setDestinationFolder(destination); configuration.setTemplateFolder(templatesPath); }
/** * @param db The database holding the content * @param destination The destination folder * @param templatesPath The templates folder * @param config Project configuration * @deprecated Use {@link #Renderer(ContentStore, JBakeConfiguration)} instead. * Creates a new instance of Renderer with supplied references to folders. */ @Deprecated public Renderer(ContentStore db, File destination, File templatesPath, CompositeConfiguration config) { this(db, new JBakeConfigurationFactory().createDefaultJbakeConfiguration(templatesPath.getParentFile(), config)); DefaultJBakeConfiguration configuration = ((DefaultJBakeConfiguration) this.config); configuration.setDestinationFolder(destination); configuration.setTemplateFolder(templatesPath); }