blob: e2eef7ced46c163ef9400f6d80d7672bd0dbc976 [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
17import com.google.common.base.Function;
18import com.google.common.collect.ImmutableMap;
19import com.google.common.io.Resources;
20import com.google.template.soy.SoyFileSet;
21import com.google.template.soy.tofu.SoyTofu;
22
23import java.net.URL;
24import java.util.Map;
25
26/** Renderer that precompiles Soy and uses static precompiled CSS. */
27public class DefaultRenderer extends Renderer {
28 private final SoyTofu tofu;
29
30 DefaultRenderer() {
Chad Horohoe2a28d622012-11-12 11:56:59 -080031 this("", null, "");
Dave Borowitz9de65952012-08-13 16:09:45 -070032 }
33
Chad Horohoe2a28d622012-11-12 11:56:59 -080034 public DefaultRenderer(String staticPrefix, URL customTemplates, String siteTitle) {
35 this(ImmutableMap.<String, String> of(), staticPrefix, customTemplates, siteTitle);
Dave Borowitz9de65952012-08-13 16:09:45 -070036 }
37
Chad Horohoe2a28d622012-11-12 11:56:59 -080038 public DefaultRenderer(Map<String, String> globals, String staticPrefix, URL customTemplates,
39 String siteTitle) {
Dave Borowitz9de65952012-08-13 16:09:45 -070040 super(
41 new Function<String, URL>() {
42 @Override
43 public URL apply(String name) {
44 return Resources.getResource(Renderer.class, "templates/" + name);
45 }
46 },
Chad Horohoe2a28d622012-11-12 11:56:59 -080047 globals, staticPrefix, customTemplates, siteTitle);
Dave Borowitz9de65952012-08-13 16:09:45 -070048 SoyFileSet.Builder builder = new SoyFileSet.Builder()
49 .setCompileTimeGlobals(this.globals);
50 for (URL template : templates) {
51 builder.add(template);
52 }
53 tofu = builder.build().compileToTofu();
54 }
55
56 @Override
57 protected SoyTofu getTofu() {
58 return tofu;
59 }
60}