當前位置: 首頁>>代碼示例>>Java>>正文


Java Handlebars.SafeString方法代碼示例

本文整理匯總了Java中com.github.jknack.handlebars.Handlebars.SafeString方法的典型用法代碼示例。如果您正苦於以下問題:Java Handlebars.SafeString方法的具體用法?Java Handlebars.SafeString怎麽用?Java Handlebars.SafeString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.github.jknack.handlebars.Handlebars的用法示例。


在下文中一共展示了Handlebars.SafeString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

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

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

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

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

示例6: execute

import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Override
public CharSequence execute(final Object valueObj)
        throws Exception {

    StringBuffer buffer = new StringBuffer();
    TemplateContentModelImpl contentModel = contentModel();
    SlingHttpServletRequest slingRequest = contentModel.request();

    WCMMode wcmMode = WCMMode.fromRequest(slingRequest);
    ClientLibraryUtil clientLibUtil = new ClientLibraryUtil(htmlLibraryManager, slingRequest);
    clientLibUtil.setOptions(true, true, false, false, false, BLANK);

    if (wcmMode != WCMMode.DISABLED) {
        ComponentContext componentContext = WCMUtils.getComponentContext(slingRequest);
        EditContext editContext = componentContext.getEditContext();
        String dlgPath = null;
        if (editContext != null && editContext.getComponent() != null) {
            dlgPath = editContext.getComponent().getDialogPath();
        }

        if (AuthoringUIMode.fromRequest(slingRequest) == AuthoringUIMode.TOUCH) {
            buffer.append(clientLibUtil.generateClientLibrariesPristine("cq.authoring.page"));
        } else
        if (AuthoringUIMode.fromRequest(slingRequest) == AuthoringUIMode.CLASSIC) {
            buffer.append(clientLibUtil.generateClientLibrariesPristine("cq.wcm.edit"));
            boolean isEditMode = (wcmMode == WCMMode.EDIT) ? true : false;
            String dialogPath = dlgPath == null ? "" : dlgPath;
            buffer.append(this.getJavaScript(slingRequest, isEditMode, dialogPath));
        }
    }

    return new Handlebars.SafeString(buffer);
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:34,代碼來源:InitScriptHelperFunction.java

示例7: execute

import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Override
public CharSequence execute(final String property)
        throws Exception {
    String defaultValue = (param("defaultValue") != null) ? (String) param("defaultValue") : BLANK;
    Object value = options().context.get(property);
    String responseString = (value != null) ? value.toString() : defaultValue;
    return new Handlebars.SafeString(responseString);
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:9,代碼來源:PropertyHelperFunction.java

示例8: execute

import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Override
public CharSequence execute(final String path)
        throws Exception {
    this.builder = new StringBuilder("");

    AreaTag area = new AreaTag();
    area.setCallerHelper(this);

    area.setPath(path);
    if(params() != null) {
        Map<String, Object> paramsMap = paramsMap();
        for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
            String param = entry.getKey();
            String value = (String) entry.getValue();

            if(param.equals("moduleType")) {
                area.setModuleType(value);

            } else if(param.equals("level")){
                area.setLevel(new Integer(value));

            } else if(param.equals("nodeTypes")){
                area.setNodeTypes(value);

            } else if(param.equals("editable")){
                area.setEditable(Boolean.valueOf(value));

            } else if(param.equals("listLimit")){
                area.setListLimit(Integer.parseInt(value));
            }
        }

    } else {
        throw new Exception ("Invalid parameters for helper: " + NAME);
    }

    area.doEndTag();

    return new Handlebars.SafeString(this.builder.toString());
}
 
開發者ID:DantaFramework,項目名稱:JahiaDF,代碼行數:41,代碼來源:TemplateAreaHelperFunction.java

示例9: execute

import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Override
public CharSequence execute(final Object obj)
        throws Exception {
    this.builder = new StringBuilder("");

    ListTag list = new ListTag();
    list.setCallerHelper(this);

    if(params() != null) {
        Map<String, Object> paramsMap = paramsMap();
        for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
            String param = entry.getKey();
            String value = (String) entry.getValue();

            if(param.equals("path")) {
                list.setPath(value);

            } else if(param.equals("nodeTypes")){
                list.setNodeTypes(value);

            } else if(param.equals("editable")){
                list.setEditable(Boolean.valueOf(value));

            }
        }

    } else {
        throw new Exception ("Invalid parameters for helper: " + NAME);
    }

    list.doEndTag();

    return new Handlebars.SafeString(this.builder.toString());
}
 
開發者ID:DantaFramework,項目名稱:JahiaDF,代碼行數:35,代碼來源:TemplateListHelperFunction.java

示例10: gaTracking

import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
public CharSequence gaTracking() {
	if(Strings.isNullOrEmpty(code)) {
		return "";
	} else {
		return new Handlebars.SafeString(
				"<script>dataLayer = [{'siteSection': 'PlantsoftheWorldOnline', 'commercial': 'No',}];</script>" +
				"<noscript><iframe src='//www.googletagmanager.com/ns.html?id=" + code + "'" +
				"height='0' width='0' style='display:none;visibility:hidden'></iframe></noscript>" +
				"<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':" +
				"new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0]," +
				"j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=" +
				"'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);" +
				"})(window,document,'script','dataLayer','" + code + "');</script>");
	}
}
 
