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


Java Context类代码示例

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


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

示例1: render

import com.github.jknack.handlebars.Context; //导入依赖的package包/类
@Override
public void render(
    RoutingContext context, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
  try {
    Template template = cache.get(templateFileName);
    if (template == null) {
      synchronized (this) {
        loader.setVertx(context.vertx());
        template = handlebars.compile(templateFileName);
        cache.put(templateFileName, template);
      }
    }
    Context engineContext = Context.newBuilder(context.data()).resolver(getResolvers()).build();
    handler.handle(Future.succeededFuture(Buffer.buffer(template.apply(engineContext))));
  } catch (Exception ex) {
    handler.handle(Future.failedFuture(ex));
  }
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:19,代码来源:ClasspathAwareHandlebarsTemplateEngine.java

示例2: compileHandlebarsAndApply

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

示例3: compileWith

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

示例4: render

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

示例5: serialize

import com.github.jknack.handlebars.Context; //导入依赖的package包/类
@Override
public JsonElement serialize(Context context, Type type, JsonSerializationContext jsonSerializationContext) {
    JsonObject serialized = jsonSerializationContext.serialize(context.model()).getAsJsonObject();
    try {
        Field extendedContextField = ((Class) type).getDeclaredField("extendedContext");
        extendedContextField.setAccessible(true);
        Context extendedContext = (Context) extendedContextField.get(context);
        if (extendedContext != null) {
            JsonObject extendedContextJson = jsonSerializationContext.serialize(extendedContext.model())
                    .getAsJsonObject();

            Set<Map.Entry<String, JsonElement>> entries = extendedContextJson.entrySet();
            for (Map.Entry<String, JsonElement> entry : entries) {
                serialized.add(entry.getKey(), entry.getValue());
            }
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        log.error("Error while serializing the handlebars context: " + context);
    }
    return serialized;
}
 
开发者ID:wso2-attic,项目名称:carbon-uuf,代码行数:22,代码来源:DebugUtil.java

示例6: hashContext

import com.github.jknack.handlebars.Context; //导入依赖的package包/类
/**
* Iterate over a hash like object.
*
* @param context The context object.
* @param options The helper options.
* @return The string output.
* @throws IOException If something goes wrong.
*/
 private CharSequence hashContext(final Object context, final Options options)
         throws IOException {
     Set < Entry < String, Object >> propertySet = options
             .propertySet(context);
     StringBuilder buffer = new StringBuilder();
     Context parent = options.context;
     boolean first = true;
     for (Entry < String, Object > entry : propertySet) {
         Context current = Context.newBuilder(parent, entry.getValue())
                 .combine("@key", entry.getKey())
                 .combine("@first", first ? "first" : "").build();
         buffer.append(options.fn(current));
         current.destroy();
         first = false;
     }
     return buffer.toString();
 }
 
开发者ID:legsem,项目名称:legstar-core2,代码行数:26,代码来源:EachHelper.java

示例7: ensureReleaseBranch

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

示例8: onRender

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

示例9: render

import com.github.jknack.handlebars.Context; //导入依赖的package包/类
@Override
public void render(RoutingContext context, String templateDirectory, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
  try {
    String baseTemplateFileName = templateFileName;
    templateFileName = templateDirectory + templateFileName;
    Template template = isCachingEnabled() ? cache.get(templateFileName) : null;
    if (template == null) {
      synchronized (this) {
        loader.setPrefix(templateDirectory);
        loader.setVertx(context.vertx());
        // Strip leading slash from Utils##normalizePath
        template = handlebars.compile(baseTemplateFileName.substring(1));
        if (isCachingEnabled()) {
          cache.put(templateFileName, template);
        }
      }
    }
    Context engineContext = Context.newBuilder(context.data()).resolver(getResolvers()).build();
    handler.handle(Future.succeededFuture(Buffer.buffer(template.apply(engineContext))));
  } catch (Exception ex) {
    handler.handle(Future.failedFuture(ex));
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:24,代码来源:HandlebarsTemplateEngineImpl.java

示例10: request

import com.github.jknack.handlebars.Context; //导入依赖的package包/类
protected final SlingHttpServletRequest request() {
    Options options = options();
    if (options != null) {
        Context context = options.context;
        SlingHttpServletRequest result = (SlingHttpServletRequest) context.get(SLING_HTTP_REQUEST);
        return result;
    }
    return null;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:10,代码来源:AbstractAEMHelperFunction.java

示例11: toJSONObject

import com.github.jknack.handlebars.Context; //导入依赖的package包/类
public JSONObject toJSONObject() {
    synchronized (currentScopeData()) {
        JSONObject modelDataObj = wrap(currentScopeData());
        Context context = currentContext.parent();
        while (context != null) {
            modelDataObj.merge(context.model());
            context = context.parent();
        }
        return modelDataObj;
    }
}
 
开发者ID:DantaFramework,项目名称:Core,代码行数:12,代码来源:AbstractTemplateContentModelImpl.java

示例12: retractScope

import com.github.jknack.handlebars.Context; //导入依赖的package包/类
public synchronized AbstractTemplateContentModelImpl retractScope() {
    if (currentContext != rootContext) {
        Context oldContext = currentContext;
        currentContext = currentContext.parent();
        oldContext.destroy();
    }
    invalidateJSONString();
    return this;
}
 
开发者ID:DantaFramework,项目名称:Core,代码行数:10,代码来源:AbstractTemplateContentModelImpl.java

示例13: render

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

示例14: render

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

示例15: request

import com.github.jknack.handlebars.Context; //导入依赖的package包/类
protected final HttpServletRequest request() {
    Options options = options();
    if (options != null) {
        Context context = options.context;
        HttpServletRequest result = (HttpServletRequest) context.get(HTTP_REQUEST);
        return result;
    }
    return null;
}
 
开发者ID:DantaFramework,项目名称:JahiaDF,代码行数:10,代码来源:AbstractJahiaHelperFunction.java


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