@Override public View getView(String viewName, final ResourceLoader resourceLoader) throws Exception { String filename = filename(viewName); byte[] bytes = resourceLoader.load(filename); if (bytes == null) return null; Mustache.TemplateLoader loader = loader(resourceLoader); String template = new String(bytes); Mustache.Compiler compiler = getViewFactory(resourceLoader); Template mustache = compiler.withLoader(loader).compile(template); return view(mustache); }
@Override public File convert(SupportingFile support) { try { File destinationFolder = new File(new File(targetDir.getAbsolutePath()), support.folder); File outputFile = new File(destinationFolder, support.destinationFilename); String template = generator.readTemplate(new File(TEMPLATE_DIR_CLASSPATH, support.templateFile).getPath()); String formatted = template; if (support.templateFile.endsWith(MUSTACHE_EXTENSION)) { LOGGER.info("writing file to {}", outputFile.getAbsolutePath()); formatted = Mustache.compiler().withLoader(loader(generator)).defaultValue("") .compile(template).execute(data); } else { LOGGER.info("copying file to {}", outputFile.getAbsolutePath()); } FileUtils.writeStringToFile(outputFile, formatted); return outputFile; } catch (IOException e) { throw new RuntimeException("Can't generate project", e); } } };
resourceAsStream = HttpUtils.class.getClassLoader().getResourceAsStream(template); Mustache.compiler() .withLoader(partial -> { final String partialClasspathName; if (partial.startsWith("/")) {
compiler = config.processCompiler(compiler); Template tmpl = compiler .withLoader(new Mustache.TemplateLoader() { @Override public Reader getTemplate(String name) {
URL optionalClassnameTemplate = getClass().getResource(templateResource); Mustache.Compiler compiler = Mustache.compiler().withLoader((name) -> { if (optionalClassnameTemplate != null) { return new InputStreamReader(getClass().getResourceAsStream(templateResource), StandardCharsets.UTF_8);
resourceAsStream = HttpUtils.class.getClassLoader().getResourceAsStream(template); Mustache.compiler() .withLoader(partial -> { final String partialClasspathName; if (partial.startsWith("/")) {
public TemplateHolder(JSONObject configuration) { JSONObject search = configuration.optJSONObject("search"); String searchString = search.getString("template"); Template searchTemplate = Mustache.compiler().escapeHTML(false).standardsMode(true).withLoader(s -> getReader(searchString)).compile(getReader(searchString)); Template searchUrlTemplate = createTemplate(search.optString("url", "")); if (bulk != null) { Template bulkUrlTemplate = createTemplate(bulk.optString("url")); Template bulkTemplate = Mustache.compiler().escapeHTML(false).standardsMode(true).withLoader(s -> getReader(add.optString("template"))).compile(getReader(bulk.optString("template"))); this.bulk = new TemplateRequest(bulk.optString("method", "POST"), bulkUrlTemplate, bulkTemplate);
protected File processTemplateToFile(Map<String, Object> templateData, String templateName, String outputFilename) throws IOException { String adjustedOutputFilename = outputFilename.replaceAll("//", "/").replace('/', File.separatorChar); if (ignoreProcessor.allowsFile(new File(adjustedOutputFilename))) { String templateFile = getFullTemplateFile(config, templateName); String template = readTemplate(templateFile); Mustache.Compiler compiler = Mustache.compiler(); compiler = config.processCompiler(compiler); Template tmpl = compiler .withLoader(new Mustache.TemplateLoader() { @Override public Reader getTemplate(String name) { return getTemplateReader(getFullTemplateFile(config, name + ".mustache")); } }) .defaultValue("") .compile(template); writeToFile(adjustedOutputFilename, tmpl.execute(templateData)); return new File(adjustedOutputFilename); } LOGGER.info("Skipped generation of " + adjustedOutputFilename + " due to rule in .openapi-generator-ignore"); return null; }
@Bean public Mustache.Compiler mustacheCompiler(TemplateLoader loader) { return compiler().escapeHTML(false).withLoader(loader); }
public void afterPropertiesSet() throws Exception { templateLoader.setPrefix(prefix); templateLoader.setSuffix(suffix); if (compiler == null) { compiler = Mustache.compiler() .escapeHTML(escapeHTML) .standardsMode(standardsMode) .withLoader(templateLoader); } }
public void afterPropertiesSet() throws Exception { templateLoader.setPrefix(prefix); templateLoader.setSuffix(suffix); if (compiler == null) { compiler = Mustache.compiler() .escapeHTML(escapeHTML) .standardsMode(standardsMode) .withLoader(templateLoader); } }
@Bean public ViewResolver mustacheViewResolver() { String prefix = "classpath:/templates/"; String suffix = ".mustache"; Mustache.TemplateLoader loader = new MustacheResourceTemplateLoader(prefix, suffix); MustacheViewResolver mustacheViewResolver = new MustacheViewResolver(Mustache.compiler().withLoader(loader)); mustacheViewResolver.setPrefix(prefix); mustacheViewResolver.setSuffix(suffix); return mustacheViewResolver; }
private static Compiler mustacheCompiler() { return Mustache.compiler().withLoader(mustacheTemplateLoader()); }
@Override protected Mustache.Compiler createViewFactory(ResourceLoader templateLoader) { return Mustache.compiler().withLoader(loader(templateLoader)); }