added a first version of java doc for the templating module

This commit is contained in:
Sheldan
2020-05-11 20:46:14 +02:00
parent e89c3b8796
commit 70428e6e03
19 changed files with 283 additions and 10 deletions

View File

@@ -1,6 +1,19 @@
package dev.sheldan.abstracto.templating;
/**
* An interface to be used on objects, which should be able to be processable by the template engine.
* This contains a template key and the model which is used when rendering this template.
*/
public interface Templatable {
/**
* The template key to be used to render this object.
* @return The template key as string
*/
String getTemplateName();
/**
* The model to be used to render this template.
* @return The model containing the attributes to be used for rendering.
*/
Object getTemplateModel();
}

View File

@@ -7,10 +7,19 @@ import net.dv8tion.jda.api.entities.MessageEmbed;
import java.util.List;
/**
* A full message which is ready to be send. This message can contain an arbitrary amount of embeds and a string message.
*/
@Getter
@Setter
@Builder
public class MessageToSend {
/**
* The collections of embeds to be send. The first embed is in the same message as the string message.
*/
private List<MessageEmbed> embeds;
/**
* The string content to be used in the first message.
*/
private String message;
}

View File

@@ -10,6 +10,9 @@ import javax.persistence.*;
import java.time.Instant;
import java.util.Objects;
/**
* Represents the template stored in the database.
*/
@Builder
@Entity
@NoArgsConstructor
@@ -19,10 +22,16 @@ import java.util.Objects;
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Template {
/**
* The globally unique key of the template
*/
@Id
@Getter
private String key;
/**
* The content of the template
*/
@Getter
@Column(length = 4000)
private String content;

View File

@@ -4,8 +4,32 @@ import dev.sheldan.abstracto.templating.model.MessageToSend;
import java.util.HashMap;
/**
* Provides methods to render templates with the appropriate model.
*/
public interface TemplateService {
/**
* The template containing a embed definition which should be rendered. The key must refer to an existing template and the supplied model will be used when rendering.
* This creates a {@link MessageToSend} object containing the rendered template and might result in multiple embeds.
* @param key The key of the embed template to be used for rendering.
* @param model The model providing the properties to be used for rendering
* @return A fully rendered message containing the content of the template and might contain multiple embeds.
*/
MessageToSend renderEmbedTemplate(String key, Object model);
/**
* Renders the template identified by the key with the given {@link HashMap} used as model and returns the value as a string
* @param key The key of the template to be rendered.
* @param parameters The {@link HashMap} to be used as the parameters for the template
* @return The template rendered as string.
*/
String renderTemplateWithMap(String key, HashMap<String, Object> parameters);
/**
* Renders the template identified by the key with the given model and returns the value as a string
* @param key The key of the template to be rendered
* @param model The object containing the model to be used in the template
* @return The template rendered as string.
*/
String renderTemplate(String key, Object model);
}

View File

@@ -2,8 +2,29 @@ package dev.sheldan.abstracto.templating.service.management;
import dev.sheldan.abstracto.templating.model.database.Template;
/**
* Provides methods to access the stored templates.
*/
public interface TemplateManagementService {
/**
* Retrieves the template identified by the key.
* @param key They template key to search for
* @return The {@link Template} identified by the key, if it exists.
*/
Template getTemplateByKey(String key);
/**
* Checks whether or not the template exists in the database.
* @param key They key of the template to search for
* @return true, if the template exists and false otherwise
*/
boolean templateExists(String key);
/**
* Creates a template identified by the key and with the provided content.
* @param key They key of the template to create.
* @param content The content the template should have
* @return The created template in the database.
*/
Template createTemplate(String key, String content);
}