当前位置: 首页>>代码示例>>Java>>正文


Java Handlebars.compileInline方法代码示例

本文整理汇总了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.");
  }
}
 
开发者ID:Cognifide,项目名称:knotx,代码行数:17,代码来源:HandlebarsFragment.java

示例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;     		
}
 
开发者ID:CeeqlGroup,项目名称:ceeql,代码行数:27,代码来源:CeeqlTemplate.java

示例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;
    }
}
 
开发者ID:FAOSTAT,项目名称:faostat-api,代码行数:22,代码来源:QUERIES.java

示例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);
}
 
开发者ID:jenkinsci,项目名称:gatekeeper-plugin,代码行数:20,代码来源:GatekeeperMerge.java

示例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();
}
 
开发者ID:taichi,项目名称:siden,代码行数:21,代码来源:UseHandlebars.java

示例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);
  }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:22,代码来源:QueryReportExecutor.java

示例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() + "}");
		}
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:30,代码来源:AdminGUIEndpoint.java

示例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);
    }
}
 
开发者ID:legsem,项目名称:legstar-core2,代码行数:10,代码来源:Xsd2JaxbGenerator.java

示例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);
    }
}
 
开发者ID:legsem,项目名称:legstar-core2,代码行数:12,代码来源:Xsd2CobolTypesGenerator.java

示例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));
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:14,代码来源:BlueprintTemplateProcessor.java

示例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;
}
 
开发者ID:gentics,项目名称:mesh,代码行数:7,代码来源:TableGenerator.java

示例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;
}
 
开发者ID:fpoulin,项目名称:json-shapeshifter,代码行数:7,代码来源:StringHandlebarsBinding.java


注:本文中的com.github.jknack.handlebars.Handlebars.compileInline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。