blob: 297350e2732d7e7868704e655c24a5e74b415126 [file] [log] [blame]
Dave Borowitz9de65952012-08-13 16:09:45 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.gitiles;
16
Dave Borowitz987988a2014-03-19 09:29:13 -070017import com.google.common.collect.ImmutableList;
Dave Borowitz9de65952012-08-13 16:09:45 -070018import com.google.common.collect.ImmutableMap;
19import com.google.common.io.Resources;
20import com.google.template.soy.SoyFileSet;
21import com.google.template.soy.tofu.SoyTofu;
Dave Borowitz9de65952012-08-13 16:09:45 -070022import java.net.URL;
23import java.util.Map;
24
25/** Renderer that precompiles Soy and uses static precompiled CSS. */
26public class DefaultRenderer extends Renderer {
27 private final SoyTofu tofu;
28
29 DefaultRenderer() {
Han-Wen Nienhuysc0200f62016-05-02 17:34:51 +020030 this("", ImmutableList.<URL>of(), "");
Dave Borowitz9de65952012-08-13 16:09:45 -070031 }
32
Dave Borowitz76bbefd2014-03-11 16:57:45 -070033 public DefaultRenderer(String staticPrefix, Iterable<URL> customTemplates, String siteTitle) {
Han-Wen Nienhuysc0200f62016-05-02 17:34:51 +020034 this(ImmutableMap.<String, String>of(), staticPrefix, customTemplates, siteTitle);
Dave Borowitz9de65952012-08-13 16:09:45 -070035 }
36
Han-Wen Nienhuysc0200f62016-05-02 17:34:51 +020037 public DefaultRenderer(
38 Map<String, String> globals,
39 String staticPrefix,
40 Iterable<URL> customTemplates,
41 String siteTitle) {
Dave Borowitz9de65952012-08-13 16:09:45 -070042 super(
Dave Borowitzca557f72016-10-04 09:46:24 -040043 r -> Resources.getResource(Renderer.class, "templates/" + r),
Han-Wen Nienhuysc0200f62016-05-02 17:34:51 +020044 globals,
45 staticPrefix,
46 customTemplates,
47 siteTitle);
48 SoyFileSet.Builder builder = SoyFileSet.builder().setCompileTimeGlobals(this.globals);
Shawn Pearcea9b99a12015-02-10 15:35:11 -080049 for (URL template : templates.values()) {
Dave Borowitz9de65952012-08-13 16:09:45 -070050 builder.add(template);
51 }
52 tofu = builder.build().compileToTofu();
53 }
54
55 @Override
56 protected SoyTofu getTofu() {
57 return tofu;
58 }
59}