Search in sources :

Example 16 with OrchidPage

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

the class AssetsGenerator method startIndexing.

@Override
public List<? extends OrchidPage> startIndexing() {
    List<OrchidResource> resourcesList = resources.getResourceEntries("assets", null, true);
    List<OrchidPage> assets = new ArrayList<>();
    for (OrchidResource entry : resourcesList) {
        //            entry.getReference().setBasePath("assets");
        assets.add(new OrchidPage(entry));
    }
    return assets;
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) ArrayList(java.util.ArrayList)

Example 17 with OrchidPage

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

the class PebbleWrapperTemplateFunction method doExecute.

private Object doExecute(Map<String, Object> args, EvaluationContext context) {
    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 18 with OrchidPage

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

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

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

the class GeneratorServiceTest method setUp.

@BeforeEach
public void setUp() {
    context = mock(OrchidContext.class);
    extractor = mock(OptionsExtractor.class);
    theme = mock(Theme.class);
    buildMetrics = new BuildMetrics(context);
    internalIndex = new OrchidRootIndex(context, "internal");
    when(context.resolve(OptionsExtractor.class)).thenReturn(extractor);
    when(context.findTheme(any())).thenReturn(theme);
    when(context.getIndex()).thenReturn(internalIndex);
    when(context.includeDrafts()).thenReturn(false);
    when(context.getEmbeddedData(anyString(), anyString())).thenReturn(new EdenPair<>("", new HashMap<>()));
    generators = new HashSet<>();
    mockPage1Reference = new OrchidReference(context, "page1.html");
    mockPage1Resource = new StringResource(mockPage1Reference, "");
    mockPage1 = spy(new OrchidPage(mockPage1Resource, RenderService.RenderMode.TEMPLATE, "mockPage1", ""));
    pages1 = new ArrayList<>();
    pages1.add(mockPage1);
    generator1 = spy(new MockGenerator("gen1", OrchidGenerator.Stage.COLLECTION, pages1));
    generators.add(generator1);
    mockPage2Reference = new OrchidReference(context, "page2.html");
    mockFreeableResource = spy(new OrchidResource(mockPage2Reference) {

        @Nonnull
        @Override
        public InputStream getContentStream() {
            return OrchidExtensionsKt.asInputStream("");
        }
    });
    mockPage2 = spy(new OrchidPage(mockFreeableResource, RenderService.RenderMode.TEMPLATE, "mockPage2", ""));
    pages2 = new ArrayList<>();
    pages2.add(mockPage2);
    generator2 = spy(new MockGenerator("gen2", OrchidGenerator.Stage.CONTENT, pages2));
    generators.add(generator2);
    pages3 = new ArrayList<>();
    generator3 = new MockGenerator("gen3", OrchidGenerator.Stage.WARM_UP, pages3);
    generator3 = spy(generator3);
    generators.add(generator3);
    when(context.resolveSet(OrchidGenerator.class)).thenReturn(generators);
    // test the service directly
    service = new GeneratorServiceImpl();
    service.initialize(context);
    // test that the default implementation is identical to the real implementation
    underTest = new GeneratorService() {

        public void initialize(OrchidContext context) {
        }

        public <T extends OrchidService> T getService(Class<T> serviceClass) {
            return (T) service;
        }
    };
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) OrchidContext(com.eden.orchid.api.OrchidContext) HashMap(java.util.HashMap) OptionsExtractor(com.eden.orchid.api.options.OptionsExtractor) StringResource(com.eden.orchid.api.resources.resource.StringResource) OrchidReference(com.eden.orchid.api.theme.pages.OrchidReference) OrchidRootIndex(com.eden.orchid.api.indexing.OrchidRootIndex) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) Theme(com.eden.orchid.api.theme.Theme) BeforeEach(org.junit.jupiter.api.BeforeEach)

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