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


Java Options类代码示例

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


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

示例1: apply

import com.github.jknack.handlebars.Options; //导入依赖的package包/类
@Override
public CharSequence apply(Object context, Options options) throws IOException {
  if (context == null) {
    return "\"\"";
  }

  final StringBuilder sb = new StringBuilder();

  sb.append('"');

  for (char c : context.toString().toCharArray()) {
    if (c == '\\' || c == '\"' || c == '`') {
      sb.append('\\');
      sb.append(c);
    } else if (c == '!') {
      sb.append("\"'!'\"");
    } else {
      sb.append(c);
    }
  }

  sb.append('"');

  return sb.toString();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:26,代码来源:BashEscapedHelper.java

示例2: apply

import com.github.jknack.handlebars.Options; //导入依赖的package包/类
@Override
public CharSequence apply(Object param0, Options options)	throws IOException {				
	if(param0 instanceof Map){					
		@SuppressWarnings("unchecked")
		Map<String,Object> map = (Map<String, Object>) param0;
		StringBuilder out = new StringBuilder();
		map.forEach(new BiConsumer<String,Object>() {
			@Override
			public void accept(String key, Object value) {
				Map<String,Object> context = new HashMap<String, Object>(2);
				context.put(KEY, key);
				context.put(VALUE, value);
				try {
					String s = options.fn(context).toString();								
					out.append(s);
				} catch (Exception e) {}
				context.clear();
			}
		});
		return out.toString();
	}
	return StringPool.BLANK;
}
 
开发者ID:rfxlab,项目名称:analytics-with-rfx,代码行数:24,代码来源:HandlebarsHelpers.java

示例3: handlebars

import com.github.jknack.handlebars.Options; //导入依赖的package包/类
@Bean
public ViewResolver handlebars() {
    HandlebarsViewResolver viewResolver = new HandlebarsViewResolver();
    
    // add handlebars helper to get a label's literal without datatype
    viewResolver.registerHelper("literal", new Helper<Literal>() {
        @Override
        public Object apply(Literal literal, Options options) throws IOException {
            return literal.getLabel();
        }
    });
    
    viewResolver.setPrefix("/WEB-INF/templates/");
    viewResolver.setSuffix(".hbs");
    viewResolver.setFailOnMissingFile(false);
    
    return viewResolver;
}
 
开发者ID:DTL-FAIRData,项目名称:FAIRDataPoint,代码行数:19,代码来源:RestApiContext.java

示例4: dateHelper

import com.github.jknack.handlebars.Options; //导入依赖的package包/类
private Helper<Long> dateHelper() {
    return new Helper<Long>() {
        public CharSequence apply(Long arg0, Options arg1) throws IOException {
            PeriodFormatter formatter = new PeriodFormatterBuilder()
                .appendDays()
                .appendSuffix(" d : ")
                .appendHours()
                .appendSuffix(" h : ")
                .appendMinutes()
                .appendSuffix(" m : ")
                .appendSeconds()
                .appendSuffix(" s : ")
                .appendMillis()
                .appendSuffix(" ms")
                .toFormatter();
            return formatter.print(new Period((arg0 * 1) / 1000000));
        }
    };
}
 
开发者ID:web-innovate,项目名称:bootstraped-multi-test-results-report,代码行数:20,代码来源:Helpers.java

示例5: parseGender

import com.github.jknack.handlebars.Options; //导入依赖的package包/类
private Gender parseGender(Options options) {
    String gender = options.hash("gender");

    if ("resolve".equalsIgnoreCase(gender)) {
        String patronymic = options.hash(ATTR_PATRONYMIC, null);
        if (patronymic == null) {
            options.get(ATTR_PATRONYMIC, "");
        }
        return PETROVICH.gender(patronymic, Gender.Male);
    } else if ("MALE".equals(gender)) {
        return Gender.Male;
    } else if ("FEMALE".equals(gender)) {
        return Gender.Female;
    }
    return Gender.Both;
}
 
开发者ID:ukase,项目名称:handlebars-petrovich4j,代码行数:17,代码来源:PetrovichHelper.java

示例6: apply

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

示例7: applyWithCurrentTemplate

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

示例8: radioGroup

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

示例9: classificationLine

import com.github.jknack.handlebars.Options; //导入依赖的package包/类
private String classificationLine(List<Taxon> classification, int index, Options options) {
	if(index == classification.size()-1) {
		return String.format("<ol><li><h1 class=\"c-summary__heading\">%s</h1></li><ol>",
				taxonNameAndAuthor(classification.get(index), options));
	} else {
		if(classification.get(index).getTaxonRank() == null) {
			return String.format("<ol><li>%s%s</li></ol>",
					taxonLink(classification.get(index), options),
					classificationLine(classification, index+1, options));
		} else {
			return String.format("<ol><li>%s: %s%s</li></ol>",
					WordUtils.capitalize(classification.get(index).getTaxonRank().toString().toLowerCase()),
					taxonLink(classification.get(index), options),
					classificationLine(classification, index+1, options));
		}
	}
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:18,代码来源:NameHelper.java

示例10: link

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

示例11: 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);
}
 
开发者ID:wso2-attic,项目名称:carbon-uuf,代码行数:17,代码来源:FillPlaceholderHelper.java

示例12: apply

import com.github.jknack.handlebars.Options; //导入依赖的package包/类
public CharSequence apply(String title, Options options) throws IOException {
    if (title == null) {
        throw new IllegalArgumentException("Title cannot be null.");
    }

    Optional<String> currentTitle = getPlaceholderValue(options);
    if (currentTitle.isPresent()) {
        throw new IllegalStateException(
                "Cannot set page title. It is already set to '" + currentTitle.get() + "'.");
    } else {
        StringBuilder buffer = new StringBuilder(title);
        for (Object param : options.params) {
            buffer.append(param);
        }
        addToPlaceholder(buffer.toString(), options);
        return "";
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-uuf,代码行数:19,代码来源:TitleHelper.java

示例13: 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 "";
}
 
开发者ID:wso2-attic,项目名称:carbon-uuf,代码行数:23,代码来源:CssHelper.java

示例14: 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 "";
}
 
开发者ID:wso2-attic,项目名称:carbon-uuf,代码行数:17,代码来源:DefinePlaceholderHelper.java

示例15: 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 "";
}
 
开发者ID:wso2-attic,项目名称:carbon-uuf,代码行数:25,代码来源:FaviconHelper.java


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