private void setupDefaultContentFolder() { setContentFolder(new File(getSourceFolder(), getContentFolderName())); }
@Override public String getOutputExtensionByDocType(String docType) { String templateExtensionKey = DOCTYPE_TEMPLATE_PREFIX + docType + DOCTYPE_EXTENSION_POSTFIX; String defaultOutputExtension = getOutputExtension(); return getAsString(templateExtensionKey, defaultOutputExtension); }
@Override public File getTemplateFileByDocType(String docType) { String templateKey = DOCTYPE_TEMPLATE_PREFIX + docType + DOCTYPE_FILE_POSTFIX; String templateFileName = getAsString(templateKey); if (templateFileName != null) { return new File(getTemplateFolder(), templateFileName); } logger.warn("Cannot find configuration key '{}' for document type '{}'", templateKey, docType); return null; }
public DefaultJBakeConfiguration(File sourceFolder, CompositeConfiguration configuration) { this.compositeConfiguration = configuration; setSourceFolder(sourceFolder); setupDefaultDestination(); setupPathsRelativeToSourceFile(); }
public void setSourceFolder(File sourceFolder) { setProperty(SOURCE_FOLDER_KEY, sourceFolder); setupPathsRelativeToSourceFile(); }
@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); }
public void setTemplateExtensionForDocType(String docType, String extension) { String templateExtensionKey = DOCTYPE_TEMPLATE_PREFIX + docType + DOCTYPE_EXTENSION_POSTFIX; setProperty(templateExtensionKey, extension); }
@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(); }
@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(); }
/** * @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); }
/** * Creates a {@link DefaultJBakeConfiguration} with value site.host replaced * by http://localhost:[server.port]. * The server.port is read from the project properties file. * * @param sourceFolder The source folder of the project * @param destinationFolder The destination folder to render and copy files to * @param isClearCache Whether to clear database cache or not * @return A configuration by given parameters * @throws ConfigurationException if loading the configuration fails */ public DefaultJBakeConfiguration createJettyJbakeConfiguration(File sourceFolder, File destinationFolder, boolean isClearCache) throws ConfigurationException { DefaultJBakeConfiguration configuration = (DefaultJBakeConfiguration) getConfigUtil().loadConfig(sourceFolder); configuration.setDestinationFolder(destinationFolder); configuration.setClearCache(isClearCache); configuration.setSiteHost("http://localhost:"+configuration.getServerPort()); return configuration; }
/** * Primary intention is to extend test cases to increase coverage. * * @throws Exception */ @Test public void testWriteProtected() throws Exception { File assets = new File(config.getSourceFolder(), "assets"); File css = new File(folder.toFile(),"css"); css.mkdir(); final File cssFile = new File(css, "bootstrap.min.css"); FileUtils.touch(cssFile); cssFile.setReadOnly(); config.setAssetFolder(assets); config.setDestinationFolder(folder.toFile()); Asset asset = new Asset(config); asset.copy(); cssFile.setWritable(true); Assertions.assertFalse(asset.getErrors().isEmpty(), "At least one error during copy expected"); }
private void setupDefaultAssetFolder() { String assetFolder = getAsString(JBakeProperty.ASSET_FOLDER); setAssetFolder(new File(getSourceFolder(), assetFolder)); }
private void setupDefaultTemplateFolder() { String destinationPath = getAsString(JBakeProperty.TEMPLATE_FOLDER); setTemplateFolder(new File(getSourceFolder(), destinationPath)); }
private void setupDefaultDestination() { String destinationPath = getAsString(JBakeProperty.DESTINATION_FOLDER); setDestinationFolder(new File(getSourceFolder(), destinationPath)); }
@BeforeClass public static void setUpClass() throws Exception { sourceFolder = TestUtils.getTestResourcesAsSourceFolder(); Assert.assertTrue("Cannot find sample data structure!", sourceFolder.exists()); config = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(sourceFolder); config.setSourceFolder(sourceFolder); Assert.assertEquals(".html", config.getOutputExtension()); config.setDatabaseStore(storageType.toString()); String dbPath = folder.newFolder("documents" + System.currentTimeMillis()).getAbsolutePath(); config.setDatabasePath(dbPath); db = DBUtil.createDataStore(config); }
/** * Creates a {@link DefaultJBakeConfiguration} * * This is a compatibility factory method * * @param sourceFolder The source folder of the project * @param destination The destination folder to render and copy files to * @param compositeConfiguration A given {@link CompositeConfiguration} * @param isClearCache Whether to clear database cache or not * @return A configuration by given parameters */ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFolder, File destination, CompositeConfiguration compositeConfiguration, boolean isClearCache) { DefaultJBakeConfiguration configuration = new DefaultJBakeConfiguration(sourceFolder, compositeConfiguration); configuration.setDestinationFolder(destination); configuration.setClearCache(isClearCache); return configuration; }
/** * Primary intention is to extend test cases to increase coverage. * * @throws Exception */ @Test public void testUnlistable() throws Exception { config.setAssetFolder(new File(config.getSourceFolder(), "non-exsitent")); Asset asset = new Asset(config); asset.copy(); }
@Test public void shouldHandleCustomContentFolder() throws Exception { File source = TestUtils.getTestResourcesAsSourceFolder(); DefaultJBakeConfiguration config = (DefaultJBakeConfiguration) util.loadConfig(source); config.setContentFolder(TestUtils.newFolder(sourceFolder.toFile(), "my_custom_content")); assertThat(config.getContentFolderName()).isEqualTo("my_custom_content"); }
@BeforeEach public void setup(@TempDir Path folder) throws Exception { fixtureDir = new File(this.getClass().getResource("/fixture").getFile()); this.folder = folder; config = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(fixtureDir); config.setDestinationFolder(folder.toFile()); Assertions.assertEquals(".html", config.getOutputExtension()); }