Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.tagliatelle;
import parsii.tokenizer.ParseError;
import parsii.tokenizer.Position;
import sirius.kernel.Sirius;
import sirius.kernel.cache.Cache;
import sirius.kernel.cache.CacheEntry;
import sirius.kernel.cache.CacheManager;
import sirius.kernel.commons.MultiMap;
import sirius.kernel.commons.Strings;
import sirius.kernel.commons.Tuple;
import sirius.kernel.commons.Value;
import sirius.kernel.di.std.Part;
import sirius.kernel.di.std.Parts;
import sirius.kernel.di.std.Register;
import sirius.kernel.health.Log;
import sirius.tagliatelle.compiler.CompilationContext;
import sirius.tagliatelle.compiler.CompileError;
import sirius.tagliatelle.compiler.CompileException;
import sirius.tagliatelle.compiler.Compiler;
import sirius.tagliatelle.rendering.GlobalRenderContext;
import sirius.web.resources.Resource;
import sirius.web.resources.Resources;
import sirius.web.templates.Templates;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Provides statically compiled and optimized templates to generate HTML, XML and text files.
*
* Helps to resolve and compile templates and also to generate a context used to render their output.
*/
@Register(classes = Tagliatelle.class)
public class Tagliatelle {
/**
* Logs everything related to resolving, compiling and rendering tagliatelle templates.
*/
public static final Log LOG = Log.get("tagliatelle");
protected static final String PRAGMA_ALIAS = "alias";
/**
* Contains all aliases collected via {@link ClassAliasProvider alias providers}.
*/
private Map> aliases;
@Parts(ClassAliasProvider.class)
private Collection aliasProviders;
@Part
private Resources resources;
@Part
private Templates templates;
/**
* Keeps compiled templates around to improve the speed of rendering.
*/
private Cache compiledTemplates = CacheManager.createLocalCache("tagliatelle-templates");
private List>> globalVariables;
private MultiMap taglibTags;
/**
* Returns all taglibs and all tags within this taglib.
*
* @return a multimap containing all taglibs (prefix) and their tags
*/
public MultiMap getTagLibTags() {
if (taglibTags == null) {
MultiMap result = MultiMap.createOrdered();
Sirius.getClasspath()
.find(Pattern.compile("(default/)?taglib/([a-z]+)/(.*).html.pasta"))
.forEach(m -> result.put(m.group(2), m.group(3)));
taglibTags = result;
}
return taglibTags;
}
/**
* Returns a list of all tag lib prefixes and descriptions.
*
* @return a list of tuples containing the taglib prefix and a short description
*/
public List> getTagLibs() {
return getTagLibTags().keySet()
.stream()
.map(name -> Tuple.create(name,
Sirius.getSettings()
.get("tagliatelle.taglib." + name)
.asString(name)))
.collect(Collectors.toList());
}
/**
* Determines if a taglib with the given prefix exists.
*
* @param prefix the prefix to check
* @return true if a taglib with the given prefix exists, false otherwise
*/
public boolean isTaglib(String prefix) {
return getTagLibTags().getUnderlyingMap().containsKey(prefix);
}
/**
* Provides all known class aliases.
*
* @return an unmodifyable map of all known aliases for Java classes.
*/
public Map> getClassAliases() {
if (aliases == null) {
Map> aliasMap = new HashMap<>();
aliasProviders.forEach(p -> p.collectAliases(aliasMap::put));
aliases = aliasMap;
}
return Collections.unmodifiableMap(aliases);
}
/**
* Creates a new list of global variables used to initialize a global render context.
*
* @return a new list of global variables
*/
public List