Soy index cleanup
Some cleanup on the use of Soy index:
* The canonical-path property of GR-APP is removed because it did not
initialize at the right time and a top-level global is used instead.
* Only set a top-level global for canonical path if it is not the empty
string. In this way, the index document does not include an inline
script when it is not needed.
* Give the index Soy template a more descriptive name. index.html.soy
was too generic, and the intermediate period would cause problems with
some internal build tooling.
Bug: Issue 5919
Change-Id: I0bf5964b17cb4f4f9df150b0c6abe8ae1e49f22b
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/IndexServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/IndexServlet.java
index 3eb77ea..4ac3da7 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/IndexServlet.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/IndexServlet.java
@@ -37,7 +37,7 @@
private final byte[] indexSource;
IndexServlet(String canonicalURL, @Nullable String cdnPath) throws URISyntaxException {
- String resourcePath = "com/google/gerrit/httpd/raw/index.html.soy";
+ String resourcePath = "com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy";
SoyFileSet.Builder builder = SoyFileSet.builder();
builder.add(Resources.getResource(resourcePath));
SoyTofu.Renderer renderer =
diff --git a/gerrit-httpd/src/main/resources/com/google/gerrit/httpd/raw/index.html.soy b/gerrit-httpd/src/main/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy
similarity index 92%
rename from gerrit-httpd/src/main/resources/com/google/gerrit/httpd/raw/index.html.soy
rename to gerrit-httpd/src/main/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy
index 4d8c43b..32f91f1 100644
--- a/gerrit-httpd/src/main/resources/com/google/gerrit/httpd/raw/index.html.soy
+++ b/gerrit-httpd/src/main/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy
@@ -27,7 +27,9 @@
<meta name="description" content="Gerrit Code Review">{\n}
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">{\n}
- <script>window.CANONICAL_PATH = '{$canonicalPath}';</script>{\n}
+ {if $canonicalPath != ''}
+ <script>window.CANONICAL_PATH = '{$canonicalPath}';</script>{\n}
+ {/if}
// SourceCodePro fonts are used in styles/fonts.css
// @see https://github.com/w3c/preload/issues/32 regarding crossorigin
@@ -40,5 +42,5 @@
<link rel="import" href="{$staticResourcePath}/elements/gr-app.html">{\n}
<body unresolved>{\n}
- <gr-app id="app" canonical-path="{$canonicalPath}"></gr-app>{\n}
+ <gr-app id="app"></gr-app>{\n}
{/template}
diff --git a/polygerrit-ui/app/elements/gr-app.js b/polygerrit-ui/app/elements/gr-app.js
index acf38c7..90f641d 100644
--- a/polygerrit-ui/app/elements/gr-app.js
+++ b/polygerrit-ui/app/elements/gr-app.js
@@ -37,12 +37,6 @@
value: function() { return document.body; },
},
- /**
- * The path component of the canonicalWebURL. If Gerrit is running from
- * the root of the domain, this should be empty.
- */
- canonicalPath: String,
-
_account: {
type: Object,
observer: '_accountChanged',
@@ -80,8 +74,6 @@
},
ready: function() {
- Gerrit.CANONICAL_PATH = this.canonicalPath;
-
this.$.router.start();
this.$.restAPI.getAccount().then(function(account) {
diff --git a/polygerrit-ui/app/elements/gr-app_test.html b/polygerrit-ui/app/elements/gr-app_test.html
index 2eb835d..7fcb03c 100644
--- a/polygerrit-ui/app/elements/gr-app_test.html
+++ b/polygerrit-ui/app/elements/gr-app_test.html
@@ -27,7 +27,7 @@
<test-fixture id="basic">
<template>
- <gr-app id="app" canonical-path="/abc/def/ghi"></gr-app>
+ <gr-app id="app"></gr-app>
</template>
</test-fixture>
@@ -107,9 +107,5 @@
done();
});
});
-
- test('canonical-path', function() {
- assert.equal(Gerrit.CANONICAL_PATH, '/abc/def/ghi');
- });
});
</script>