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;
}
}
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));
}
}
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));
}
}
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;
}
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);
}
Aggregations