blob: 5c3a448ef576516bb2265c4cc2fd11d54699b71a [file] [log] [blame]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08001= Gerrit Code Review - Themes
Shawn O. Pearced2b73db2009-01-09 11:55:47 -08002
Shawn O. Pearcee31d02c2009-12-08 12:21:37 -08003Gerrit supports some customization of the HTML it sends to
Shawn O. Pearced2b73db2009-01-09 11:55:47 -08004the browser, allowing organizations to alter the look and
5feel of the application to fit with their general scheme.
6
Dave Borowitz1e49e142013-04-09 12:14:57 -07007Configuration can either be sitewide or per-project. Projects without a
8specified theme inherit from their parents, or from the sitewide theme
9for `All-Projects`.
10
11Sitewide themes are stored in `'$site_path'/etc`, and per-project
12themes are stored in `'$site_path'/themes/{project-name}`. Files are
13only served from a single theme directory; if you want to modify or
14extend an inherited theme, you must copy it into the appropriate
15per-project directory.
16
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080017== HTML Header/Footer
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080018
19At startup Gerrit reads the following files (if they exist) and
20uses them to customize the HTML page it sends to clients:
21
Dave Borowitz1e49e142013-04-09 12:14:57 -070022* `<theme-dir>/GerritSiteHeader.html`
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080023+
24HTML is inserted below the menu bar, but above any page content.
25This is a good location for an organizational logo, or links to
26other systems like bug tracking.
27
Dave Borowitz1e49e142013-04-09 12:14:57 -070028* `<theme-dir>/GerritSiteFooter.html`
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080029+
Shawn O. Pearce03273c92009-01-13 10:32:50 -080030HTML is inserted at the bottom of the page, below all other content,
31but just above the footer rule and the "Powered by Gerrit Code
32Review (v....)" message shown at the extreme bottom.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080033
Dave Borowitz1e49e142013-04-09 12:14:57 -070034* `<theme-dir>/GerritSite.css`
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080035+
36The CSS rules are inlined into the top of the HTML page, inside
37of a `<style>` tag. These rules can be used to support styling
38the elements within either the header or the footer.
39
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080040The *.html files must be valid XHTML, with one root element,
41typically a single `<div>` tag. The server parses it as XML, and
42then inserts the root element into the host page. If a file has
43more than one root level element, Gerrit will not start.
44
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080045== Static Images
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080046
Shawn O. Pearce1261bef2009-05-08 18:31:51 -070047Static image files can also be served from `'$site_path'/static`,
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080048and may be referenced in `GerritSite{Header,Footer}.html`
49or `GerritSite.css` by the relative URL `static/$name`
50(e.g. `static/logo.png`).
51
David Pursehouse221d4f62012-06-08 17:38:08 +090052To simplify security management, files are only served from
Shawn O. Pearce1261bef2009-05-08 18:31:51 -070053`'$site_path'/static`. Subdirectories are explicitly forbidden from
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080054being served from this location by enforcing the rule that file names
55cannot contain `/` or `\`. (Client requests for `static/foo/bar`
56will result in 404 Not Found responses.)
57
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080058== HTTP Caching
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080059
Shawn O. Pearce0e2604c2009-05-08 09:46:33 -070060The header, footer, and CSS files are inlined into the host page,
61which is always sent with a no-cache header. Clients will see any
Shawn O. Pearce1fdd6bf2010-01-08 19:28:12 -080062changes immediately after they are made.
Shawn O. Pearce0e2604c2009-05-08 09:46:33 -070063
Shawn O. Pearce1261bef2009-05-08 18:31:51 -070064Assets under `'$site_path'/static` whose file name matches one of the
Shawn O. Pearce0e2604c2009-05-08 09:46:33 -070065following patterns are served with a 1 year expiration, permitting
66very aggressive caching by clients and edge-proxies:
67
68 * `*.cache.html`
69 * `*.cache.gif`
70 * `*.cache.png`
71 * `*.cache.css`
72 * `*.cache.jar`
73 * `*.cache.swf`
74
Shawn O. Pearce1261bef2009-05-08 18:31:51 -070075All other assets under `'$site_path'/static` are served with a 5
Shawn O. Pearce0e2604c2009-05-08 09:46:33 -070076minute expire, permitting some (limited) caching. It may take up
Shawn O. Pearce1fdd6bf2010-01-08 19:28:12 -080077to 5 minutes after making a change, before clients see the changes.
Shawn O. Pearce0e2604c2009-05-08 09:46:33 -070078
79It is recommended that static images used in the site header
80or footer be named with a unique caching file name, for example
81`my_logo1.cache.png`, to allow browsers to take advantage of their
82disk cache. If the image needs to be modified, create a new file,
83`my_logo2.cache.png` and update the header (or footer) HTML to
84reference the new image path.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080085
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080086== Google Analytics Integration
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080087
88To connect Gerrit to Google Analytics add the following to your
89`GerritSiteFooter.html`:
90
91====
92 <div>
93 <!-- standard analytics code -->
94 <script type="text/javascript">
95 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
96 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
97 </script>
98 <script type="text/javascript">
99 var pageTracker = _gat._getTracker("UA-nnnnnnn-n");
100 pageTracker._trackPageview();
101 </script>
Shawn Pearcea48826e2013-11-29 20:38:55 -0800102 be <!-- /standard analytics code -->
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800103
104 <script type="text/javascript">
105 window.onload = function() {
Shawn Pearcea48826e2013-11-29 20:38:55 -0800106 var p = window.location.pathname;
107 Gerrit.on('history', function (s) {
108 pageTracker._trackPageview(p + '/' + s)
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800109 });
110 };
111 </script>
112 </div>
113====
114
115Please consult the Google Analytics documentation for the correct
116setup code (the first two script tags). The above is shown only
117as a reference example.
118
Shawn O. Pearce4335c302009-05-08 09:54:45 -0700119If your footer is otherwise empty, wrap all of the script tags into
120a single `<div>` tag (like above) to ensure it is a well-formed
121XHTML document file.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800122
Shawn Pearcea48826e2013-11-29 20:38:55 -0800123The global function `Gerrit.on("history")` accepts functions that
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800124accept a string parameter. These functions are put into a list and
125invoked any time Gerrit shifts URLs. You'll see page names like
Shawn Pearcea48826e2013-11-29 20:38:55 -0800126`/c/123` be passed to these functions, which in turn are handed off
127to Google Analytics for tracking. Our example hook above uses '/'
128instead of '#' because Analytics won't track anchors.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800129
130The `window.onload` callback is necessary to ensure that the
Shawn Pearcea48826e2013-11-29 20:38:55 -0800131`Gerrit.on()` function has actually been defined by the
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800132page. Because GWT loads the module asynchronously any `<script>`
133block in the header or footer will execute before Gerrit has defined
134the function and is ready to register the hook callback.
135
Shawn Pearcea48826e2013-11-29 20:38:55 -0800136The function `gerrit_addHistoryHook` is deprecated and may be
137removed in a future release.
138
Shawn O. Pearce5500e692009-05-28 15:55:01 -0700139GERRIT
140------
141Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700142
143SEARCHBOX
144---------