use of com.eden.orchid.api.compilers.TemplateTag in project Orchid by JavaEden.
the class ContentTagParser method render.
@Override
public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context) throws IOException {
OrchidContext orchidContext = contextProvider.get();
TemplateTag freshTag = orchidContext.resolve(tagClass);
Map<String, Object> evaluatedParamExpressionMap = evaluateParams(paramExpressionMap, self, context);
Object pageVar = context.getVariable("page");
final OrchidPage actualPage;
if (pageVar instanceof OrchidPage) {
actualPage = (OrchidPage) pageVar;
} else {
actualPage = null;
}
freshTag.extractOptions(orchidContext, evaluatedParamExpressionMap);
String bodyContent = StringUtils.toString(tagBodyExpression.evaluate(self, context)).trim();
TemplateTag.Tab tab = new TemplateTag.SimpleTab(null, null, bodyContent);
freshTag.setContent(tab);
freshTag.onRender(orchidContext, actualPage);
if (freshTag.rendersContent()) {
writer.append(freshTag.renderContent(orchidContext, actualPage));
}
}
use of com.eden.orchid.api.compilers.TemplateTag in project Orchid by JavaEden.
the class SimpleTagParser method render.
@Override
public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context) throws IOException {
OrchidContext orchidContext = contextProvider.get();
TemplateTag freshTag = orchidContext.resolve(tagClass);
Map<String, Object> evaluatedParamExpressionMap = evaluateParams(paramExpressionMap, self, context);
Object pageVar = context.getVariable("page");
final OrchidPage actualPage;
if (pageVar instanceof OrchidPage) {
actualPage = (OrchidPage) pageVar;
} else {
actualPage = null;
}
freshTag.extractOptions(orchidContext, evaluatedParamExpressionMap);
freshTag.onRender(orchidContext, actualPage);
if (freshTag.rendersContent()) {
writer.append(freshTag.renderContent(orchidContext, actualPage));
}
}
use of com.eden.orchid.api.compilers.TemplateTag in project Orchid by JavaEden.
the class NonDynamicTabbedTagParser method render.
@Override
public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context) throws IOException {
OrchidContext orchidContext = contextProvider.get();
// create a new tag
TemplateTag freshTag = orchidContext.resolve(tagClass);
// evaluate its own params and populate the main Tag class with them
Map<String, Object> evaluatedParamExpressionMap = evaluateParams(paramExpressionMap, self, context);
Object pageVar = context.getVariable("page");
final OrchidPage actualPage;
if (pageVar instanceof OrchidPage) {
actualPage = (OrchidPage) pageVar;
} else {
actualPage = null;
}
freshTag.extractOptions(orchidContext, evaluatedParamExpressionMap);
// populate the content of each tab
for (Map.Entry<String, Expression<?>> tagBodyExpression : tagBodyExpressions.entrySet()) {
// get the tab body content
String key = tagBodyExpression.getKey();
String bodyContent = StringUtils.toString(tagBodyExpression.getValue().evaluate(self, context)).trim();
// Get a new Tab instance, evaluate that tab's options, and then populate the Tab instance with them
TemplateTag.Tab tab = freshTag.getNewTab(key, bodyContent);
Map<String, Object> tabParams = evaluateParams(tagBodyParams.get(key), self, context);
tab.extractOptions(orchidContext, tabParams);
// add the tab to the Tag
freshTag.setContent(key, tab);
}
freshTag.onRender(orchidContext, actualPage);
if (freshTag.rendersContent()) {
writer.append(freshTag.renderContent(orchidContext, actualPage));
}
}
use of com.eden.orchid.api.compilers.TemplateTag in project Orchid by JavaEden.
the class DynamicTabbedTagParser method render.
@Override
public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context) throws IOException {
OrchidContext orchidContext = contextProvider.get();
// create a new tag
TemplateTag freshTag = orchidContext.resolve(tagClass);
context.getScopeChain().pushScope(MapsKt.mapOf(new Pair<>("__parentTabbedTag", freshTag)));
// evaluate its own params and populate the main Tag class with them
Map<String, Object> evaluatedParamExpressionMap = evaluateParams(paramExpressionMap, self, context);
Object pageVar = context.getVariable("page");
final OrchidPage actualPage;
if (pageVar instanceof OrchidPage) {
actualPage = (OrchidPage) pageVar;
} else {
actualPage = null;
}
freshTag.extractOptions(orchidContext, evaluatedParamExpressionMap);
String bodyContent = StringUtils.toString(tagBodyExpression.evaluate(self, context)).trim();
TemplateTag.Tab tab = new TemplateTag.SimpleTab(null, null, bodyContent);
freshTag.onRender(orchidContext, actualPage);
if (freshTag.rendersContent()) {
writer.append(freshTag.renderContent(orchidContext, actualPage));
}
context.getScopeChain().popScope();
}
use of com.eden.orchid.api.compilers.TemplateTag in project Orchid by JavaEden.
the class CorePebbleExtension method getTokenParsers.
@Override
public List<TokenParser> getTokenParsers() {
List<TokenParser> tokenParsers = new ArrayList<>();
Set<String> childTabNames = new HashSet<>();
for (TemplateTag templateTag : templateTags) {
final String[] tabParams;
final Class<? extends TemplateTag.Tab> tabClass;
if (templateTag.getType() == TemplateTag.Type.Tabbed) {
TemplateTag.Tab tab = templateTag.getNewTab("", "");
tabParams = tab.parameters();
tabClass = tab.getClass();
childTabNames.add(tab.getType());
} else {
tabParams = null;
tabClass = null;
}
tokenParsers.add(new PebbleWrapperTemplateTag(contextProvider, templateTag.getName(), templateTag.getType(), templateTag.parameters(), templateTag.getClass(), tabParams, tabClass));
}
for (String childTabName : childTabNames) {
tokenParsers.add(new PebbleWrapperTemplateTagChildTab(contextProvider, childTabName));
}
return tokenParsers;
}
Aggregations