use of com.github.mustachejava.DefaultMustacheFactory in project webprotege by protegeproject.
the class PasswordResetMailer_IT method setUp.
@Before
public void setUp() throws Exception {
when(placeUrl.getApplicationUrl()).thenReturn(applicationUrl);
when(appNameProvider.get()).thenReturn(theAppName);
OverridableFile overridableFile = new OverridableFile(TEMPLATE_PATH, new File("/tmp/data"));
FileContents templateFile = new FileContents(overridableFile);
TemplateEngine templateEngine = new TemplateEngine(DefaultMustacheFactory::new);
ResetPasswordMailer mailer = new ResetPasswordMailer(sendMailImpl, templateEngine, templateFile, placeUrl, appNameProvider);
mailer.sendEmail(userId, emailAddress, theNewPassword, e -> {
});
verify(sendMailImpl, times(1)).sendMail(eq(singletonList(emailAddress)), eq("Your password has been reset"), bodyCaptor.capture(), any(MessagingExceptionHandler.class));
}
use of com.github.mustachejava.DefaultMustacheFactory in project qpp-conversion-tool by CMSgov.
the class ErrorCodeDocumentationGenerator method main.
public static void main(String... args) throws IOException {
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mdTemplate = mf.compile("error-code/error-code-tempate.md");
try (FileWriter fw = new FileWriter("./ERROR_MESSAGES.md")) {
List<ErrorCode> errorCodes = Arrays.asList(ErrorCode.values());
mdTemplate.execute(fw, errorCodes).flush();
fw.flush();
}
}
use of com.github.mustachejava.DefaultMustacheFactory in project bndtools by bndtools.
the class MustacheTemplateEngine method getTemplateParameters.
@Override
public Map<String, String> getTemplateParameters(ResourceMap inputs, IProgressMonitor monitor) throws Exception {
final Map<String, String> params = new HashMap<>();
final Properties defaults = readDefaults(inputs);
TemplateSettings settings = readSettings(inputs);
DefaultMustacheFactory factory = new DefaultMustacheFactory();
AccumulateNamesObjectHandler namesAccumulator = new AccumulateNamesObjectHandler(factory.getObjectHandler());
factory.setObjectHandler(namesAccumulator);
int counter = 0;
for (Entry<String, Resource> entry : inputs.entries()) {
String inputPath = entry.getKey();
factory.compile(new StringReader(inputPath), "mapping", settings.leftDelim, settings.rightDelim).execute(new StringWriter(), Collections.emptyMap());
Resource source = entry.getValue();
if (settings.ignore == null || !settings.ignore.matches(inputPath)) {
if (source.getType() == ResourceType.File && settings.preprocessMatch.matches(inputPath)) {
InputStreamReader reader = new InputStreamReader(source.getContent(), source.getTextEncoding());
factory.compile(reader, "temp" + (counter++), settings.leftDelim, settings.rightDelim).execute(new StringWriter(), Collections.emptyMap()).toString();
}
}
}
for (String param : namesAccumulator.getNames()) {
params.put(param, defaults.getProperty(param));
}
return params;
}
use of com.github.mustachejava.DefaultMustacheFactory in project bndtools by bndtools.
the class MustacheTemplateEngine method generateOutputs.
@Override
public ResourceMap generateOutputs(ResourceMap inputs, Map<String, List<Object>> parameters, IProgressMonitor monitor) throws Exception {
TemplateSettings settings = readSettings(inputs);
Properties defaults = readDefaults(inputs);
ResourceMap outputs = new ResourceMap();
final Map<String, Object> flattenedParams = flattenParameters(parameters);
applyDefaults(defaults, flattenedParams);
DefaultMustacheFactory mustacheFactory = new DefaultMustacheFactory();
mustacheFactory.setObjectHandler(new CheckMissingObjectHandler(mustacheFactory.getObjectHandler()));
for (Entry<String, Resource> entry : inputs.entries()) {
String inputPath = entry.getKey();
Resource source = entry.getValue();
StringWriter writer = new StringWriter();
mustacheFactory.compile(new StringReader(inputPath), "mapping", settings.leftDelim, settings.rightDelim).execute(writer, flattenedParams);
String outputPath = writer.toString();
if (settings.ignore == null || !settings.ignore.matches(inputPath)) {
Resource output;
switch(source.getType()) {
case Folder:
output = source;
break;
case File:
if (settings.preprocessMatch.matches(inputPath)) {
// This file should be processed with the template engine
InputStreamReader reader = new InputStreamReader(source.getContent(), source.getTextEncoding());
StringWriter rendered = new StringWriter();
mustacheFactory.compile(reader, outputPath, settings.leftDelim, settings.rightDelim).execute(rendered, flattenedParams);
output = new StringResource(rendered.toString());
} else {
// This file should be directly copied
output = source;
}
break;
default:
throw new IllegalArgumentException("Unknown resource type " + source.getType());
}
outputs.put(outputPath, output);
}
}
return outputs;
}
use of com.github.mustachejava.DefaultMustacheFactory in project wcomponents by BorderTech.
the class TemplateRenderInterceptor method paint.
/**
* {@inheritDoc}
*/
@Override
public void paint(final RenderContext renderContext) {
UIContext uic = UIContextHolder.getCurrent();
// Generate the HTML
StringWriter outputBuffer = new StringWriter();
PrintWriter outputWriter = new PrintWriter(outputBuffer);
WebXmlRenderContext outputContext = new WebXmlRenderContext(outputWriter, uic.getLocale());
super.paint(outputContext);
String html = outputBuffer.toString();
// Only process TEMPLATE if has I18N brackets
if (html.contains("{{#i18n")) {
// Create a new instance of factory to avoid caching the page.
// https://github.com/spullara/mustache.java/issues/117
final MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile(new StringReader(html), UUID.randomUUID().toString());
StringWriter templateWriter = new StringWriter();
mustache.execute(templateWriter, new I18NContext(getResourceBundle()));
html = templateWriter.toString();
}
// Get the OUTPUT writer
WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
PrintWriter writer = webRenderContext.getWriter();
writer.print(html);
}
Aggregations