開發者ID:RBGKew,項目名稱:powop,代碼行數:16,代碼來源:AnalyticsHelper.java

示例11: apply

import com.github.jknack.handlebars.Handlebars; //導入方法依賴的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 + "\"/>");
    }
}
 
開發者ID:wso2-attic,項目名稱:carbon-uuf,代碼行數:12,代碼來源:CSRFTokenHelper.java

示例12: apply

import com.github.jknack.handlebars.Handlebars; //導入方法依賴的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());
}
 
開發者ID:wso2-attic,項目名稱:carbon-uuf,代碼行數:30,代碼來源:DefineZoneHelper.java

示例13: preOrLink

import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
public static Helper<Object> preOrLink() {
  return new Helper<Object>() {
    @Override
    public CharSequence apply(Object o, Options options) throws IOException {
      if (o == null) {
        return "";
      }
      if (o.toString().trim().startsWith("{")) {
        return new Handlebars.SafeString("<pre><code class=\"json\">" + o.toString() + "</code></pre>");
      } else {
        return new Handlebars.SafeString(String.format("<a href=\"#%s\" >%s</a>", o.toString(), o.toString()));
      }
    }
  };
}
 
開發者ID:adrobisch,項目名稱:raml-converter,代碼行數:16,代碼來源:HandlebarsHelpers.java

示例14: execute

import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Override
public CharSequence execute(String path)
        throws Exception {
    String responseString = "";
    if (!isInvalidPath(path)) {
        TemplateContentModelImpl contentModel = contentModel();
        SlingHttpServletRequest request = contentModel.request();
        ResourceResolver resourceResolver = request.getResourceResolver();
        Resource resource = request.getResource();
        if (path != null) {
            path = interpolate(path);
            path = attachSuffixOrPrefix(path, (String) param("prefix"), (String) param("suffix"));
            if (!path.startsWith("/")) {
                path = request.getResource().getPath() + "/" + path;
            }
            path = ResourceUtil.normalize(path);
        }
        ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
        Resource tmp = request.getResourceResolver().resolve(path);
        String resourceType = interpolate((String) param("resourceType"));

        final RequestDispatcherOptions opts = new RequestDispatcherOptions();
        opts.setForceResourceType(resourceType);
        RequestDispatcher dispatcher;
        if (tmp != null) {
            if (tmp instanceof NonExistingResource) {
                if (resourceType != null) {
                    resource = new IncludeHelperSyntheticResource(request.getResourceResolver(), path, resourceType);
                    opts.remove(RequestDispatcherOptions.OPT_FORCE_RESOURCE_TYPE);
                }
            } else {
                resource = tmp;
            }
        }
        com.day.cq.wcm.api.components.Component component = componentManager.getComponentOfResource(resource);

        dispatcher = request.getRequestDispatcher(resource, opts);
        HttpServletResponse wrappedResponse = contentModel().wrappedResponse();
        dispatcher.include(request, wrappedResponse);
        responseString = wrappedResponse.toString();
    } else {
        LOG.error("{} It is not valid", path);
    }
    return new Handlebars.SafeString(responseString);
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:46,代碼來源:IncludeResourceHelperFunction.java

示例15: execute

import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Override
public CharSequence execute(final Object obj)
        throws Exception {
    this.builder = new StringBuilder("");

    ModuleTag module = new ModuleTag();
    module.setCallerHelper(this);

    if(params() != null) {
        Map<String, Object> paramsMap = paramsMap();
        for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
            String param = entry.getKey();
            String value = (String) entry.getValue();

            if(param.equals("path")) {
                module.setPath(value);

            } else if(param.equals("view")){
                module.setView(value);

            } else if(param.equals("nodeTypes")){
                module.setNodeTypes(value);

            } else if(param.equals("editable")){
                module.setEditable(Boolean.valueOf(value));

            } else if (param.equals("node")){
                JCRNodeWrapper node = null;
                Resource currentResource = (Resource) bindings.get("currentResource");

                if (!value.startsWith("/")) {
                    JCRNodeWrapper nodeWrapper = currentResource.getNode();
                    if (!value.equals("*") && nodeWrapper.hasNode(value)) {
                        node = nodeWrapper.getNode(value);
                    }
                } else if (value.startsWith("/")) {
                    JCRSessionWrapper session = currentResource.getNode().getSession();
                    try {
                        node = (JCRNodeWrapper) session.getItem(value);
                    } catch (PathNotFoundException e) { }
                }

                module.setNode(node);
            }
        }

    } else {
        throw new Exception ("Invalid parameters for helper: " + NAME);
    }

    module.doEndTag();

    return new Handlebars.SafeString(this.builder.toString());
}
 
開發者ID:DantaFramework,項目名稱:JahiaDF,代碼行數:55,代碼來源:TemplateModuleHelperFunction.java


注:本文中的com.github.jknack.handlebars.Handlebars.SafeString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。