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