Search in sources :

Example 6 with OrchidContext

use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.

the class ModularListOptionExtractor method getDefaultValue.

@Override
public ModularList getDefaultValue(Field field) {
    OrchidContext context = contextProvider.get();
    ModularList modularList = (ModularList) context.resolve(field.getType());
    modularList.initialize(context, new ArrayList<>());
    return modularList;
}
Also used : ModularList(com.eden.orchid.api.theme.components.ModularList) OrchidContext(com.eden.orchid.api.OrchidContext)

Example 7 with OrchidContext

use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.

the class ModularListOptionExtractor method getOption.

@Override
public ModularList getOption(Field field, Object sourceObject, String key) {
    OrchidContext context = contextProvider.get();
    final String typeKey;
    final String valueKey;
    if (field.isAnnotationPresent(ImpliedKey.class)) {
        ImpliedKey impliedKey = field.getAnnotation(ImpliedKey.class);
        typeKey = impliedKey.typeKey();
        valueKey = impliedKey.valueKey();
    } else {
        typeKey = null;
        valueKey = null;
    }
    Iterable iterable = iterableConverter.convert(field.getType(), sourceObject, typeKey, valueKey).second;
    List<Map<String, Object>> jsonArray = new ArrayList<>();
    for (Object o : iterable) {
        Map<String, Object> map = (Map<String, Object>) mapConverter.convert(field.getType(), o).second;
        jsonArray.add(map);
    }
    if (jsonArray.size() > 0) {
        ModularList modularList = (ModularList) contextProvider.get().resolve(field.getType());
        modularList.initialize(context, jsonArray);
        return modularList;
    }
    return null;
}
Also used : ModularList(com.eden.orchid.api.theme.components.ModularList) OrchidContext(com.eden.orchid.api.OrchidContext) ImpliedKey(com.eden.orchid.api.options.annotations.ImpliedKey) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 8 with OrchidContext

use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.

the class Orchid method start.

public boolean start(List<Module> modules) {
    OrchidContext context = null;
    try {
        String moduleLog = "\n--------------------";
        for (Module module : modules) {
            if (!module.getClass().getName().startsWith("com.eden.orchid.OrchidModule")) {
                moduleLog += "\n * " + module.getClass().getName();
            }
        }
        moduleLog += "\n";
        Clog.tag("Using the following modules").log(moduleLog);
        Injector injector = Guice.createInjector(modules);
        String flagLog = "";
        flagLog += "\n--------------------\n";
        flagLog += OrchidFlags.getInstance().printFlags();
        flagLog += "\n";
        Clog.tag("Flag values").log(flagLog);
        context = injector.getInstance(OrchidContext.class);
        try {
            OrchidSecurityManager manager = injector.getInstance(OrchidSecurityManager.class);
            System.setSecurityManager(manager);
        } catch (Exception e) {
        }
        Clog.i("Running Orchid version {}, site version {} in {} environment", context.getOrchidVersion(), context.getVersion(), context.getEnvironment());
        context.start();
        context.finish();
        return true;
    } catch (Exception e) {
        Clog.e("Something went wrong running Orchid", e);
        e.printStackTrace();
        if (context != null) {
            context.broadcast(Orchid.Lifecycle.Shutdown.fire(context, this));
        }
        return false;
    }
}
Also used : OrchidContext(com.eden.orchid.api.OrchidContext) Injector(com.google.inject.Injector) OrchidSecurityManager(com.eden.orchid.api.OrchidSecurityManager) Module(com.google.inject.Module)

Example 9 with OrchidContext

use of com.eden.orchid.api.OrchidContext 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 10 with OrchidContext

use of com.eden.orchid.api.OrchidContext 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)

Aggregations

OrchidContext (com.eden.orchid.api.OrchidContext)14 OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)6 TemplateTag (com.eden.orchid.api.compilers.TemplateTag)4 PebbleWrapperTemplateTag (com.eden.orchid.impl.compilers.pebble.PebbleWrapperTemplateTag)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Map (java.util.Map)3 OrchidResource (com.eden.orchid.api.resources.resource.OrchidResource)2 StringResource (com.eden.orchid.api.resources.resource.StringResource)2 ModularList (com.eden.orchid.api.theme.components.ModularList)2 OrchidReference (com.eden.orchid.api.theme.pages.OrchidReference)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 JSONObject (org.json.JSONObject)2 Clog (com.caseyjbrooks.clog.Clog)1 JSONElement (com.eden.common.json.JSONElement)1 OrchidSecurityManager (com.eden.orchid.api.OrchidSecurityManager)1 OrchidRootIndex (com.eden.orchid.api.indexing.OrchidRootIndex)1 OptionsExtractor (com.eden.orchid.api.options.OptionsExtractor)1 ImpliedKey (com.eden.orchid.api.options.annotations.ImpliedKey)1