Search in sources :

Example 1 with TemplateTag

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));
    }
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) OrchidContext(com.eden.orchid.api.OrchidContext) TemplateTag(com.eden.orchid.api.compilers.TemplateTag) PebbleWrapperTemplateTag(com.eden.orchid.impl.compilers.pebble.PebbleWrapperTemplateTag)

Example 2 with TemplateTag

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));
    }
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) OrchidContext(com.eden.orchid.api.OrchidContext) TemplateTag(com.eden.orchid.api.compilers.TemplateTag) PebbleWrapperTemplateTag(com.eden.orchid.impl.compilers.pebble.PebbleWrapperTemplateTag)

Example 3 with TemplateTag

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));
    }
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) OrchidContext(com.eden.orchid.api.OrchidContext) TemplateTag(com.eden.orchid.api.compilers.TemplateTag) PebbleWrapperTemplateTag(com.eden.orchid.impl.compilers.pebble.PebbleWrapperTemplateTag) Expression(com.mitchellbosecke.pebble.node.expression.Expression) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with TemplateTag

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();
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) OrchidContext(com.eden.orchid.api.OrchidContext) TemplateTag(com.eden.orchid.api.compilers.TemplateTag) PebbleWrapperTemplateTag(com.eden.orchid.impl.compilers.pebble.PebbleWrapperTemplateTag) Pair(kotlin.Pair)

Example 5 with TemplateTag

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;
}
Also used : TemplateTag(com.eden.orchid.api.compilers.TemplateTag) ArrayList(java.util.ArrayList) TokenParser(com.mitchellbosecke.pebble.tokenParser.TokenParser) HashSet(java.util.HashSet)

Aggregations

TemplateTag (com.eden.orchid.api.compilers.TemplateTag)5 OrchidContext (com.eden.orchid.api.OrchidContext)4 OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)4 PebbleWrapperTemplateTag (com.eden.orchid.impl.compilers.pebble.PebbleWrapperTemplateTag)4 Expression (com.mitchellbosecke.pebble.node.expression.Expression)1 TokenParser (com.mitchellbosecke.pebble.tokenParser.TokenParser)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Pair (kotlin.Pair)1