本文整理汇总了Java中com.github.jknack.handlebars.Handlebars.compileInline方法的典型用法代码示例。如果您正苦于以下问题:Java Handlebars.compileInline方法的具体用法?Java Handlebars.compileInline怎么用?Java Handlebars.compileInline使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.jknack.handlebars.Handlebars
的用法示例。
在下文中一共展示了Handlebars.compileInline方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compileWith
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
String compileWith(Handlebars handlebars) {
try {
Template compiledFragment = handlebars.compileInline(unwrappedContent);
LOGGER.trace("Applying context [{}] to fragment [{}]", fragment.context(),
StringUtils
.abbreviate(fragment.content().replaceAll("[\n\r\t]", ""),
MAX_FRAGMENT_CONTENT_LOG_LENGTH));
return compiledFragment.apply(
Context.newBuilder(fragment.context())
.push(JsonObjectValueResolver.INSTANCE)
.build());
} catch (IOException e) {
LOGGER.error("Could not process fragment [{}]", fragment.content(), e);
throw new IllegalStateException("Handlebars fragment can not be evaluated correctly.");
}
}
示例2: apply
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
Context apply(String s, Map<String, String> args, boolean isBatch, Handle dbiHandle, Map<String, String> parameters, NameList names) throws IOException {
ObjectReader mapper = new ObjectMapper().readerFor(Object.class);
HashMap<String, Object> parsedArgs = new HashMap<>();
for (Map.Entry<String, String> a : args.entrySet()) {
try {
parsedArgs.put(a.getKey(), mapper.readValue(a.getValue()));
} catch (Exception e) {
parsedArgs.put(a.getKey(), a.getValue());
}
}
Handlebars handlebars = new Handlebars().with(EscapingStrategy.NOOP);
this.parameters = parameters;
StringHelper.register(handlebars);
StringHelpers.register(handlebars);
FilterHelper.register(handlebars);
ConditionalHelper.register(handlebars);
new ParameterHelper(parameters, names).registerHelper(handlebars);
eh = new EachHelper(parameters, names, isBatch, dbiHandle).registerHelper(handlebars);
template = handlebars.compileInline(s);
sql = template.apply(parsedArgs);
return this;
}
示例3: getQuery
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
public String getQuery(String id, Map<String, Object> procedureParameters) {
Handlebars handlebars = new Handlebars();
Map<String, Object> parameters = new LinkedHashMap<String, Object>() {};
try {
String query = this.getQueries().get(id.toLowerCase());
Template template = handlebars.compileInline(query);
for (String key : procedureParameters.keySet()) {
// TODO: review the search condition
Boolean escape = (id == "search" || id == "suggestions")? true: false;
String queryCondition = createQueryCondition(procedureParameters.get(key), escape);
parameters.put(key, new Handlebars.SafeString(queryCondition));
}
LOGGER.info("getQuery; parameters: " + parameters);
query = template.apply(parameters);
LOGGER.info("getQuery; Query: " + query);
return query;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例4: ensureReleaseBranch
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
private void ensureReleaseBranch(AdvancedSCMManager amm, String targetBranch) throws AdvancedSCMException, ReleaseBranchInvalidException{
String releaseFileContent = null;
if (releaseFileContentTemplate != null && !releaseFileContentTemplate.isEmpty()
&& releaseFilePath != null && !releaseFilePath.isEmpty()) {
Handlebars handlebars = new Handlebars();
Context templateContext = Context.newContext(null);
templateContext.data("release", amm.getReleaseBranch(targetBranch).getReleaseName());
Template mustacheTemplate;
try {
mustacheTemplate = handlebars.compileInline(releaseFileContentTemplate);
releaseFileContent = mustacheTemplate.apply(templateContext);
} catch (IOException e) {
throw new AdvancedSCMException("Error rendering release file content template");
}
}
amm.ensureReleaseBranch(
targetBranch, releaseFilePath, releaseFileContent,
"[Jenkins Integration Merge] " + targetBranch + " release", commitUsername);
}
示例5: main
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
App app = App.configure(conf -> {
conf.set(Config.RENDERER_REPOSITORY, new HandleBarsRepo());
return conf;
});
// see. https://github.com/jknack/handlebars.java
Handlebars engine = new Handlebars();
Template t = engine.compileInline("Hello {{this}}!");
// use handlebars simply
app.get("/bars",
(req, res) -> res.render("john", Renderer.of(t::apply)));
// read template from templates/say/hello.html
app.get("/hello",
(req, res) -> res.render(new User("peter"), "say/hello"));
app.listen().addShutdownHook();
}
示例6: prepareStatement
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
private void prepareStatement() throws ReportException {
try {
Map<String, String> parameters = new HashMap<String, String>();
Enumeration<String> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String key = paramNames.nextElement();
parameters.put(key, StringEscapeUtils.escapeSql(request.getParameter(key)));
}
log.trace("Loading parameters from request: {}", parameters);
Handlebars handlebars = new Handlebars();
Template template = handlebars.compileInline(config.getQuery());
statement = template.apply(parameters);
log.trace("Loaded statement: {}", statement);
} catch (IOException ioe) {
throw new ReportException("Exception templating query", ioe);
}
}
示例7: saveMeshUiConfig
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
private void saveMeshUiConfig() {
File parentFolder = new File(CONFIG_FOLDERNAME);
if (!parentFolder.exists() && !parentFolder.mkdirs()) {
throw error(INTERNAL_SERVER_ERROR, "Could not create configuration folder {" + parentFolder.getAbsolutePath() + "}");
}
File outputFile = new File(parentFolder, CONF_FILE);
if (!outputFile.exists()) {
InputStream ins = getClass().getResourceAsStream("/meshui-templates/mesh-ui-config.hbs");
if (ins == null) {
throw error(INTERNAL_SERVER_ERROR, "Could not find mesh-ui config template within classpath.");
}
try {
Handlebars handlebars = new Handlebars();
Template template = handlebars.compileInline(IOUtils.toString(ins));
Map<String, Object> model = new HashMap<>();
int httpPort = Mesh.mesh().getOptions().getHttpServerOptions().getPort();
model.put("mesh_http_port", httpPort);
// Prepare render context
Context context = Context.newBuilder(model).resolver(MapValueResolver.INSTANCE).build();
FileWriter writer = new FileWriter(outputFile);
template.apply(context, writer);
writer.close();
} catch (Exception e) {
log.error("Could not save configuration file {" + outputFile.getAbsolutePath() + "}");
}
}
}
示例8: loadTemplate
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
private Template loadTemplate(Handlebars handlebars, String resourceName) {
try {
String text = IOUtils.toString(getClass().getResourceAsStream(
resourceName));
return handlebars.compileInline(text);
} catch (IOException e) {
throw new Xsd2ConverterException(e);
}
}
示例9: Xsd2CobolTypesGenerator
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
public Xsd2CobolTypesGenerator() {
try {
String text = IOUtils.toString(getClass().getResourceAsStream(
JAVA_CLASS_TEMPLATE_NAME));
Handlebars handlebars = new Handlebars();
hbtJavaClass = handlebars.compileInline(text);
modelBuilder = new Xsd2CobolTypesModelBuilder();
} catch (IOException e) {
throw new Xsd2ConverterException(e);
}
}
示例10: generateBlueprintWithParameters
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
private String generateBlueprintWithParameters(String blueprintText, Cluster cluster, Set<RDSConfig> rdsConfigs) throws IOException {
Handlebars handlebars = new Handlebars();
handlebars.with(EscapingStrategy.NOOP);
handlebars.registerHelperMissing(new Helper<Object>() {
@Override
public CharSequence apply(final Object context, final Options options) throws IOException {
return options.fn.text();
}
});
Template template = handlebars.compileInline(blueprintText, "{{{", "}}}");
return template.apply(prepareTemplateObject(cluster.getBlueprintInputs().get(Map.class), cluster, rdsConfigs));
}
示例11: renderTable
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
private String renderTable(Map<String, Object> context, String templateSource) throws IOException {
Handlebars handlebars = new Handlebars();
Template template = handlebars.compileInline(templateSource);
String output = template.apply(context);
return output;
}
示例12: StringHandlebarsBinding
import com.github.jknack.handlebars.Handlebars; //导入方法依赖的package包/类
public StringHandlebarsBinding(String template, Map<String, Binding> params) throws IOException {
Handlebars handlebars = new Handlebars();
this.template = handlebars.compileInline(template);
this.params = params;
}