/** * 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 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); } }
@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(); }
/** * Create default {@link Utensils} by a given {@link JBakeConfiguration} * @param config a {@link JBakeConfiguration} * @return a default {@link Utensils} instance */ public static Utensils createDefaultUtensils(JBakeConfiguration config) { JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(config); inspector.inspect(); Utensils utensils = new Utensils(); utensils.setConfiguration(config); ContentStore contentStore = DBUtil.createDataStore(config); utensils.setContentStore(contentStore); utensils.setCrawler(new Crawler(contentStore, config)); utensils.setRenderer(new Renderer(contentStore, config)); utensils.setAsset(new Asset(config)); return utensils; } }
/** * Create default {@link Utensils} by a given {@link JBakeConfiguration} * @param config a {@link JBakeConfiguration} * @return a default {@link Utensils} instance */ public static Utensils createDefaultUtensils(JBakeConfiguration config) { JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(config); inspector.inspect(); Utensils utensils = new Utensils(); utensils.setConfiguration(config); ContentStore contentStore = DBUtil.createDataStore(config); utensils.setContentStore(contentStore); utensils.setCrawler(new Crawler(contentStore, config)); utensils.setRenderer(new Renderer(contentStore, config)); utensils.setAsset(new Asset(config)); return utensils; } }