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

com.github.nagyesta.lowkeyvault.template.backup.BackupTemplateProcessor Maven / Gradle / Ivy

package com.github.nagyesta.lowkeyvault.template.backup;

import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
import com.github.nagyesta.lowkeyvault.template.HandlebarsTemplateProcessor;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class BackupTemplateProcessor implements HandlebarsTemplateProcessor {

    private final TimeHelperSource timeHelperSource;

    @Autowired
    public BackupTemplateProcessor(final TimeHelperSource timeHelperSource) {
        this.timeHelperSource = timeHelperSource;
    }

    @Override
    public String processTemplate(@NonNull final String templateAsString, @NonNull final BackupContext context) throws IOException {
        final Handlebars handlebars = new Handlebars();
        handlebars.registerHelpers(timeHelperSource);
        final Template template = handlebars.compileInline(templateAsString);
        return template.apply(context);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy