Search in sources :

Example 6 with OrchidPage

use of com.eden.orchid.api.theme.pages.OrchidPage in project Orchid by JavaEden.

the class PebbleWrapperTemplateFilter method doApply.

private Object doApply(Object input, Map<String, Object> args, EvaluationContext context) throws PebbleException {
    args.put(inputParam, input);
    TemplateFunction freshFunction = contextProvider.get().resolve(functionClass);
    Object pageVar = context.getVariable("page");
    final OrchidPage actualPage;
    if (pageVar instanceof OrchidPage) {
        actualPage = (OrchidPage) pageVar;
    } else {
        actualPage = null;
    }
    freshFunction.extractOptions(contextProvider.get(), args);
    Object output = freshFunction.apply(contextProvider.get(), actualPage);
    if (freshFunction.isSafeString()) {
        return new SafeString(output.toString());
    } else {
        return output;
    }
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) TemplateFunction(com.eden.orchid.api.compilers.TemplateFunction) SafeString(com.mitchellbosecke.pebble.extension.escaper.SafeString)

Example 7 with OrchidPage

use of com.eden.orchid.api.theme.pages.OrchidPage 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 8 with OrchidPage

use of com.eden.orchid.api.theme.pages.OrchidPage 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 9 with OrchidPage

use of com.eden.orchid.api.theme.pages.OrchidPage in project Orchid by JavaEden.

the class AdminAssetResponse method getResponse.

static OrchidResponse getResponse(OrchidContext context, File targetFile, String targetPath) {
    AdminTheme theme = context.getAdminTheme();
    OrchidResource res = theme.getResourceSource().getResourceEntry(context, targetPath);
    String mimeType = StaticFileResponse.mimeTypes.getOrDefault(FilenameUtils.getExtension(targetFile.getName()), "text/plain");
    Clog.i("Rendering admin File: #{$1}", targetPath);
    if (res != null) {
        if (context.isBinaryExtension(FilenameUtils.getExtension(targetFile.getName()))) {
            InputStream stream = res.getContentStream();
            return new OrchidResponse(context).contentStream(stream).mimeType(mimeType);
        } else {
            OrchidPage page = new OrchidPage(res, RenderService.RenderMode.TEMPLATE, "", null);
            return new OrchidResponse(context).mimeType(mimeType).content(page.getContent()).mimeType(mimeType);
        }
    }
    return null;
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) OrchidResponse(com.eden.orchid.api.server.OrchidResponse) InputStream(java.io.InputStream) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) AdminTheme(com.eden.orchid.api.theme.AdminTheme)

Example 10 with OrchidPage

use of com.eden.orchid.api.theme.pages.OrchidPage in project Orchid by JavaEden.

the class NotFound404Response method getResponse.

static OrchidResponse getResponse(OrchidContext context, String targetPath) {
    String content = "";
    Clog.i("Rendering 404: #{$1}", targetPath);
    OrchidResource resource = context.getFlexibleResourceSource(LocalResourceSource.INSTANCE, null).locateResourceEntry(context, "404");
    OrchidPage page = null;
    if (resource != null) {
        page = new OrchidPage(resource, RenderService.RenderMode.TEMPLATE, "404", "Not Found!");
    } else {
        resource = context.getDefaultResourceSource(null, null).getResourceEntry(context, "templates/server/404.peb");
        Map<String, Object> indexPageVars = new HashMap<>();
        indexPageVars.put("title", "Not Found - " + targetPath);
        indexPageVars.put("path", targetPath);
        Map<String, Object> object = new HashMap<>(context.getConfig());
        object.put("page", indexPageVars);
        object.put("theme", context.getTheme());
        String notFoundIndexContent;
        if (resource != null) {
            notFoundIndexContent = context.compile(resource, resource.getReference().getExtension(), resource.getContent(), object);
        } else {
            notFoundIndexContent = context.serialize("json", object);
        }
        page = new OrchidPage(new StringResource(new OrchidReference(context, "404.txt"), notFoundIndexContent), RenderService.RenderMode.TEMPLATE, "404", "Not Found!");
    }
    return new OrchidResponse(context).page(page).status(404);
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) StringResource(com.eden.orchid.api.resources.resource.StringResource) OrchidReference(com.eden.orchid.api.theme.pages.OrchidReference) HashMap(java.util.HashMap) OrchidResponse(com.eden.orchid.api.server.OrchidResponse) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource)

Aggregations

OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)22 OrchidResource (com.eden.orchid.api.resources.resource.OrchidResource)7 HashMap (java.util.HashMap)7 OrchidContext (com.eden.orchid.api.OrchidContext)6 ArrayList (java.util.ArrayList)5 TemplateTag (com.eden.orchid.api.compilers.TemplateTag)4 StringResource (com.eden.orchid.api.resources.resource.StringResource)4 OrchidResponse (com.eden.orchid.api.server.OrchidResponse)4 OrchidReference (com.eden.orchid.api.theme.pages.OrchidReference)4 PebbleWrapperTemplateTag (com.eden.orchid.impl.compilers.pebble.PebbleWrapperTemplateTag)4 Map (java.util.Map)4 JSONArray (org.json.JSONArray)4 JSONObject (org.json.JSONObject)3 TemplateFunction (com.eden.orchid.api.compilers.TemplateFunction)2 AssetPage (com.eden.orchid.api.theme.assets.AssetPage)2 OrchidInternalIndex (com.eden.orchid.impl.indexing.OrchidInternalIndex)2 SafeString (com.mitchellbosecke.pebble.extension.escaper.SafeString)2 Clog (com.caseyjbrooks.clog.Clog)1 JSONElement (com.eden.common.json.JSONElement)1 EdenPair (com.eden.common.util.EdenPair)1