Search in sources :

Example 1 with Theme

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

the class ThemeOption method parseOption.

@Override
public JSONElement parseOption(String[] options) {
    try {
        Class<? extends Theme> themeClass = (Class<? extends Theme>) Class.forName(options[1]);
        Theme theme = Orchid.getInstance().getInjector().getInstance(themeClass);
        if (theme != null) {
            Orchid.getInstance().getContext().setTheme(theme);
            return new JSONElement(options[1]);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    Clog.e("The Theme class #{$1} could not be found. Please make sure it has been registered properly.", new Object[] { options[1] });
    return new JSONElement(options[1]);
}
Also used : JSONElement(com.eden.common.json.JSONElement) Theme(com.eden.orchid.api.theme.Theme)

Example 2 with Theme

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

the class OrchidContextImpl method reorderThemes.

private void reorderThemes() {
    Class<?> superclass = getTheme().getClass();
    int i = 0;
    // find the highest priority of any Theme
    int highestThemePriority = 0;
    for (OrchidResourceSource resourceSourceEntry : OrchidUtils.resolveSet(this, OrchidResourceSource.class)) {
        if (resourceSourceEntry instanceof Theme) {
            highestThemePriority = Math.max(highestThemePriority, resourceSourceEntry.getPriority());
        }
    }
    // Go through all Themes and set each parent theme as the next-highest Theme priority
    while (!superclass.equals(Theme.class)) {
        for (OrchidResourceSource resourceSourceEntry : OrchidUtils.resolveSet(this, OrchidResourceSource.class)) {
            if (resourceSourceEntry instanceof Theme) {
                Theme theme = (Theme) resourceSourceEntry;
                if (theme.getClass().equals(superclass)) {
                    theme.setPriority((highestThemePriority) - i);
                    break;
                }
            }
        }
        i++;
        superclass = superclass.getSuperclass();
    }
}
Also used : Theme(com.eden.orchid.api.theme.Theme) OrchidResourceSource(com.eden.orchid.api.resources.resourceSource.OrchidResourceSource)

Example 3 with Theme

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

the class OrchidContextImpl method reorderResourceSources.

private void reorderResourceSources() {
    Theme theme = getTheme();
    reorderThemes();
    for (OrchidResourceSource source : OrchidUtils.resolveSet(this, DefaultResourceSource.class)) {
        if (source instanceof Theme) {
            if (!source.getClass().isAssignableFrom(theme.getClass())) {
                source.setPriority(-1);
            }
        }
    }
}
Also used : Theme(com.eden.orchid.api.theme.Theme) OrchidResourceSource(com.eden.orchid.api.resources.resourceSource.OrchidResourceSource)

Example 4 with Theme

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

the class ListThemesTask method run.

@Override
public void run() {
    Clog.logger(OrchidTasks.loggerKey, "" + "#{ $0 | fg('cyan') }[Priority]#{$0 |reset}" + "#{ $0 | fg('magenta') }[Theme]#{$0 |reset}" + "#{ $0 | fg('blue') }[Theme Parent]#{$0 |reset}" + "");
    Clog.logger(OrchidTasks.loggerKey, "------------------------------------------------------------------------------------");
    Clog.logger(OrchidTasks.loggerKey, "------------------------------------------------------------------------------------");
    for (Theme theme : themes) {
        String message;
        if (theme.getPriority() < 0) {
            message = "#{ $0 | fg('red') }[#{$1}][#{$2}]";
            if (!theme.getClass().getSuperclass().equals(Theme.class)) {
                message += "[#{$3}]";
            }
            message += "(inactive)#{$0 |reset}";
        } else {
            message = "#{ $0 | fg('cyan') }[#{$1}]#{$0 |reset}";
            message += "#{ $0 | fg('magenta') }[#{$2}]#{$0 |reset}";
            if (!theme.getClass().getSuperclass().equals(Theme.class)) {
                message += "#{ $0 | fg('blue') }[#{$3}]#{$0 |reset}";
            }
        }
        Clog.logger(OrchidTasks.loggerKey, message, new Object[] { theme.getPriority(), theme.getClass().getName(), theme.getClass().getSuperclass().getSimpleName() });
    }
}
Also used : Theme(com.eden.orchid.api.theme.Theme)

Example 5 with Theme

use of com.eden.orchid.api.theme.Theme 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

Theme (com.eden.orchid.api.theme.Theme)5 OrchidResourceSource (com.eden.orchid.api.resources.resourceSource.OrchidResourceSource)2 JSONElement (com.eden.common.json.JSONElement)1 OrchidContext (com.eden.orchid.api.OrchidContext)1 OrchidRootIndex (com.eden.orchid.api.indexing.OrchidRootIndex)1 OptionsExtractor (com.eden.orchid.api.options.OptionsExtractor)1 OrchidResource (com.eden.orchid.api.resources.resource.OrchidResource)1 StringResource (com.eden.orchid.api.resources.resource.StringResource)1 OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)1 OrchidReference (com.eden.orchid.api.theme.pages.OrchidReference)1 HashMap (java.util.HashMap)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1