org.libreoffice.ci.gerrit.buildbot.servlets.DefaultRenderer.java Source code

Java tutorial

Introduction

Here is the source code for org.libreoffice.ci.gerrit.buildbot.servlets.DefaultRenderer.java

Source

// Copyright 2012 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.libreoffice.ci.gerrit.buildbot.servlets;

import java.net.URL;
import java.util.Map;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import com.google.template.soy.SoyFileSet;
import com.google.template.soy.tofu.SoyTofu;

/** Renderer that precompiles Soy and uses static precompiled CSS. */
public class DefaultRenderer extends Renderer {
    private final SoyTofu tofu;

    DefaultRenderer() {
        this(null, "");
    }

    public DefaultRenderer(URL customTemplates, String siteTitle) {
        this(ImmutableMap.<String, String>of(), customTemplates, siteTitle);
    }

    public DefaultRenderer(Map<String, String> globals, URL customTemplates, String siteTitle) {
        super(new Function<String, URL>() {
            @Override
            public URL apply(String name) {
                return Resources.getResource(Renderer.class, "templates/" + name);
            }
        }, globals, customTemplates, siteTitle);
        SoyFileSet.Builder builder = new SoyFileSet.Builder().setCompileTimeGlobals(this.globals);
        for (URL template : templates) {
            builder.add(template);
        }
        tofu = builder.build().compileToTofu();
    }

    @Override
    protected SoyTofu getTofu() {
        return tofu;
    }
}