private Options getAsciiDocOptionsAndAttributes(ParserContext context) { JBakeConfiguration config = context.getConfig(); List<String> asciidoctorAttributes = config.getAsciidoctorAttributes(); final AttributesBuilder attributes = attributes(asciidoctorAttributes.toArray(new String[asciidoctorAttributes.size()])); if (config.getExportAsciidoctorAttributes()) { final String prefix = config.getAttributesExportPrefixForAsciidoctor(); for (final Iterator<String> it = config.getKeys(); it.hasNext(); ) { final String key = it.next(); if (!key.startsWith("asciidoctor")) { attributes.attribute(prefix + key.replace(".", "_"), config.get(key)); } } } final List<String> optionsSubset = config.getAsciidoctorOptionKeys(); final Options options = options().attributes(attributes.get()).get(); for (final String optionKey : optionsSubset) { Object optionValue = config.getAsciidoctorOption(optionKey); if (optionKey.equals(Options.TEMPLATE_DIRS)) { List<String> dirs = getAsList(optionValue); if (!dirs.isEmpty()) { options.setTemplateDirs(String.valueOf(dirs)); } } else { options.setOption(optionKey, optionValue); } } options.setBaseDir(context.getFile().getParentFile().getAbsolutePath()); options.setSafe(UNSAFE); return options; }
@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; } }
/** * Starts watching the file system for changes to trigger a bake. * * @param config JBakeConfiguration settings */ public void start(JBakeConfiguration config) { try { FileSystemManager fsMan = VFS.getManager(); FileObject listenPath = fsMan.resolveFile(config.getContentFolder().toURI()); FileObject templateListenPath = fsMan.resolveFile(config.getTemplateFolder().toURI()); FileObject assetPath = fsMan.resolveFile(config.getAssetFolder().toURI()); logger.info("Watching for (content, template, asset) changes in [{}]", config.getSourceFolder().getPath()); DefaultFileMonitor monitor = new DefaultFileMonitor(new CustomFSChangeListener(config)); monitor.setRecursive(true); monitor.addFile(listenPath); monitor.addFile(templateListenPath); monitor.addFile(assetPath); monitor.start(); } catch (FileSystemException e) { logger.error("Problems watching filesystem changes", e); } } }
/** * 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); }
private String assetSubPath(File asset) throws IOException { // First, strip asset folder from file path String targetFolder = asset.getCanonicalPath().replace(config.getAssetFolder().getCanonicalPath() + File.separatorChar, ""); // And just to be sure, let's also remove the content folder, as some assets are copied from here. targetFolder = targetFolder.replace(config.getContentFolder().getCanonicalPath() + File.separatorChar, ""); return targetFolder; }
private void ensureContentFolder() { File path = configuration.getContentFolder(); checkRequiredFolderExists(configuration.getContentFolderName(), path); }
@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 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); }
@Override public void renderDocument(final Map<String, Object> model, String templateName, final Writer writer) throws RenderingException { model.put("version", config.getVersion()); Iterator<String> configKeys = config.getKeys(); while (configKeys.hasNext()) { String key = configKeys.next(); valueObject = config.getPaginateIndex(); valueObject = config.get(key); File templateFolder = config.getTemplateFolder(); File templateFile = new File(templateFolder, templateName); if (!templateFile.exists()) {
@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; } }
for (File content : contents) { if (content.isDirectory()) { if (content.getName().equalsIgnoreCase(config.getTemplateFolderName())) { safe = false; if (content.getName().equalsIgnoreCase(config.getContentFolderName())) { safe = false; if (content.getName().equalsIgnoreCase(config.getAssetFolderName())) { safe = false; outputFolder.getAbsolutePath())); if (config.getExampleProjectByType(templateType) != null) { File templateFile = new File(templateLocationFolder, config.getExampleProjectByType(templateType)); if (!templateFile.exists()) { throw new Exception("Cannot find example project file: " + templateFile.getPath());
updateDocTypesFromConfiguration(); contentStore.updateSchema(); contentStore.updateAndClearCacheIfNeeded(config.getClearCache(), config.getTemplateFolder()); asset.copyAssetsFromContent(config.getContentFolder());
protected void run(LaunchOptions res, JBakeConfiguration config) { System.out.println("JBake " + config.getVersion() + " (" + config.getBuildTimeStamp() + ") [http://jbake.org]"); System.out.println(); runServer(res.getDestination(), config.getServerPort()); } else if (!res.getSource().getPath().equals(".")) { runServer(res.getSource(), config.getServerPort()); } else { runServer(config.getDestinationFolder(), config.getServerPort()); runServer(config.getDestinationFolder(), config.getServerPort());
@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; } }
public ModelRenderingConfig(String fileName, Map<String, Object> model, String templateType) { super(new File(config.getDestinationFolder(), fileName), fileName, findTemplateName(templateType)); this.model = model; }
String outputFilename = config.getDestinationFolder().getPath() + File.separatorChar + content.get(Attributes.URI); if (outputFilename.lastIndexOf('.') > outputFilename.lastIndexOf(File.separatorChar)) { outputFilename = outputFilename.substring(0, outputFilename.lastIndexOf('.')); String outputExtension = config.getOutputExtensionByDocType(docType); File draftFile = new File(outputFilename, config.getDraftSuffix() + outputExtension); if (draftFile.exists()) { draftFile.delete(); outputFilename = outputFilename + config.getDraftSuffix();
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)); if (config.getRenderTagsIndex()) { try { 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(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()); }
static public String getUriPathToContentRoot(JBakeConfiguration config, File sourceFile) { return getPathToRoot(config, config.getContentFolder(), sourceFile); }
private void checkAssetFolder() { File path = configuration.getAssetFolder(); if (!path.exists()) { LOGGER.warn("No asset folder '{}' was found!", path.getAbsolutePath()); } }