本文整理匯總了Java中com.github.jknack.handlebars.Handlebars.compile方法的典型用法代碼示例。如果您正苦於以下問題:Java Handlebars.compile方法的具體用法?Java Handlebars.compile怎麽用?Java Handlebars.compile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.jknack.handlebars.Handlebars
的用法示例。
在下文中一共展示了Handlebars.compile方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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));
}
示例2: getFooter
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Override
public String getFooter() {
StringBuilder result = new StringBuilder();
I18n i18n = getI18n(this.getClass().getClassLoader(), "org.sakaiproject.pasystem.impl.i18n.pasystem");
Handlebars handlebars = loadHandleBars(i18n);
Session session = SessionManager.getCurrentSession();
Map<String, Object> context = new HashMap<String, Object>();
try {
Template template = handlebars.compile("templates/shared_footer");
context.put("portalCDNQuery", PortalUtils.getCDNQuery());
context.put("sakai_csrf_token", session.getAttribute("sakai.csrf.token"));
result.append(template.apply(context));
} catch (IOException e) {
log.warn("IOException while getting footer", e);
return "";
}
result.append(getBannersFooter(handlebars, context));
result.append(getPopupsFooter(handlebars, context));
result.append(getTimezoneCheckFooter(handlebars, context));
return result.toString();
}
示例3: getBannersFooter
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
private String getBannersFooter(Handlebars handlebars, Map<String, Object> context) {
try {
Template template = handlebars.compile("templates/banner_footer");
context.put("bannerJSON", getActiveBannersJSON());
return template.apply(context);
} catch (IOException e) {
log.warn("IOException while getting banners footer", e);
return "";
}
}
示例4: getPopupsFooter
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
private String getPopupsFooter(Handlebars handlebars, Map<String, Object> context) {
Session session = SessionManager.getCurrentSession();
User currentUser = UserDirectoryService.getCurrentUser();
if (currentUser == null || currentUser.getId() == null || "".equals(currentUser.getId())) {
return "";
}
try {
if (session.getAttribute(POPUP_SCREEN_SHOWN) == null) {
Popup popup = new PopupForUser(currentUser).getPopup();
if (popup.isActiveNow()) {
context.put("popupTemplate", popup.getTemplate());
context.put("popupUuid", popup.getUuid());
context.put("popup", true);
if (currentUser.getId() != null) {
// Delivered!
session.setAttribute(POPUP_SCREEN_SHOWN, "true");
}
}
}
Template template = handlebars.compile("templates/popup_footer");
return template.apply(context);
} catch (IOException | MissingUuidException e) {
log.warn("IOException while getting popups footer", e);
return "";
}
}
示例5: getTimezoneCheckFooter
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
private String getTimezoneCheckFooter(Handlebars handlebars, Map<String, Object> context) {
if (ServerConfigurationService.getBoolean("pasystem.timezone-check", true)) {
try {
Template template = handlebars.compile("templates/timezone_footer");
return template.apply(context);
} catch (IOException e) {
log.warn("Timezone footer failed", e);
return "";
}
} else {
return "";
}
}
示例6: compileOrDie
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
public Template compileOrDie(String template, Handlebars handlebars) {
try {
return handlebars.compile(template);
} catch (IOException e) {
throw new IllegalStateException("Error compiling template '"+ template+"': "+e, e);
}
}
示例7: providesRunnerTemplate
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Provides
@Singleton
@Named(RUNNER_TEMPLATE)
public Template providesRunnerTemplate(Handlebars handlebars) throws IOException {
return handlebars.compile(RUNNER_TEMPLATE);
}
示例8: providesEnvironmentTemplate
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Provides
@Singleton
@Named(ENVIRONMENT_TEMPLATE)
public Template providesEnvironmentTemplate(Handlebars handlebars) throws IOException {
return handlebars.compile(ENVIRONMENT_TEMPLATE);
}
示例9: providesLogrotateTemplate
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Provides
@Singleton
@Named(LOGROTATE_TEMPLATE)
public Template providesLogrotateTemplate(Handlebars handlebars) throws IOException {
return handlebars.compile(LOGROTATE_TEMPLATE);
}
示例10: providesDockerTempalte
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Provides
@Singleton
@Named(DOCKER_TEMPLATE)
public Template providesDockerTempalte(Handlebars handlebars) throws IOException {
return handlebars.compile(DOCKER_TEMPLATE);
}
示例11: initTemplate
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
private static Template initTemplate(String templateName) throws IOException {
Handlebars handlebars = new Handlebars(new ClassPathTemplateLoader(sf_templatePrefix));
StringHelpers.register(handlebars);
handlebars.registerHelpers(ReportHelpers.class);
return handlebars.compile(templateName);
}
示例12: doGet
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
checkAccessControl();
I18n i18n = tagService.getI18n(this.getClass().getClassLoader(), "org.sakaiproject.tags.tool.i18n.tagservice");
response.setHeader("Content-Type", "text/html");
URL toolBaseURL = determineBaseURL();
Handlebars handlebars = loadHandlebars(toolBaseURL, i18n);
try {
Template template = handlebars.compile("org/sakaiproject/tags/tool/views/layout");
Map<String, Object> context = new HashMap<>();
context.put("baseURL", toolBaseURL);
context.put("layout", true);
context.put("skinRepo", serverConfigurationService.getString("skin.repo", ""));
context.put("randomSakaiHeadStuff", request.getAttribute("sakai.html.head"));
Handler handler = handlerForRequest(request);
Map<String, List<String>> messages = loadFlashMessages();
handler.handle(request, response, context);
storeFlashMessages(handler.getFlashMessages());
if (handler.hasRedirect()) {
response.sendRedirect(toolBaseURL + handler.getRedirect());
} else {
context.put("flash", messages);
context.put("errors", handler.getErrors().toList());
if (Boolean.TRUE.equals(context.get("layout"))) {
response.getWriter().write(template.apply(context));
}
}
} catch (IOException e) {
log.warn("Write failed", e);
}
}
示例13: doGet
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
checkAccessControl();
I18n i18n = paSystem.getI18n(this.getClass().getClassLoader(), "org.sakaiproject.pasystem.tool.i18n.pasystem");
response.setHeader("Content-Type", "text/html");
URL toolBaseURL = determineBaseURL();
Handlebars handlebars = loadHandlebars(toolBaseURL, i18n);
try {
Template template = handlebars.compile("org/sakaiproject/pasystem/tool/views/layout");
Map<String, Object> context = new HashMap<String, Object>();
context.put("baseURL", toolBaseURL);
context.put("layout", true);
context.put("skinRepo", ServerConfigurationService.getString("skin.repo", ""));
context.put("randomSakaiHeadStuff", request.getAttribute("sakai.html.head"));
Handler handler = handlerForRequest(request);
Map<String, List<String>> messages = loadFlashMessages();
handler.handle(request, response, context);
storeFlashMessages(handler.getFlashMessages());
if (handler.hasRedirect()) {
response.sendRedirect(toolBaseURL + handler.getRedirect());
} else {
context.put("flash", messages);
context.put("errors", handler.getErrors().toList());
if (Boolean.TRUE.equals(context.get("layout"))) {
response.getWriter().write(template.apply(context));
}
}
} catch (IOException e) {
log.warn("Write failed", e);
}
}
示例14: providesLogrotateCronTemplate
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
@Provides
@Singleton
@Named(LOGROTATE_CRON_TEMPLATE)
public Template providesLogrotateCronTemplate(Handlebars handlebars) throws IOException {
return handlebars.compile(LOGROTATE_CRON_TEMPLATE);
}