Merge "Improve styling/branding options"
diff --git a/gitiles-servlet/src/main/java/com/google/gitiles/BaseServlet.java b/gitiles-servlet/src/main/java/com/google/gitiles/BaseServlet.java
index 2c94a27..a7bf02a 100644
--- a/gitiles-servlet/src/main/java/com/google/gitiles/BaseServlet.java
+++ b/gitiles-servlet/src/main/java/com/google/gitiles/BaseServlet.java
@@ -239,7 +239,10 @@
 
     Map<String, Object> allData = getData(req);
 
-    GitilesConfig.putVariant(getAccess(req).getConfig(), "customHeader", "headerVariant", allData);
+    // for backwards compatibility, first try to access the old customHeader config var,
+    // then read the new customVariant variable.
+    GitilesConfig.putVariant(getAccess(req).getConfig(), "customHeader", "customVariant", allData);
+    GitilesConfig.putVariant(getAccess(req).getConfig(), "customVariant", "customVariant", allData);
     allData.putAll(soyData);
     GitilesView view = ViewFilter.getView(req);
     if (!allData.containsKey("repositoryName") && view.getRepositoryName() != null) {
diff --git a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/BlameDetail.soy b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/BlameDetail.soy
index f5110d8..909ee0f 100644
--- a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/BlameDetail.soy
+++ b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/BlameDetail.soy
@@ -19,7 +19,7 @@
  * @param title human-readable revision name.
  * @param repositoryName name of this repository.
  * @param? menuEntries menu entries.
- * @param? headerVariant variant name for custom header.
+ * @param? customVariant variant name for custom styling.
  * @param breadcrumbs breadcrumbs for this page.
  * @param data blob data, matching the params for .blobBox.
  * @param? regions for non-binary files, list of regions, one per line, with the
@@ -82,5 +82,7 @@
   </div>
 {/if}
 
-{call .footer /}
+{call .footer}
+  {param customVariant: $customVariant /}
+{/call}
 {/template}
diff --git a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/Common.soy b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/Common.soy
index 2a7ba40..9ca25d3 100644
--- a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/Common.soy
+++ b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/Common.soy
@@ -21,7 +21,7 @@
  * @param? repositoryName repository name for this page, if applicable.
  * @param? menuEntries optional list of menu entries with "text" and optional
  *     "url" keys.
- * @param? headerVariant variant name for custom header.
+ * @param? customVariant variant name for custom styling.
  * @param breadcrumbs navigation breadcrumbs for this page.
  * @param? css optional list of CSS URLs to include.
  * @param? containerClass optional class to append to the main container.
@@ -45,11 +45,13 @@
       <link rel="stylesheet" type="text/css" href="{$url}">
     {/foreach}
   {/if}
+  {delcall gitiles.customHeadTagPart variant="$customVariant ?: ''" /}
+
 </head>
 <body class="Site">
   <header class="Site-header">
     <div class="Header">
-      {delcall gitiles.customHeader variant="$headerVariant ?: 'default'" /}
+      {delcall gitiles.customHeader variant="$customVariant ?: ''" /}
 
       {if $menuEntries and length($menuEntries)}
         <div class="Header-menu">
@@ -84,32 +86,74 @@
 {/template}
 
 /**
+ * Default (empty) custom head tag part
+ *
+ * This can be used to include per-project CSS/JS by
+ * providing custom variants.
+ */
+{deltemplate gitiles.customHeadTagPart}
+  <!-- default customHeadTagPart -->
+{/deltemplate}
+
+/**
  * Default custom header implementation for Gitiles.
  */
-{deltemplate gitiles.customHeader variant="'default'"}
+{deltemplate gitiles.customHeader}
+<!-- default customHeader -->
 <div class="Header-title">
   {msg desc="short name of the application"}{gitiles.SITE_TITLE}{/msg}
 </div>
 {/deltemplate}
 
 /**
- * Standard footer.
+ * Footer 'powered by' element
+ *
+ * Please call this in custom variants as well.
+ */
+{template .footerPoweredBy}
+<span class="Footer-poweredBy">
+  Powered by <a href="https://code.google.com/p/gitiles/">Gitiles</a>
+</span>
+{/template}
+
+/**
+ * Footer format badge
+ *
+ * You can use this in custom footers as well.
+ */
+{template .footerFormatBadge}
+<span class="Footer-formats">
+  <a class="u-monospace Footer-formatsItem" href="?format=TEXT">{msg desc="text format"}txt{/msg}</a>
+    {sp}
+  <a class="u-monospace Footer-formatsItem" href="?format=JSON">{msg desc="JSON format"}json{/msg}</a>
+</span>
+{/template}
+
+/**
+ * Default Footer
+ */
+{deltemplate gitiles.customFooter}
+<!-- default customFooter -->
+<footer class="Site-footer">
+  <div class="Footer">
+   {call gitiles.footerPoweredBy /}
+   {call gitiles.footerFormatBadge /}
+  </div>
+</footer>
+{/deltemplate}
+
+/**
+ * Main footer.
+ *
+ * The footer tag part can be customized by creating a customFooter
+ * variant template.
+ *
+ * @param? customVariant variant name for custom styling.
  */
 {template .footer}
     </div> <!-- Container -->
   </div> <!-- Site-content -->
-  <footer class="Site-footer">
-    <div class="Footer">
-      <span class="Footer-poweredBy">
-        Powered by <a href="https://code.google.com/p/gitiles/">Gitiles</a>
-      </span>
-      <span class="Footer-formats">
-        <a class="u-monospace Footer-formatsItem" href="?format=TEXT">{msg desc="text format"}txt{/msg}</a>
-        {sp}
-        <a class="u-monospace Footer-formatsItem" href="?format=JSON">{msg desc="JSON format"}json{/msg}</a>
-      </span>
-    </div>
-  </footer>
+  {delcall gitiles.customFooter variant="$customVariant ?: ''" /}
 </body>
 </html>
 {/template}
diff --git a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/DiffDetail.soy b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/DiffDetail.soy
index d800d2e..252ab7b 100644
--- a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/DiffDetail.soy
+++ b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/DiffDetail.soy
@@ -19,7 +19,7 @@
  * @param title human-readable revision name.
  * @param repositoryName name of this repository.
  * @param? menuEntries menu entries.
- * @param? headerVariant variant name for custom header.
+ * @param? customVariant variant name for custom styling.
  * @param breadcrumbs breadcrumbs for this page.
  * @param? commit optional commit for which diffs are displayed, with keys
  *     corresponding to the gitiles.commitDetail template (minus "diffTree").
@@ -32,7 +32,9 @@
 {/if}
 {call .streamingPlaceholder /}
 
-{call .footer /}
+{call .footer}
+  {param customVariant: $customVariant /}
+{/call}
 {/template}
 
 /**
diff --git a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/HostIndex.soy b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/HostIndex.soy
index 7ac3581..ab3b18c 100644
--- a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/HostIndex.soy
+++ b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/HostIndex.soy
@@ -18,7 +18,7 @@
  *
  * @param hostName host name.
  * @param? menuEntries menu entries.
- * @param? headerVariant variant name for custom header.
+ * @param? customVariant variant name for custom styling.
  * @param? prefix prefix path for matching repositories.
  * @param? breadcrumbs map of breadcrumbs for header.
  * @param repositories list of repository description maps with name, cloneUrl,
@@ -29,7 +29,7 @@
   {param title: $prefix ? $prefix : $hostName ? $hostName + ' Git repositories' : 'Git repositories' /}
   {param menuEntries: $menuEntries /}
   {param breadcrumbs: $breadcrumbs /}
-  {param headerVariant: $headerVariant /}
+  {param customVariant: $customVariant /}
 {/call}
 
 {if length($repositories)}
@@ -62,5 +62,8 @@
     {/foreach}
   </div>
 {/if}
-{call .footer /}
+
+{call .footer}
+  {param customVariant: $customVariant /}
+{/call}
 {/template}
diff --git a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/LogDetail.soy b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/LogDetail.soy
index ba2c24d..be7c9b3 100644
--- a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/LogDetail.soy
+++ b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/LogDetail.soy
@@ -19,7 +19,7 @@
  * @param title human-readable revision name.
  * @param repositoryName name of this repository.
  * @param? menuEntries menu entries.
- * @param? headerVariant variant name for custom header.
+ * @param? customVariant variant name for custom styling.
  * @param breadcrumbs breadcrumbs for this page.
  * @param? tags optional list of tags encountered when peeling this object, with
  *     keys corresponding to gitiles.tagDetail.
@@ -35,7 +35,9 @@
 
 {call .streamingPlaceholder /}
 
-{call .footer /}
+{call .footer}
+  {param customVariant: $customVariant /}
+{/call}
 {/template}
 
 
diff --git a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/PathDetail.soy b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/PathDetail.soy
index e2349d2..c4c5d5f 100644
--- a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/PathDetail.soy
+++ b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/PathDetail.soy
@@ -19,7 +19,7 @@
  * @param title human-readable name of this path.
  * @param repositoryName name of this repository.
  * @param? menuEntries menu entries.
- * @param? headerVariant variant name for custom header.
+ * @param? customVariant variant name for custom styling.
  * @param breadcrumbs breadcrumbs for this page.
  * @param type path type, matching one of the constant names defined in
  *         org.eclipse.jgit.lib.FileMode.
@@ -51,7 +51,9 @@
     </div>
 {/switch}
 
-{call .footer /}
+{call .footer}
+  {param customVariant: $customVariant /}
+{/call}
 {/template}
 
 /**
diff --git a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RefList.soy b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RefList.soy
index 74f89d0..be9c94a 100644
--- a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RefList.soy
+++ b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RefList.soy
@@ -19,7 +19,7 @@
  *
  * @param repositoryName name of this repository.
  * @param? menuEntries menu entries.
- * @param? headerVariant variant name for custom header.
+ * @param? customVariant variant name for custom styling.
  * @param breadcrumbs breadcrumbs for this page.
  * @param branches list of branch objects with url, name, and isHead keys.
  * @param tags list of tag objects with url and name keys.
@@ -29,7 +29,7 @@
   {param title: 'Refs' /}
   {param repositoryName: $repositoryName /}
   {param menuEntries: $menuEntries /}
-  {param headerVariant: $headerVariant /}
+  {param customVariant: $customVariant /}
   {param breadcrumbs: $breadcrumbs /}
 {/call}
 
@@ -49,7 +49,9 @@
   {/if}
 </div>
 
-{call .footer /}
+{call .footer}
+  {param customVariant: $customVariant /}
+{/call}
 {/template}
 
 /**
diff --git a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RepositoryIndex.soy b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RepositoryIndex.soy
index ec6e67e..3ab7d5b 100644
--- a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RepositoryIndex.soy
+++ b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RepositoryIndex.soy
@@ -18,7 +18,7 @@
  *
  * @param repositoryName name of this repository.
  * @param? menuEntries menu entries.
- * @param? headerVariant variant name for custom header.
+ * @param? customVariant variant name for custom styling.
  * @param breadcrumbs breadcrumbs for this page.
  * @param cloneUrl clone URL for this repository.
  * @param description description text of the repository.
@@ -36,7 +36,7 @@
     {param title: $repositoryName /}
     {param repositoryName: null /}
     {param menuEntries: $menuEntries /}
-    {param headerVariant: $headerVariant /}
+    {param customVariant: $customVariant /}
     {param breadcrumbs: $breadcrumbs /}
     {param css: [gitiles.DOC_CSS_URL] /}
   {/call}
@@ -45,7 +45,7 @@
     {param title: $repositoryName /}
     {param repositoryName: null /}
     {param menuEntries: $menuEntries /}
-    {param headerVariant: $headerVariant /}
+    {param customVariant: $customVariant /}
     {param breadcrumbs: $breadcrumbs /}
   {/call}
 {/if}
@@ -90,7 +90,9 @@
   {call .tags_ data="all" /}
 {/if}
 
-{call .footer /}
+{call .footer}
+  {param customVariant: $customVariant /}
+{/call}
 {/template}
 
 /**
diff --git a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RevisionDetail.soy b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RevisionDetail.soy
index cfed23e..2bfabe0 100644
--- a/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RevisionDetail.soy
+++ b/gitiles-servlet/src/main/resources/com/google/gitiles/templates/RevisionDetail.soy
@@ -19,7 +19,7 @@
  * @param title human-readable revision name.
  * @param repositoryName name of this repository.
  * @param? menuEntries menu entries.
- * @param? headerVariant variant name for custom header.
+ * @param? customVariant variant name for styling.
  * @param breadcrumbs breadcrumbs for this page.
  * @param? hasBlob set to true if the revision or its peeled value is a blob.
  * @param? hasReadme set to true if the treeDetail has readmeHtml.
@@ -59,5 +59,7 @@
   {/switch}
 {/foreach}
 
-{call .footer /}
+{call .footer}
+  {param customVariant: $customVariant /}
+{/call}
 {/template}