| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package com.google.gitiles; |
| 16 | |
| Dave Borowitz | 987988a | 2014-03-19 09:29:13 -0700 | [diff] [blame] | 17 | import com.google.common.collect.ImmutableList; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableMap; |
| 19 | import com.google.common.io.Resources; |
| 20 | import com.google.template.soy.SoyFileSet; |
| 21 | import com.google.template.soy.tofu.SoyTofu; |
| Dave Borowitz | ca557f7 | 2016-10-04 09:46:24 -0400 | [diff] [blame] | 22 | |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 23 | import java.net.URL; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | /** Renderer that precompiles Soy and uses static precompiled CSS. */ |
| 27 | public class DefaultRenderer extends Renderer { |
| 28 | private final SoyTofu tofu; |
| 29 | |
| 30 | DefaultRenderer() { |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 31 | this("", ImmutableList.<URL>of(), ""); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| Dave Borowitz | 76bbefd | 2014-03-11 16:57:45 -0700 | [diff] [blame] | 34 | public DefaultRenderer(String staticPrefix, Iterable<URL> customTemplates, String siteTitle) { |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 35 | this(ImmutableMap.<String, String>of(), staticPrefix, customTemplates, siteTitle); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 38 | public DefaultRenderer( |
| 39 | Map<String, String> globals, |
| 40 | String staticPrefix, |
| 41 | Iterable<URL> customTemplates, |
| 42 | String siteTitle) { |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 43 | super( |
| Dave Borowitz | ca557f7 | 2016-10-04 09:46:24 -0400 | [diff] [blame] | 44 | r -> Resources.getResource(Renderer.class, "templates/" + r), |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 45 | globals, |
| 46 | staticPrefix, |
| 47 | customTemplates, |
| 48 | siteTitle); |
| 49 | SoyFileSet.Builder builder = SoyFileSet.builder().setCompileTimeGlobals(this.globals); |
| Shawn Pearce | a9b99a1 | 2015-02-10 15:35:11 -0800 | [diff] [blame] | 50 | for (URL template : templates.values()) { |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 51 | builder.add(template); |
| 52 | } |
| 53 | tofu = builder.build().compileToTofu(); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | protected SoyTofu getTofu() { |
| 58 | return tofu; |
| 59 | } |
| 60 | } |