use of com.hubspot.jinjava.Jinjava in project curiostack by curioswitch.
the class UpdateIntelliJSdksTaskTest method testTemplate.
private String testTemplate(String path) {
String template = resource(path);
Jinjava jinjava = new Jinjava();
return jinjava.render(template, ImmutableMap.<String, Object>builder().put("gradleHome", testGradleHome.toAbsolutePath().toString().replace('\\', '/')).put("jdkFolder", "jdk-zulu13.28.11-ca-jdk13.0.1").put("javaVersion", "zulu13.28.11-ca-jdk13.0.1").put("goVersion", ToolDependencies.getDefaultVersion("golang")).build());
}
use of com.hubspot.jinjava.Jinjava in project kork by spinnaker.
the class JinjaArtifactExtractor method jinjaTransform.
private String jinjaTransform(String messagePayload) {
if (StringUtils.isEmpty(jinjaTemplate)) {
return messagePayload;
}
Jinjava jinja = jinjavaFactory.create();
Map<String, ?> context = readMapValue(messagePayload);
return jinja.render(jinjaTemplate, context);
}
use of com.hubspot.jinjava.Jinjava in project badge-plugin by jenkinsci.
the class ReadmeGenerator method main.
public static void main(String... args) throws IOException {
Jinjava jinjava = new Jinjava();
jinjava.getGlobalContext().registerTag(new ListImagesTag());
jinjava.getGlobalContext().registerTag(new DescribeStepTag());
Map<String, Object> context = Maps.newHashMap();
String template = Resources.toString(Resources.getResource("readme/README.tmpl"), Charsets.UTF_8);
String renderedTemplate = jinjava.render(template, context);
try (PrintWriter out = new PrintWriter("README.md")) {
out.println(renderedTemplate);
}
}
use of com.hubspot.jinjava.Jinjava in project curiostack by curioswitch.
the class UpdateIntelliJSdksTask method addJdkSnippet.
private static void addJdkSnippet(String templatePath, Map<String, Object> templateVars, ImmutableList.Builder<String> lines, boolean skipStart) throws IOException {
Jinjava jinjava = new Jinjava();
String template = Resources.toString(Resources.getResource(templatePath), StandardCharsets.UTF_8);
String rendered = jinjava.render(template, templateVars);
rendered.lines().skip(skipStart ? 2 : 0).forEach(lines::add);
}
use of com.hubspot.jinjava.Jinjava in project curiostack by curioswitch.
the class ConvertConfigsToJsonTask method exec.
@TaskAction
void exec() {
var jinJava = new Jinjava(JinjavaConfig.newBuilder().withTrimBlocks(true).build());
try {
jinJava.setResourceLocator(new FileLocator(getProject().getProjectDir()));
} catch (FileNotFoundException e) {
throw new IllegalStateException("Could not initialize Jinjava");
}
var project = getProject();
for (var file : getInputFiles()) {
Path path = file.toPath();
if (!path.toString().endsWith(".tf.yml") && !path.toString().endsWith(".tf.yaml")) {
var outDir = outputDir.resolve(project.getProjectDir().toPath().relativize(path.getParent()));
if (path.toString().contains(".jinja.")) {
var outPath = outDir.resolve(path.getFileName().toString().replace(".jinja.", "."));
try {
Files.createDirectories(outDir);
Files.writeString(outPath, jinJava.render(Files.readString(path), ImmutableMap.of()));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
} else {
// Copy non-config files (usually templates) as is.
project.copy(copy -> {
copy.from(path);
copy.into(outDir);
});
}
continue;
}
String jsonFilename = getNameWithoutExtension(path.getFileName().toString()) + ".json";
Path relativePath = getProject().getProjectDir().toPath().relativize(path);
final Path outPath;
if (relativePath.getNameCount() > 1) {
if (!relativePath.startsWith("modules")) {
outPath = outputDir.resolve(flattenFilename(relativePath, jsonFilename));
} else {
// Modules will always have a top-level directory where this should go.
outPath = outputDir.resolve(relativePath.subpath(0, 3)).resolveSibling(flattenFilename(relativePath, jsonFilename));
}
} else {
outPath = outputDir.resolve(project.getProjectDir().toPath().relativize(file.toPath())).resolveSibling(jsonFilename);
}
try {
createDirectories(outPath.getParent());
} catch (IOException e) {
throw new UncheckedIOException("Could not create output directory.", e);
}
workerExecutor.noIsolation().submit(ConvertToJson.class, parameters -> {
parameters.getProjectDirectory().set(project.getProjectDir());
parameters.getSourceFile().set(file);
parameters.getOutFile().set(outPath.toFile());
});
}
}
Aggregations