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


Java Handlebars类代码示例

本文整理汇总了Java中com.github.jknack.handlebars.Handlebars的典型用法代码示例。如果您正苦于以下问题:Java Handlebars类的具体用法?Java Handlebars怎么用?Java Handlebars使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Handlebars类属于com.github.jknack.handlebars包,在下文中一共展示了Handlebars类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compileHandlebarsAndApply

import com.github.jknack.handlebars.Handlebars; //导入依赖的package包/类
private static Builder compileHandlebarsAndApply(final Handlebars handlebars,
                                                 final String templateName,
                                                 final Map<String, Object> model,
                                                 final Function<String, Builder> method) {
    Preconditions.checkArgument(StringUtils.hasText(templateName), "Template name not specified");

    final Context context = Context.newBuilder(model).combine(model).build();
    try {
        return method.apply(handlebars.compile(templateName).apply(context));
    } catch (IOException e) {
        throw new RuntimeException("Could not render template", e);

    } finally {
        context.destroy();
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:17,代码来源:MailMessageDTO.java

示例2: 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

示例3: writeTestsPassedReport

import com.github.jknack.handlebars.Handlebars; //导入依赖的package包/类
private void writeTestsPassedReport() throws IOException {
    Template template = new Helpers(new Handlebars()).registerHelpers().compile(TEST_OVERVIEW_REPORT);

    List<TestSuiteModel> onlyPassed = new ArrayList<>(processedTestSuites);

    for (Iterator<TestSuiteModel> it = onlyPassed.listIterator(); it.hasNext(); ) {
        TestSuiteModel f = it.next();
        if (f.getOverallStatus().equalsIgnoreCase(Constants.FAILED)) {
            it.remove();
        }
    }

    AllRSpecJUnitReports allTestSuites = new AllRSpecJUnitReports("Passed test suites report", onlyPassed);
    FileUtils.writeStringToFile(new File(TEST_OVERVIEW_PATH + "testsPassed.html"),
        template.apply(allTestSuites));
}
 
开发者ID:web-innovate,项目名称:bootstraped-multi-test-results-report,代码行数:17,代码来源:RSpecReportBuilder.java

示例4: writeTestsFailedReport

import com.github.jknack.handlebars.Handlebars; //导入依赖的package包/类
private void writeTestsFailedReport() throws IOException {
    Template template = new Helpers(new Handlebars()).registerHelpers().compile(TEST_OVERVIEW_REPORT);

    List<TestSuiteModel> onlyFailed = new ArrayList<>(processedTestSuites);

    for (Iterator<TestSuiteModel> it = onlyFailed.listIterator(); it.hasNext(); ) {
        TestSuiteModel f = it.next();
        if (f.getOverallStatus().equalsIgnoreCase(Constants.PASSED)) {
            it.remove();
        }
    }

    AllRSpecJUnitReports allTestSuites = new AllRSpecJUnitReports("Failed test suites report", onlyFailed);
    FileUtils.writeStringToFile(new File(TEST_OVERVIEW_PATH + "testsFailed.html"),
        template.apply(allTestSuites));
}
 
开发者ID:web-innovate,项目名称:bootstraped-multi-test-results-report,代码行数:17,代码来源:RSpecReportBuilder.java

示例5: apply

import com.github.jknack.handlebars.Handlebars; //导入依赖的package包/类
@Override
public CharSequence apply(final String path, final Options options)
        throws IOException {
    notEmpty(path, "found: '%s', expected 'template path'", path);
    String wrapperName = options.hash("wrapper", "anonymous");
    final JsWrapper wrapper = JsWrapper.wrapper(wrapperName);
    notNull(wrapper, "found '%s', expected: '%s'",
            wrapperName, StringUtils.join(JsWrapper.values(), ", ").toLowerCase());

    Handlebars handlebars = options.handlebars;
    String name = path;
    if (name.startsWith("/")) {
        name = name.substring(1);
    }
    if (wrapper == JsWrapper.AMD) {
        name += handlebars.getLoader().getSuffix();
    }
    Template template = handlebars.compile(path);
    String precompiled = template.toJavaScript();
    return new Handlebars.SafeString(wrapper.wrap(name, precompiled));
}
 
开发者ID:gtenham,项目名称:magnolia-templating,代码行数:22,代码来源:HandlebarsPrecompileHelper.java

示例6: applyWithCurrentTemplate

import com.github.jknack.handlebars.Handlebars; //导入依赖的package包/类
@Override
public CharSequence applyWithCurrentTemplate(final String path, final Options options) {
    notEmpty(path, "found: '%s', expected 'template path'", path);
    String wrapperName = options.hash("wrapper", "anonymous");
    final JsWrapper wrapper = JsWrapper.wrapper(wrapperName);
    notNull(wrapper, "found '%s', expected: '%s'",
            wrapperName, StringUtils.join(JsWrapper.values(), ", ").toLowerCase());

    Handlebars handlebars = options.handlebars;
    String name = StringUtils.substringBeforeLast(path,".");
    if (name.startsWith("/")) {
        name = name.substring(1);
    }
    if (wrapper == JsWrapper.AMD) {
        name += handlebars.getLoader().getSuffix();
    }
    Template template = options.fn;
    String precompiled = template.toJavaScript();
    return new Handlebars.SafeString(wrapper.wrap(name, precompiled));
}
 
开发者ID:gtenham,项目名称:magnolia-templating,代码行数:21,代码来源:HandlebarsPrecompileHelper.java

示例7: radioGroup

import com.github.jknack.handlebars.Handlebars; //导入依赖的package包/类
public CharSequence radioGroup(Object obj, String field, String values, Options options) {
	StringBuilder radios = new StringBuilder();
	String labelClass = options.hash("labelClass");

	String tmpl = "<label class=\"%s\"><input type=\"radio\" name=\"%s\" value=\"%s\"%s>%s</label>";

	for(String value : values.split(",")) {
		try {
			String checked = "";
			if(BeanUtils.getSimpleProperty(obj, field).equalsIgnoreCase(value)) {
				checked = " checked";
			}
			radios.append(String.format(tmpl, labelClass, field, value, checked, WordUtils.capitalize(value)));
		} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
			log.warn("Could not find property {} on object {}", field, obj);
		}
	}

	return new Handlebars.SafeString(radios);
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:21,代码来源:FormHelper.java

示例8: link

import com.github.jknack.handlebars.Handlebars; //导入依赖的package包/类
private CharSequence link(Image image, String type, Options options) {
	boolean modal = options.hash("lightbox", true);
	String figureClass = options.hash("figure-class");
	String imgTag = String.format("<img src=\"%s\" title=\"%s\"/>",
			imageUrl(image, type),
			image.getTitle() == null ? "" : image.getTitle());

	if(figureClass != null) {
		imgTag = String.format("<figure class=\"%s\">%s</figure>", figureClass, imgTag);
	}

	if(modal) {
		imgTag = String.format("<a href=\"%s\" title=\"%s\">%s</a>",
				imageUrl(image, "fullsize"), generateCaption(image), imgTag);
	}

	return new Handlebars.SafeString(imgTag);
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:19,代码来源:ImageHelper.java

示例9: 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

示例10: apply

import com.github.jknack.handlebars.Handlebars; //导入依赖的package包/类
protected String apply(String s, Object context) throws IOException {
       Handlebars handlebars = new Handlebars().with(EscapingStrategy.NOOP);
       StringHelper.register(handlebars);
       StringHelpers.register(handlebars);
       FilterHelper.register(handlebars);
       ConditionalHelper.register(handlebars);
       parameters = new LinkedHashMap<String, String>();
       names = new NameList() {
       	int i = 0;
   	    protected String next() {
   	    	return "p"+(i++);
   	    }       	
       };
       new ParameterHelper(parameters, names).registerHelper(handlebars);
   	return handlebars.compileInline(s).apply(
   		(context!=null && context instanceof TestUtils.MapBuilder)?
			((TestUtils.MapBuilder)context).build() : context);
}
 
开发者ID:CeeqlGroup,项目名称:ceeql,代码行数:19,代码来源:AbstractHelperTest.java

示例11: 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

示例12: apply

import com.github.jknack.handlebars.Handlebars; //导入依赖的package包/类
@Override
public CharSequence apply(String fragmentName, Options options) throws IOException {
    if ((fragmentName == null) || fragmentName.isEmpty()) {
        throw new IllegalArgumentException("Fragment name cannot be null or empty.");
    }

    Lookup lookup = options.data(HbsRenderable.DATA_KEY_LOOKUP);
    RequestLookup requestLookup = options.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
    Optional<Fragment> fragment = lookup.getFragmentIn(requestLookup.tracker().getCurrentComponentName(),
                                                       fragmentName);
    if (!fragment.isPresent()) {
        throw new IllegalArgumentException(
                "Fragment '" + fragmentName + "' does not exists in component '" +
                        requestLookup.tracker().getCurrentComponentName() + "' or in its dependencies.");
    }

    Model model = new ContextModel(options.context, options.hash);
    API api = options.data(HbsRenderable.DATA_KEY_API);
    String content = fragment.get().render(model, lookup, requestLookup, api);
    return new Handlebars.SafeString(content);
}
 
开发者ID:wso2-attic,项目名称:carbon-uuf,代码行数:22,代码来源:FragmentHelper.java

示例13: create

import com.github.jknack.handlebars.Handlebars; //导入依赖的package包/类
static Handlebars create(final List<TemplateLoader> templateLoaders, final I18nResolver i18NResolver, final I18nIdentifierFactory i18nIdentifierFactory) {
    if (templateLoaders.isEmpty()) {
        throw new SunriseConfigurationException("Could not initialize Handlebars due to missing template loaders configuration", CONFIG_TEMPLATE_LOADERS);
    }
    logger.info("Provide Handlebars: template loaders [{}]]",
            templateLoaders.stream().map(TemplateLoader::getPrefix).collect(joining(", ")));
    final TemplateLoader[] loaders = templateLoaders.toArray(new TemplateLoader[templateLoaders.size()]);
    final Handlebars handlebars = new Handlebars()
            .with(loaders)
            .with(new HighConcurrencyTemplateCache())
            .infiniteLoops(true);
    handlebars.registerHelper("i18n", new HandlebarsI18nHelper(i18NResolver, i18nIdentifierFactory));
    handlebars.registerHelper("cms", new HandlebarsCmsHelper());
    handlebars.registerHelper("json", new HandlebarsJsonHelper<>());
    return handlebars;
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:17,代码来源:HandlebarsFactory.java

示例14: 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

示例15: 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


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