本文整理汇总了Java中com.github.jknack.handlebars.Options.data方法的典型用法代码示例。如果您正苦于以下问题:Java Options.data方法的具体用法?Java Options.data怎么用?Java Options.data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.jknack.handlebars.Options
的用法示例。
在下文中一共展示了Options.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isResourceAlreadyResolved
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
protected static boolean isResourceAlreadyResolved(String resourceRelativePath, Options handlebarsOptions) {
RequestLookup requestLookup = handlebarsOptions.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
RequestLookup.RenderingFlowTracker tracker = requestLookup.tracker();
Set<String> resolvedResources = handlebarsOptions.data(HbsRenderable.DATA_KEY_RESOLVED_RESOURCES);
// unique resource identifier is computed as fragment/component name+relativePath
String resourceIdentifierPrefix = tracker.isInFragment() ? tracker.getCurrentFragment().get().getName()
: tracker.getCurrentComponentName();
String resourceIdentifier = resourceIdentifierPrefix + resourceRelativePath;
if (resolvedResources == null) {
resolvedResources = new HashSet<>();
handlebarsOptions.data(HbsRenderable.DATA_KEY_RESOLVED_RESOURCES, resolvedResources);
}
return !resolvedResources.add(resourceIdentifier);
}
示例2: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public CharSequence apply(String relativePath, Options options) throws IOException {
if (relativePath == null) {
throw new IllegalArgumentException("Relative path of a CSS file cannot be null.");
}
String completeRelativePath = concatParams(relativePath, options.params);
if (isResourceAlreadyResolved(completeRelativePath, options)) {
return ""; // This resource is already added.
}
RequestLookup requestLookup = options.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
StringBuilder buffer = new StringBuilder("<link href=\"")
.append(requestLookup.getPublicUri())
.append('/')
.append(completeRelativePath);
buffer.append("\" rel=\"stylesheet\" type=\"text/css\" />\n");
addToPlaceholder(buffer.toString(), options);
return "";
}
示例3: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
public CharSequence apply(String placeholderName, Options options) throws IOException {
if ((placeholderName == null) || placeholderName.isEmpty()) {
throw new IllegalArgumentException("Placeholder name cannot be null or empty.");
}
PlaceholderWriter writer = options.data(HbsRenderable.DATA_KEY_CURRENT_WRITER);
if (options.tagType.inline()) {
// {{placeholder "name"}}
writer.addPlaceholder(placeholderName);
} else {
// {{#placeholder "name"}} default content of this placeholder {{/placeholder}}
writer.addPlaceholder(placeholderName, options.fn().toString());
}
return "";
}
示例4: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
public CharSequence apply(String relativePath, Options options) throws IOException {
if (relativePath == null) {
throw new IllegalArgumentException("Relative path of a favicon image cannot be null.");
}
RequestLookup requestLookup = options.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
StringBuilder buffer = new StringBuilder("<link rel=\"shortcut icon\" href=\"")
.append(requestLookup.getPublicUri())
.append('/')
.append(relativePath);
for (Object param : options.params) {
buffer.append(param);
}
String type = options.hash("type");
if (type != null) {
buffer.append("\" type=\"").append(type);
}
buffer.append("\" />\n");
addToPlaceholder(buffer.toString(), options);
return "";
}
示例5: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的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);
}
示例6: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public CharSequence apply(Object context, Options options) throws IOException {
if (!options.tagType.inline()) {
return "";
}
Permission permission = getPermission(context, options);
options.data(HbsPreprocessor.DATA_KEY_SECURED, permission);
return "";
}
示例7: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
public CharSequence apply(String layoutName, Options options) throws IOException {
if ((layoutName == null) || layoutName.isEmpty()) {
throw new HbsRenderingException("Layout name cannot be null or empty.");
}
Object currentLayout = options.data(HbsPreprocessor.DATA_KEY_CURRENT_LAYOUT);
if (currentLayout != null) {
throw new HbsRenderingException("Cannot set layout '" + layoutName + "' to this page because layout '" +
currentLayout + "' is already set.");
}
options.data(HbsPreprocessor.DATA_KEY_CURRENT_LAYOUT, layoutName);
return "";
}
示例8: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public CharSequence apply(Object context, Options options) throws IOException {
if (options.tagType.inline()) {
return "";
}
API api = options.data(HbsRenderable.DATA_KEY_API);
Permission permission = getPermission(context, options);
return api.hasPermission(permission) ? options.fn() : options.inverse();
}
示例9: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
public CharSequence apply(Object context, Options options) throws IOException {
RequestLookup requestLookup = options.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
String cookieValue = requestLookup.getRequest().getCookieValue(COOKIE_CSRFTOKEN);
if (cookieValue == null) {
return "";
} else {
return new Handlebars.SafeString("<input type=\"hidden\" name=\"" + COOKIE_CSRFTOKEN + "\" value=\""
+ cookieValue + "\"/>");
}
}
示例10: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
public CharSequence apply(String relativePath, Options options) throws IOException {
if (relativePath == null) {
throw new IllegalArgumentException("Relative path of a JS file cannot be null.");
}
String completeRelativePath = concatParams(relativePath, options.params);
if (isResourceAlreadyResolved(completeRelativePath, options)) {
return ""; // This resource is already added.
}
RequestLookup requestLookup = options.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
StringBuilder buffer = new StringBuilder("<script src=\"")
.append(requestLookup.getPublicUri())
.append('/')
.append(completeRelativePath);
buffer.append("\"");
// See http://www.w3schools.com/tags/att_script_async.asp
Object async = options.hash.get("async");
if ((async != null) && ((Boolean) async)) {
buffer.append(" async");
}
// See http://www.w3schools.com/tags/att_script_defer.asp
Object defer = options.hash.get("defer");
if ((defer != null) && ((Boolean) defer)) {
buffer.append(" defer");
}
buffer.append(" type=\"text/javascript\"></script>\n");
addToPlaceholder(buffer.toString(), options);
return "";
}
示例11: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
public CharSequence apply(String zoneName, Options options) throws IOException {
RequestLookup requestLookup = options.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
if (!requestLookup.tracker().isInPage()) {
// helper is called inside a fragment or a layout
throw new HbsRenderingException("'#" + HELPER_NAME + "' helper is only allowed inside pages.");
}
if ((zoneName == null) || zoneName.isEmpty()) {
throw new IllegalArgumentException("Zone name cannot be null or empty.");
}
requestLookup.putToZone(zoneName, options.fn().toString());
return "";
}
示例12: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
public CharSequence apply(String templateName, Options options) throws IOException {
String scriptText;
if (TagType.VAR.equals(options.tagType)) { // fragment template name is provided
if (options.params.length < 1) {
throw new HbsRenderingException("Fragment name is not given in the template helper.");
}
String fragmentName = options.param(0).toString();
Lookup lookup = options.data(HbsRenderable.DATA_KEY_LOOKUP);
RequestLookup requestLookup = options.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
String componentName = requestLookup.tracker().getCurrentComponentName();
Fragment fragment = lookup.getFragmentIn(componentName, fragmentName)
.orElseThrow(() -> new HbsRenderingException("Fragment '" + fragmentName + "' does not exist in " +
"component '" + componentName + "' or its dependencies."));
if (!(fragment.getRenderable() instanceof HbsRenderable)) {
throw new HbsRenderingException(
"The template of the fragment '" + fragmentName + "' is not a handlebars " + "template.");
}
scriptText = "\n" + ((HbsRenderable) fragment.getRenderable()).getTemplate().text() + "\n";
} else { // fragment is defined inline
scriptText = options.fn.text();
}
String script = "<script id=\"" + templateName + "\" type=\"text/x-handlebars-template\">" + scriptText +
"</script>";
addToPlaceholder(script, options);
return "";
}
示例13: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
public CharSequence apply(String relativeUri, Options options) throws IOException {
if (relativeUri == null) {
throw new IllegalArgumentException("Relative URI of a hyperlink cannot be null.");
}
RequestLookup requestLookup = options.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
StringBuilder buffer = new StringBuilder(requestLookup.getPublicUri()).append('/').append(relativeUri);
for (Object param : options.params) {
buffer.append(param);
}
return buffer.toString();
}
示例14: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
public CharSequence apply(String key, Options options) throws IOException {
if (key == null) {
throw new IllegalArgumentException("Key of a translating string cannot be null.");
}
Locale locale;
Lookup lookup = options.data(HbsRenderable.DATA_KEY_LOOKUP);
// First priority is given to the passed locale parameter. {{i18n "key" locale="en-US"}}
locale = computeLocale(options.hash);
if (locale == null) {
// Check whether we have already computed the locale for this request.
Locale currentRequestLocale = options.data(DATA_KEY_CURRENT_REQUEST_LOCALE);
if (currentRequestLocale == null) {
// Second priority is given to the accept language header of the request.
RequestLookup requestLookup = options.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
locale = computeLocale(requestLookup.getRequest(), lookup.getI18nResources());
if (locale == null) {
// Seems like we have failed to compute a locale in above approaches.
// Let's check whether a default locale is configured in the configuration.
locale = computeLocale(lookup.getConfiguration());
if (locale == null) {
// Since there is no other option, we choose fallback locale.
locale = FALLBACK_LOCALE;
}
}
options.data(DATA_KEY_CURRENT_REQUEST_LOCALE, locale);
} else {
locale = currentRequestLocale;
}
}
return lookup.getI18nResources().getMessage(locale, key, options.params, key);
}
示例15: apply
import com.github.jknack.handlebars.Options; //导入方法依赖的package包/类
@Override
public CharSequence apply(String zoneName, Options options) throws IOException {
if ((zoneName == null) || zoneName.isEmpty()) {
throw new IllegalArgumentException("Zone name cannot be null or empty.");
}
Lookup lookup = options.data(HbsRenderable.DATA_KEY_LOOKUP);
RequestLookup requestLookup = options.data(HbsRenderable.DATA_KEY_REQUEST_LOOKUP);
StringBuilder buffer = new StringBuilder();
buffer.append("<!--[UUF-ZONE]{\"name\": \"").append(zoneName).append("\",\"position\": \"start\"}-->\n");
List<Fragment> bindings = lookup.getBindings(requestLookup.tracker().getCurrentComponentName(), zoneName);
Optional<String> zoneContent = requestLookup.getZoneContent(zoneName);
if (bindings.isEmpty() && !zoneContent.isPresent() && options.tagType == TagType.SECTION) {
// {{#defineZone "zone-name"}}default content{{/defineZone}}
buffer.append(options.fn().toString());
} else {
if (!bindings.isEmpty()) {
API api = options.data(HbsRenderable.DATA_KEY_API);
for (Fragment fragment : bindings) {
buffer.append(fragment.render(new ContextModel(options.context), lookup, requestLookup, api));
}
}
zoneContent.ifPresent(buffer::append);
}
buffer.append("<!--[UUF-ZONE]{\"name\": \"").append(zoneName).append("\",\"position\": \"end\"}-->\n");
return new Handlebars.SafeString(buffer.toString());
}