public ModelRenderingConfig(String fileName, Map<String, Object> model, String templateType) { super(new File(config.getDestinationFolder(), fileName), fileName, findTemplateName(templateType)); this.model = model; }
public DefaultRenderingConfig(String filename, String allInOneName) { super(new File(config.getDestinationFolder(), File.separator + filename), allInOneName, findTemplateName(allInOneName)); this.content = buildSimpleModel(allInOneName); }
private void ensureDestination() { File destination = configuration.getDestinationFolder(); if (!destination.exists()) { destination.mkdirs(); } if (!destination.canWrite()) { throw new JBakeException("Error: Destination folder is not writable: " + destination.getAbsolutePath()); } }
/** * Constructor added due to known use of a allInOneName which is used for name, template and content * * @param allInOneName */ public DefaultRenderingConfig(String allInOneName) { this(new File(config.getDestinationFolder().getPath() + File.separator + allInOneName + config.getOutputExtension()), allInOneName); }
/** * Copy all files from supplied path. * * @param path The starting path */ public void copy(File path) { FileFilter filter = new FileFilter() { @Override public boolean accept(File file) { return (!config.getAssetIgnoreHidden() || !file.isHidden()) && (file.isFile() || FileUtil.directoryOnlyIfNotIgnored(file)); } }; copy(path, config.getDestinationFolder(), filter); }
static public String getUriPathToDestinationRoot(JBakeConfiguration config, File sourceFile) { return getPathToRoot(config, config.getDestinationFolder(), sourceFile); }
/** * Copy one asset file at a time. * * @param asset The asset file to copy */ public void copySingleFile(File asset) { try { if ( !asset.isDirectory() ) { String targetPath = config.getDestinationFolder().getCanonicalPath() + File.separatorChar + assetSubPath(asset); LOGGER.info("Copying single asset file to [{}]", targetPath); copyFile(asset, new File(targetPath)); } else { LOGGER.info("Skip copying single asset file [{}]. Is a directory.", asset.getPath()); } } catch (IOException io) { LOGGER.error("Failed to copy the asset file.", io); } }
/** * Responsible for copying any asset files that exist within the content directory. * * @param path of the content directory */ public void copyAssetsFromContent(File path) { copy(path, config.getDestinationFolder(), FileUtil.getNotContentFileFilter()); }
String outputFilename = config.getDestinationFolder().getPath() + File.separatorChar + content.get(Attributes.URI); if (outputFilename.lastIndexOf('.') > outputFilename.lastIndexOf(File.separatorChar)) { outputFilename = outputFilename.substring(0, outputFilename.lastIndexOf('.'));
model.put("content", map); File path = new File(config.getDestinationFolder() + File.separator + tagPath + File.separator + tag + config.getOutputExtension()); map.put(Attributes.ROOTPATH, FileUtil.getUriPathToDestinationRoot(config, path)); model.put("content", map); File path = new File(config.getDestinationFolder() + File.separator + tagPath + File.separator + "index" + config.getOutputExtension()); map.put(Attributes.ROOTPATH, FileUtil.getUriPathToDestinationRoot(config, path)); render(new ModelRenderingConfig(path, "tagindex", model, findTemplateName("tagsindex")));
@Test public void shouldReturnDestinationFolderFromConfiguration() throws Exception { File sourceFolder = TestUtils.getTestResourcesAsSourceFolder(); File expectedDestinationFolder = new File(sourceFolder, "output"); JBakeConfiguration config = util.loadConfig(sourceFolder); assertThat(config.getDestinationFolder()).isEqualTo(expectedDestinationFolder); }
@Test public void shouldCreateDestinationFolderIfNotExists() throws Exception { String contentFolderName = "content"; String templateFolderName = "template"; String destinationFolderName = "output"; File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName); File contentFolder = TestUtils.newFolder(folder.toFile(), contentFolderName); File destinationFolder = new File(folder.toFile(), destinationFolderName); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(folder.toFile()); when(configuration.getTemplateFolder()).thenReturn(templateFolder); when(configuration.getTemplateFolderName()).thenReturn(templateFolderName); when(configuration.getContentFolder()).thenReturn(contentFolder); when(configuration.getContentFolderName()).thenReturn(contentFolderName); when(configuration.getDestinationFolder()).thenReturn(destinationFolder); when(configuration.getAssetFolder()).thenReturn(destinationFolder); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); inspector.inspect(); assertThat(destinationFolder).exists(); }
@Test public void shouldThrowExceptionIfDestinationFolderNotWritable() throws Exception { String contentFolderName = "content"; String templateFolderName = "template"; File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName); File contentFolder = TestUtils.newFolder(folder.toFile(), contentFolderName); File destinationFolder = mock(File.class); when(destinationFolder.exists()).thenReturn(true); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(folder.toFile()); when(configuration.getTemplateFolder()).thenReturn(templateFolder); when(configuration.getTemplateFolderName()).thenReturn(templateFolderName); when(configuration.getContentFolder()).thenReturn(contentFolder); when(configuration.getContentFolderName()).thenReturn(contentFolderName); when(configuration.getDestinationFolder()).thenReturn(destinationFolder); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); try { inspector.inspect(); fail("should throw JBakeException"); } catch (JBakeException e) { assertThat(e.getMessage()).contains("Error: Destination folder is not writable:"); } }
@Test public void shouldLogWarningIfAssetFolderDoesNotExist() throws Exception { String contentFolderName = "content"; String templateFolderName = "template"; String destinationFolderName = "output"; String assetFolderName = "assets"; File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName); File contentFolder = TestUtils.newFolder(folder.toFile(), contentFolderName); File destinationFolder = TestUtils.newFolder(folder.toFile(), destinationFolderName); File assetFolder = new File(folder.toFile(), assetFolderName); JBakeConfiguration configuration = mock(JBakeConfiguration.class); when(configuration.getSourceFolder()).thenReturn(folder.toFile()); when(configuration.getTemplateFolder()).thenReturn(templateFolder); when(configuration.getTemplateFolderName()).thenReturn(templateFolderName); when(configuration.getContentFolder()).thenReturn(contentFolder); when(configuration.getContentFolderName()).thenReturn(contentFolderName); when(configuration.getDestinationFolder()).thenReturn(destinationFolder); when(configuration.getAssetFolder()).thenReturn(assetFolder); JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration); inspector.inspect(); verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture()); LoggingEvent loggingEvent = captorLoggingEvent.getValue(); assertThat(loggingEvent.getMessage()).isEqualTo("No asset folder '{}' was found!"); assertThat(loggingEvent.getFormattedMessage()).isEqualTo("No asset folder '" + assetFolder.getAbsolutePath() + "' was found!"); }
@Test public void shouldReturnDefaultConfigurationWithDefaultFolders() throws Exception { File sourceFolder = folder.getRoot(); File destinationFolder = folder.newFolder("output"); File templateFolder = new File(folder.getRoot(), "templates"); File assetFolder = new File(folder.getRoot(), "assets"); JBakeConfiguration configuration = new JBakeConfigurationFactory().createDefaultJbakeConfiguration(sourceFolder, destinationFolder, true); assertThat(configuration.getSourceFolder()).isEqualTo(sourceFolder); assertThat(configuration.getDestinationFolder()).isEqualTo(destinationFolder); assertThat(configuration.getTemplateFolder()).isEqualTo(templateFolder); assertThat(configuration.getAssetFolder()).isEqualTo(assetFolder); assertThat(configuration.getClearCache()).isEqualTo(true); }
} else { runServer(config.getDestinationFolder(), config.getServerPort()); runServer(config.getDestinationFolder(), config.getServerPort());
public DefaultRenderingConfig(String filename, String allInOneName) { super(new File(config.getDestinationFolder(), File.separator + filename), allInOneName, findTemplateName(allInOneName)); this.content = buildSimpleModel(allInOneName); }
private void ensureDestination() { File destination = configuration.getDestinationFolder(); if (!destination.exists()) { destination.mkdirs(); } if (!destination.canWrite()) { throw new JBakeException("Error: Destination folder is not writable: " + destination.getAbsolutePath()); } }
/** * Constructor added due to known use of a allInOneName which is used for name, template and content * * @param allInOneName */ public DefaultRenderingConfig(String allInOneName) { this(new File(config.getDestinationFolder().getPath() + File.separator + allInOneName + config.getOutputExtension()), allInOneName); }
/** * Responsible for copying any asset files that exist within the content directory. * * @param path of the content directory */ public void copyAssetsFromContent(File path) { copy(path, config.getDestinationFolder(), FileUtil.getNotContentFileFilter()); }