org.nasdanika.html.HTMLFactory Maven / Gradle / Ivy
package org.nasdanika.html;
import java.util.Map;
import org.nasdanika.html.impl.DefaultHTMLFactory;
/**
* Implementations of this class abstract HTML rendering code from rendering of low-level HTML primitives.
* @author Pavel
*
*/
public interface HTMLFactory {
HTMLFactory INSTANCE = new DefaultHTMLFactory();
/**
* Generates element ID.
* @return
*/
String nextId();
/*******************
* Simple API's *
*******************/
/**
* Creates a tag with a given name which attributes and styles can be manipulated
* with UIElement methods.
* @param tagName
* @param content
* @return
*/
Tag tag(String tagName, Object... content);
Tag tag(TagName tagName, Object... content);
/**
* Creates a tag which is rendered only if it has content.
* @param tagName
* @param content
* @return
*/
Tag nonEmptyTag(String tagName, Object... content);
/**
* Creates a tag which is rendered only if it has content.
* @param tagName
* @param content
* @return
*/
Tag nonEmptyTag(TagName tagName, Object... content);
Tag div(Object... content);
/**
* Creates a div which is rendered only if it has content.
* @param content
* @return
*/
Tag nonEmptyDiv(Object... content);
Tag span(Object... content);
Fragment fragment(Object... content);
/**
* A convenience method for creating form inputs
* @param type Input type
* @param name Input name - optional
* @param value Input value - optional
* @param id Control id - optional
* @param placeholder Placeholder - optional
* @return
*/
Input input(InputType type);
Select select();
TextArea textArea();
Tag link(Object href, Object... content);
Tag ul(Iterable> items);
Tag ol(Iterable> items);
Table table();
Button button(Object... content);
Form form();
/**
* Generates document.title = title script.
* @param title
* @return
*/
Tag title(Object title);
// --- JavaScript ---
Function function(Object... param);
/**
* Creates an overlay div with vertically and horizontally centered content.
* @param content
* @return
*/
Tag overlay(Object... content);
/**
* Generates JavaScript code (without script tag) to size the overlay and then display it.
* @param overlaySelector
* @param overlayedSelector
*/
String showOverlay(String overlaySelector, String overlayedSelector, int widthAdjustment, int heightAdjustment);
/**
* Expands tokens in the form of {{token name}}
to their values.
* If a token is not found expansion is not processed.
* @param input String, Reader, InputStream or URL.
* @param tokenSource Source of tokens.
* @return
*/
String interpolate(Object input, java.util.function.Function tokenSource);
/**
* Expands tokens in the form of {{token name}}
to their values.
* If a token is not found expansion is not processed.
* @param input String, Reader, InputStream or URL.
* @param env
* @return
*/
String interpolate(Object input, final Map env);
/**
* Expands a single token in the form of {{token name}}
to its value.
* If a token is not found expansion is not processed.
* @param input String, Reader, InputStream or URL.
* @param token
* @param value
* @return
*/
String interpolate(Object input, String token, Object value);
/**
* Creates a named items container which wraps name in the specified tag, e.g. H2.
* @param tagName
* @return
*/
NamedItemsContainer tagNamedItemsContainer(TagName tagName);
/**
* Creates HTML page.
* @return
*/
HTMLPage page();
/**
* Creates a mutable token source with initial token.
* @param token
* @param value
* @return
*/
TokenSource tokenSource(String token, Object value);
/**
* Creates a new mutable token source.
* @return
*/
TokenSource tokenSource();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy