Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1 | = Gerrit Code Review - Themes |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 2 | |
Shawn O. Pearce | e31d02c | 2009-12-08 12:21:37 -0800 | [diff] [blame] | 3 | Gerrit supports some customization of the HTML it sends to |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 4 | the browser, allowing organizations to alter the look and |
| 5 | feel of the application to fit with their general scheme. |
| 6 | |
Dave Borowitz | 1e49e14 | 2013-04-09 12:14:57 -0700 | [diff] [blame] | 7 | Configuration can either be sitewide or per-project. Projects without a |
| 8 | specified theme inherit from their parents, or from the sitewide theme |
| 9 | for `All-Projects`. |
| 10 | |
| 11 | Sitewide themes are stored in `'$site_path'/etc`, and per-project |
| 12 | themes are stored in `'$site_path'/themes/{project-name}`. Files are |
| 13 | only served from a single theme directory; if you want to modify or |
| 14 | extend an inherited theme, you must copy it into the appropriate |
| 15 | per-project directory. |
| 16 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 17 | == HTML Header/Footer |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 18 | |
| 19 | At startup Gerrit reads the following files (if they exist) and |
| 20 | uses them to customize the HTML page it sends to clients: |
| 21 | |
Dave Borowitz | 1e49e14 | 2013-04-09 12:14:57 -0700 | [diff] [blame] | 22 | * `<theme-dir>/GerritSiteHeader.html` |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 23 | + |
| 24 | HTML is inserted below the menu bar, but above any page content. |
| 25 | This is a good location for an organizational logo, or links to |
| 26 | other systems like bug tracking. |
| 27 | |
Dave Borowitz | 1e49e14 | 2013-04-09 12:14:57 -0700 | [diff] [blame] | 28 | * `<theme-dir>/GerritSiteFooter.html` |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 29 | + |
Shawn O. Pearce | 03273c9 | 2009-01-13 10:32:50 -0800 | [diff] [blame] | 30 | HTML is inserted at the bottom of the page, below all other content, |
| 31 | but just above the footer rule and the "Powered by Gerrit Code |
| 32 | Review (v....)" message shown at the extreme bottom. |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 33 | |
Dave Borowitz | 1e49e14 | 2013-04-09 12:14:57 -0700 | [diff] [blame] | 34 | * `<theme-dir>/GerritSite.css` |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 35 | + |
| 36 | The CSS rules are inlined into the top of the HTML page, inside |
| 37 | of a `<style>` tag. These rules can be used to support styling |
| 38 | the elements within either the header or the footer. |
| 39 | |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 40 | The *.html files must be valid XHTML, with one root element, |
| 41 | typically a single `<div>` tag. The server parses it as XML, and |
| 42 | then inserts the root element into the host page. If a file has |
| 43 | more than one root level element, Gerrit will not start. |
| 44 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 45 | == Static Images |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 46 | |
Shawn O. Pearce | 1261bef | 2009-05-08 18:31:51 -0700 | [diff] [blame] | 47 | Static image files can also be served from `'$site_path'/static`, |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 48 | and may be referenced in `GerritSite{Header,Footer}.html` |
| 49 | or `GerritSite.css` by the relative URL `static/$name` |
| 50 | (e.g. `static/logo.png`). |
| 51 | |
David Pursehouse | 221d4f6 | 2012-06-08 17:38:08 +0900 | [diff] [blame] | 52 | To simplify security management, files are only served from |
Shawn O. Pearce | 1261bef | 2009-05-08 18:31:51 -0700 | [diff] [blame] | 53 | `'$site_path'/static`. Subdirectories are explicitly forbidden from |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 54 | being served from this location by enforcing the rule that file names |
| 55 | cannot contain `/` or `\`. (Client requests for `static/foo/bar` |
| 56 | will result in 404 Not Found responses.) |
| 57 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 58 | == HTTP Caching |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 59 | |
Shawn O. Pearce | 0e2604c | 2009-05-08 09:46:33 -0700 | [diff] [blame] | 60 | The header, footer, and CSS files are inlined into the host page, |
| 61 | which is always sent with a no-cache header. Clients will see any |
Shawn O. Pearce | 1fdd6bf | 2010-01-08 19:28:12 -0800 | [diff] [blame] | 62 | changes immediately after they are made. |
Shawn O. Pearce | 0e2604c | 2009-05-08 09:46:33 -0700 | [diff] [blame] | 63 | |
Shawn O. Pearce | 1261bef | 2009-05-08 18:31:51 -0700 | [diff] [blame] | 64 | Assets under `'$site_path'/static` whose file name matches one of the |
Shawn O. Pearce | 0e2604c | 2009-05-08 09:46:33 -0700 | [diff] [blame] | 65 | following patterns are served with a 1 year expiration, permitting |
| 66 | very 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. Pearce | 1261bef | 2009-05-08 18:31:51 -0700 | [diff] [blame] | 75 | All other assets under `'$site_path'/static` are served with a 5 |
Shawn O. Pearce | 0e2604c | 2009-05-08 09:46:33 -0700 | [diff] [blame] | 76 | minute expire, permitting some (limited) caching. It may take up |
Shawn O. Pearce | 1fdd6bf | 2010-01-08 19:28:12 -0800 | [diff] [blame] | 77 | to 5 minutes after making a change, before clients see the changes. |
Shawn O. Pearce | 0e2604c | 2009-05-08 09:46:33 -0700 | [diff] [blame] | 78 | |
| 79 | It is recommended that static images used in the site header |
| 80 | or footer be named with a unique caching file name, for example |
| 81 | `my_logo1.cache.png`, to allow browsers to take advantage of their |
| 82 | disk 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 |
| 84 | reference the new image path. |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 85 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 86 | == Google Analytics Integration |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 87 | |
| 88 | To 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 Pearce | a48826e | 2013-11-29 20:38:55 -0800 | [diff] [blame] | 102 | be <!-- /standard analytics code --> |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 103 | |
| 104 | <script type="text/javascript"> |
| 105 | window.onload = function() { |
Shawn Pearce | a48826e | 2013-11-29 20:38:55 -0800 | [diff] [blame] | 106 | var p = window.location.pathname; |
| 107 | Gerrit.on('history', function (s) { |
| 108 | pageTracker._trackPageview(p + '/' + s) |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 109 | }); |
| 110 | }; |
| 111 | </script> |
| 112 | </div> |
| 113 | ==== |
| 114 | |
| 115 | Please consult the Google Analytics documentation for the correct |
| 116 | setup code (the first two script tags). The above is shown only |
| 117 | as a reference example. |
| 118 | |
Shawn O. Pearce | 4335c30 | 2009-05-08 09:54:45 -0700 | [diff] [blame] | 119 | If your footer is otherwise empty, wrap all of the script tags into |
| 120 | a single `<div>` tag (like above) to ensure it is a well-formed |
| 121 | XHTML document file. |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 122 | |
Shawn Pearce | a48826e | 2013-11-29 20:38:55 -0800 | [diff] [blame] | 123 | The global function `Gerrit.on("history")` accepts functions that |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 124 | accept a string parameter. These functions are put into a list and |
| 125 | invoked any time Gerrit shifts URLs. You'll see page names like |
Shawn Pearce | a48826e | 2013-11-29 20:38:55 -0800 | [diff] [blame] | 126 | `/c/123` be passed to these functions, which in turn are handed off |
| 127 | to Google Analytics for tracking. Our example hook above uses '/' |
| 128 | instead of '#' because Analytics won't track anchors. |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 129 | |
| 130 | The `window.onload` callback is necessary to ensure that the |
Shawn Pearce | a48826e | 2013-11-29 20:38:55 -0800 | [diff] [blame] | 131 | `Gerrit.on()` function has actually been defined by the |
Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 132 | page. Because GWT loads the module asynchronously any `<script>` |
| 133 | block in the header or footer will execute before Gerrit has defined |
| 134 | the function and is ready to register the hook callback. |
| 135 | |
Shawn Pearce | a48826e | 2013-11-29 20:38:55 -0800 | [diff] [blame] | 136 | The function `gerrit_addHistoryHook` is deprecated and may be |
| 137 | removed in a future release. |
| 138 | |
Shawn O. Pearce | 5500e69 | 2009-05-28 15:55:01 -0700 | [diff] [blame] | 139 | GERRIT |
| 140 | ------ |
| 141 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 142 | |
| 143 | SEARCHBOX |
| 144 | --------- |