• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MapValueResolver类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: render

import com.github.jknack.handlebars.context.MapValueResolver; //导入依赖的package包/类
private String render(final boolean isInline, final String source, final Object data, final String languageCode) {
	try {
		final Template template = isInline ? handlebars.compileInline(source) : handlebars.compile(source);

		final Context context = Context.newBuilder(data).combine(LANGUAGE_PROPERTY, languageCode)
				.resolver(
						ScalaJsonValueResolver.INSTANCE,
						JsonNodeValueResolver.INSTANCE, 
						MapValueResolver.INSTANCE, 
						FieldValueResolver.INSTANCE)
				.build();

		return template.apply(context);

	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:andriykuba,项目名称:play-handlebars,代码行数:19,代码来源:HandlebarsApi.java


示例2: onRender

import com.github.jknack.handlebars.context.MapValueResolver; //导入依赖的package包/类
@Override
protected void onRender(Node content, RenderableDefinition definition, RenderingContext renderingContext,
                        Map<String, Object> context, String templateScript) throws RenderException {

    final AppendableWriter out;
    try {
        out = renderingContext.getAppendable();
        AggregationState aggregationState = (AggregationState) context.get("state");
        Node node = aggregationState.getCurrentContentNode();
        Locale locale = aggregationState.getLocale();
        context.put("content", new ChainedContentMap(node, locale));
        Context combinedContext = Context.newBuilder(context)
                .resolver(JavaBeanValueResolver.INSTANCE, FieldValueResolver.INSTANCE, MapValueResolver.INSTANCE)
                .build();
        try {
            Template template = handlebars.compile(templateScript);
            template.apply(combinedContext, out);
        } finally {
            combinedContext.destroy();
        }
    } catch (IOException e) {
        LOGGER.error("Cannot render template", e);
    }
}
 
开发者ID:magnoliales,项目名称:magnolia-handlebars,代码行数:25,代码来源:HandlebarsRenderer.java


示例3: render

import com.github.jknack.handlebars.context.MapValueResolver; //导入依赖的package包/类
public Future<String> render(String template, String destination, JsonObject object) {
  Context context = Context.newBuilder(object.getMap()).resolver(MapValueResolver.INSTANCE).build();
  log.debug("Rendering template {} with object {}", object);
  Future future = Future.future();
  try {
    future.complete(writeFile(destination, handlebars.compile(template).apply(context)));
  } catch (IOException e) {
    log.error("Impossible to render template {}: ", template, e);
    future.fail(e.getCause());
  }
  return future;
}
 
开发者ID:vert-x3,项目名称:vertx-starter,代码行数:13,代码来源:TemplateService.java


示例4: render

import com.github.jknack.handlebars.context.MapValueResolver; //导入依赖的package包/类
public Future<String> render(String template, JsonObject object) {
    Context context = Context.newBuilder(object.getMap()).resolver(MapValueResolver.INSTANCE).build();
    log.debug("Rendering template {} with object {}", object);
    Future future = Future.future();
    try {
        future.complete(handlebars.compile(template).apply(context));
    } catch (IOException e) {
        log.error("Impossible to render template {}: ", template, e.getMessage());
        future.fail(e.getCause());
    }
    return future;
}
 
开发者ID:danielpetisme,项目名称:vertx-forge,代码行数:13,代码来源:TemplateService.java


示例5: saveMeshUiConfig

import com.github.jknack.handlebars.context.MapValueResolver; //导入依赖的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


示例6: newContextBuilder

import com.github.jknack.handlebars.context.MapValueResolver; //导入依赖的package包/类
/**
 * @return A Handlebars context with useful default resolvers.
 */
public static Context.Builder newContextBuilder() {
    return Context.newBuilder(null).resolver(
            FieldValueResolver.INSTANCE,
            MethodValueResolver.INSTANCE,
            JavaBeanValueResolver.INSTANCE,
            MapValueResolver.INSTANCE);
}
 
开发者ID:amzn,项目名称:swa-sample-seller,代码行数:11,代码来源:TemplateRenderer.java


示例7: getMapContext

import com.github.jknack.handlebars.context.MapValueResolver; //导入依赖的package包/类
private Context getMapContext(Map<String, Object> dataModel) {
    Context context = Context
            .newBuilder(dataModel)
            .resolver(MapValueResolver.INSTANCE)
            .build();
    return context;
}
 
开发者ID:weweave,项目名称:tubewarder,代码行数:8,代码来源:TemplateRenderer.java


示例8: Hbs

import com.github.jknack.handlebars.context.MapValueResolver; //导入依赖的package包/类
/**
 * Creates a new {@link Hbs} module.
 *
 * @param prefix Template prefix.
 * @param suffix Template suffix.
 * @param helpers Optional list of helpers.
 */
public Hbs(final String prefix, final String suffix, final Class<?>... helpers) {
  this.hbs = new Handlebars(new ClassPathTemplateLoader(prefix, suffix));
  with(helpers);
  // default value resolvers.
  this.resolvers.add(MapValueResolver.INSTANCE);
  this.resolvers.add(JavaBeanValueResolver.INSTANCE);
  this.resolvers.add(MethodValueResolver.INSTANCE);
  this.resolvers.add(new RequestValueResolver());
  this.resolvers.add(new SessionValueResolver());
  this.resolvers.add(new ConfigValueResolver());
  this.resolvers.add(FieldValueResolver.INSTANCE);
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:20,代码来源:Hbs.java


示例9: valueResolversInContext

import com.github.jknack.handlebars.context.MapValueResolver; //导入依赖的package包/类
protected List<ValueResolver> valueResolversInContext(final TemplateContext templateContext) {
    final SunriseJavaBeanValueResolver javaBeanValueResolver = createJavaBeanValueResolver(templateContext);
    return asList(MapValueResolver.INSTANCE, javaBeanValueResolver, playJavaFormResolver);
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:5,代码来源:HandlebarsContextFactory.java


示例10: generate

import com.github.jknack.handlebars.context.MapValueResolver; //导入依赖的package包/类
/**
 * Generates files from templates for a given application.
 * <p>
 * All the generated files for a given application are located
 * under <code>outputDirectory/application-name</code>. Even global templates
 * are output there.
 * </p>
 *
 * @param app an application (not null)
 * @param outputDirectory the output directory (not null)
 * @param templates a non-null collection of templates
 * @param logger a logger
 * @throws IOException if something went wrong
 */
public static void generate( Application app, File outputDirectory, Collection<TemplateEntry> templates, Logger logger )
throws IOException {

	// Create the context on the fly
	ApplicationContextBean appCtx = ContextUtils.toContext( app );
	Context wrappingCtx = Context
			.newBuilder( appCtx )
			.resolver(
				MapValueResolver.INSTANCE,
				JavaBeanValueResolver.INSTANCE,
				MethodValueResolver.INSTANCE,
				new ComponentPathResolver()
			).build();

	// Deal with the templates
	try {
		for( TemplateEntry template : templates ) {

			logger.fine( "Processing template " + template.getTemplateFile() + " to application " + app + "." );

			File target;
			String targetFilePath = template.getTargetFilePath();
			if( ! Utils.isEmptyOrWhitespaces( targetFilePath )) {
				target = new File( targetFilePath.replace( "${app}", app.getName()));

			} else {
				String filename = template.getTemplateFile().getName().replaceFirst( "\\.tpl$", "" );
				target = new File( outputDirectory, app.getName() + "/" + filename );
			}

			Utils.createDirectory( target.getParentFile());
			String output = template.getTemplate().apply( wrappingCtx );
			Utils.writeStringInto( output, target );

			logger.fine( "Template " + template.getTemplateFile() + " was processed with application " + app + ". Output is in " + target );
		}

	} finally {
		wrappingCtx.destroy();
	}
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:56,代码来源:TemplateUtils.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ConsumerStrategies类代码示例发布时间:2022-05-22
下一篇:
Java FrameworkWiring类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap