Search in sources :

Example 1 with HTMLTemplate

use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.

the class TemplateManager method process.

public String process(String templatePath, Object model, String language) {
    StopWatch watch = new StopWatch();
    try {
        HTMLTemplate template = get(templatePath, model.getClass(), language);
        TemplateContext context = new TemplateContext(model, cdnManager);
        return template.process(context);
    } finally {
        logger.debug("process, templatePath={}, elapsedTime={}", templatePath, watch.elapsedTime());
    }
}
Also used : HTMLTemplate(core.framework.impl.template.HTMLTemplate) TemplateContext(core.framework.impl.template.TemplateContext) StopWatch(core.framework.util.StopWatch)

Example 2 with HTMLTemplate

use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.

the class HTMLTemplateEngine method process.

public String process(String name, Object model) {
    StopWatch watch = new StopWatch();
    try {
        HTMLTemplate template = templates.get(name);
        if (template == null)
            throw Exceptions.error("template not found, name={}", name);
        TemplateContext context = new TemplateContext(model, cdnManager);
        return template.process(context);
    } finally {
        logger.debug("process, name={}, elapsedTime={}", name, watch.elapsedTime());
    }
}
Also used : HTMLTemplate(core.framework.impl.template.HTMLTemplate) TemplateContext(core.framework.impl.template.TemplateContext) StopWatch(core.framework.util.StopWatch)

Example 3 with HTMLTemplate

use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.

the class HTMLTemplateEngine method add.

private void add(TemplateSource source, Class<?> modelClass) {
    StopWatch watch = new StopWatch();
    String name = source.name();
    try {
        HTMLTemplate previous = templates.putIfAbsent(name, new HTMLTemplateBuilder(source, modelClass).build());
        if (previous != null)
            throw Exceptions.error("template is already added, name={}", name);
    } finally {
        logger.info("add, name={}, modelClass={}, elapsedTime={}", name, modelClass.getCanonicalName(), watch.elapsedTime());
    }
}
Also used : HTMLTemplateBuilder(core.framework.impl.template.HTMLTemplateBuilder) HTMLTemplate(core.framework.impl.template.HTMLTemplate) StopWatch(core.framework.util.StopWatch)

Example 4 with HTMLTemplate

use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.

the class TemplateManager method load.

private Map<String, HTMLTemplate> load(String templatePath, Class<?> modelClass) {
    HTMLTemplateBuilder builder = new HTMLTemplateBuilder(new FileTemplateSource(webDirectory.root(), templatePath), modelClass);
    builder.cdn = cdnManager;
    Map<String, HTMLTemplate> templates = Maps.newHashMap();
    for (String language : message.languages) {
        builder.message = key -> message.get(key, language);
        HTMLTemplate htmlTemplate = builder.build();
        templates.put(language, htmlTemplate);
    }
    return templates;
}
Also used : FileTemplateSource(core.framework.impl.template.source.FileTemplateSource) HTMLTemplateBuilder(core.framework.impl.template.HTMLTemplateBuilder) HTMLTemplate(core.framework.impl.template.HTMLTemplate)

Example 5 with HTMLTemplate

use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.

the class TemplateManager method add.

public void add(String templatePath, Class<?> modelClass) {
    StopWatch watch = new StopWatch();
    try {
        Map<String, HTMLTemplate> previous = templates.putIfAbsent(templatePath, load(templatePath, modelClass));
        if (previous != null)
            throw Exceptions.error("template was registered, templatePath={}", templatePath);
        if (webDirectory.localEnv) {
            Path path = webDirectory.path(templatePath);
            templateLastModifiedTimes.put(templatePath, Files.lastModified(path));
        }
    } finally {
        logger.info("add, templatePath={}, modelClass={}, elapsedTime={}", templatePath, modelClass.getCanonicalName(), watch.elapsedTime());
    }
}
Also used : Path(java.nio.file.Path) HTMLTemplate(core.framework.impl.template.HTMLTemplate) StopWatch(core.framework.util.StopWatch)

Aggregations

HTMLTemplate (core.framework.impl.template.HTMLTemplate)6 StopWatch (core.framework.util.StopWatch)4 HTMLTemplateBuilder (core.framework.impl.template.HTMLTemplateBuilder)2 TemplateContext (core.framework.impl.template.TemplateContext)2 Path (java.nio.file.Path)2 FileTemplateSource (core.framework.impl.template.source.FileTemplateSource)1