All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.varmateo.yawg.core.DefaultExtensionsModule Maven / Gradle / Ivy

/**************************************************************************
 *
 * Copyright (c) 2019-2020 Yawg project contributors.
 *
 **************************************************************************/

package com.varmateo.yawg.core;

import java.nio.file.Path;
import java.util.function.Function;

import io.vavr.Lazy;
import io.vavr.collection.List;
import io.vavr.collection.Seq;
import io.vavr.control.Option;

import com.varmateo.yawg.asciidoctor.AsciidoctorPageBaker;
import com.varmateo.yawg.breadcrumbs.BreadcrumbsBakeListener;
import com.varmateo.yawg.commonmark.CommonMarkPageBaker;
import com.varmateo.yawg.freemarker.FreemarkerTemplateService;
import com.varmateo.yawg.html.HtmlPageBaker;
import com.varmateo.yawg.spi.DirBakeListener;
import com.varmateo.yawg.spi.PageBaker;
import com.varmateo.yawg.spi.TemplateService;


/**
 *
 */
/* default */ final class DefaultExtensionsModule {


    private final Option _templatesDir;

    private final Lazy> _pageBakers =
            Lazy.of(this::createPageBakers);

    private final Lazy> _templateServices =
            Lazy.of(this::createTemplateServices);

    private final Lazy> _dirBakeListeners =
            Lazy.of(this::createDirBakeListeners);


    private DefaultExtensionsModule(final Option templatesDir) {

        _templatesDir = templatesDir;
    }


    /**
     *
     */
    public static DefaultExtensionsModule create(final Option templatesDir) {

        return new DefaultExtensionsModule(templatesDir);
    }


    /**
     *
     */
    public Seq pageBakers() {

        return _pageBakers.get();
    }


    /**
     *
     */
    public Seq templateServices() {

        return _templateServices.get();
    }


    /**
     *
     */
    public Seq dirBakeListeners() {

        return _dirBakeListeners.get();
    }


    private Seq createPageBakers() {

        return List.of(
                AsciidoctorPageBaker.create(),
                HtmlPageBaker.create(),
                CommonMarkPageBaker.create());
    }


    private Seq createTemplateServices() {

        final List> templateServiceFactories = List.of(
                FreemarkerTemplateService::create);
        final Function> createTemplateServices =
                path -> templateServiceFactories.map(factory -> factory.apply(path));

        return _templatesDir
                .map(createTemplateServices)
                .getOrElse(List::empty);
    }


    private Seq createDirBakeListeners() {

        return List.of(
                BreadcrumbsBakeListener.create());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy