use of com.github.jknack.handlebars.Handlebars in project wcomponents by BorderTech.
the class HandlebarsRendererImpl method renderTemplate.
/**
* {@inheritDoc}
*/
@Override
public void renderTemplate(final String templateName, final Map<String, Object> context, final Map<String, WComponent> taggedComponents, final Writer writer, final Map<String, Object> options) {
LOG.debug("Rendering handlebars template " + templateName);
try {
// Map the tagged components to be used in the replace writer
Map<String, WComponent> componentsByKey = TemplateUtil.mapTaggedComponents(context, taggedComponents);
// Get Engine
Handlebars handlebars = getHandlebarsEngine(options);
// Load template (Handlebars loader makes the template name "absolute")
Template template = handlebars.compile(templateName);
// Setup handlebars context
Context handlebarsContext = createContext(context);
// Render
writeTemplate(template, handlebarsContext, componentsByKey, writer);
} catch (FileNotFoundException e) {
throw new SystemException("Could not find handlebars template [" + templateName + "]. " + e.getMessage(), e);
} catch (Exception e) {
throw new SystemException("Problems with handlebars template [" + templateName + "]. " + e.getMessage(), e);
}
}
use of com.github.jknack.handlebars.Handlebars in project wcomponents by BorderTech.
the class HandlebarsRendererImpl method renderInline.
/**
* {@inheritDoc}
*/
@Override
public void renderInline(final String templateInline, final Map<String, Object> context, final Map<String, WComponent> taggedComponents, final Writer writer, final Map<String, Object> options) {
LOG.debug("Rendering handlebars inline template.");
try {
// Map the tagged components to be used in the replace writer
Map<String, WComponent> componentsByKey = TemplateUtil.mapTaggedComponents(context, taggedComponents);
// Get Engine
Handlebars handlebars = getHandlebarsEngine(options);
// Compile inline
Template template = handlebars.compileInline(templateInline);
// Setup handlebars context
Context handlebarsContext = createContext(context);
// Write template
writeTemplate(template, handlebarsContext, componentsByKey, writer);
} catch (Exception e) {
throw new SystemException("Problems with handlebars inline template. " + e.getMessage(), e);
}
}
use of com.github.jknack.handlebars.Handlebars in project cw-omnibus by commonsguy.
the class WebServerService method onCreate.
@Override
public void onCreate() {
super.onCreate();
ConnectivityManager mgr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo ni = mgr.getActiveNetworkInfo();
if (ni == null || ni.getType() == ConnectivityManager.TYPE_MOBILE) {
EventBus.getDefault().post(new ServerStartRejectedEvent());
stopSelf();
} else {
handlebars = new Handlebars(new AssetTemplateLoader(getAssets()));
rootPath = "/" + new BigInteger(20, rng).toString(24).toUpperCase();
server = new AsyncHttpServer();
if (configureRoutes(server)) {
server.get("/.*", new AssetRequestCallback());
}
server.listen(getPort());
raiseReadyEvent();
foregroundify();
timeoutFuture = timer.schedule(onTimeout, getMaxIdleTimeSeconds(), TimeUnit.SECONDS);
}
}
use of com.github.jknack.handlebars.Handlebars in project ratpack by ratpack.
the class HandlebarsModule method provideHandlebars.
@SuppressWarnings("UnusedDeclaration")
@Provides
@Singleton
Handlebars provideHandlebars(Config config, Injector injector, TemplateLoader templateLoader, TemplateCache templateCache) {
final Handlebars handlebars = new Handlebars().with(templateLoader).with(templateCache).startDelimiter(config.getStartDelimiter()).endDelimiter(config.getEndDelimiter());
GuiceUtil.eachOfType(injector, NAMED_HELPER_TYPE, helper -> handlebars.registerHelper(helper.getName(), helper));
return handlebars;
}
use of com.github.jknack.handlebars.Handlebars in project ddf by codice.
the class FeedbackApplication method initConfigurationAppValues.
private void initConfigurationAppValues(boolean reinit) {
Handlebars handlebars = new Handlebars();
if (reinit || subjectTemplate == null || bodyTemplate == null) {
if (configurationApplication != null) {
emailDestination = configurationApplication.getQueryFeedbackEmailDestination();
String subjectTemplateStr = configurationApplication.getQueryFeedbackEmailSubjectTemplate();
String bodyTemplateStr = configurationApplication.getQueryFeedbackEmailBodyTemplate();
try {
if (subjectTemplateStr != null) {
subjectTemplate = handlebars.compileInline(subjectTemplateStr);
}
if (bodyTemplateStr != null) {
bodyTemplate = handlebars.compileInline(bodyTemplateStr);
}
} catch (IOException e) {
LOGGER.warn("Unable to compile email templates", e);
}
} else {
LOGGER.debug("Feedback configuration is not set");
}
}
}
Aggregations