Add syntax highlighting for source code examples in documentation

Currently source code examples are not syntax highlighted in the
documentation.  Also, they do not get formatted properly if they include
blank lines.

Update the documentation to make the source code examples get treated
as source code, with syntax highlighting and correct handling of blank
lines.

Change-Id: I0a211a4c350805fe1adec0c1cef6d092b0da553c
This commit is contained in:
David Pursehouse 2013-09-04 10:09:17 +09:00
parent 9b554f8268
commit 68153d7f89
2 changed files with 268 additions and 210 deletions

View File

@ -215,28 +215,29 @@ and before the DB Schema initialization or upgrade.
Plugins InitStep cannot refer to Gerrit DB Schema or any other Gerrit runtime Plugins InitStep cannot refer to Gerrit DB Schema or any other Gerrit runtime
objects injected at startup. objects injected at startup.
==== [source,java]
public class MyInitStep implements InitStep { ----
private final ConsoleUI ui; public class MyInitStep implements InitStep {
private final Section.Factory sections; private final ConsoleUI ui;
private final String pluginName; private final Section.Factory sections;
private final String pluginName;
@Inject @Inject
public GitBlitInitStep(final ConsoleUI ui, Section.Factory sections, @PluginName String pluginName) { public GitBlitInitStep(final ConsoleUI ui, Section.Factory sections, @PluginName String pluginName) {
this.ui = ui; this.ui = ui;
this.sections = sections; this.sections = sections;
this.pluginName = pluginName; this.pluginName = pluginName;
}
@Override
public void run() throws Exception {
ui.header("\nMy plugin");
Section mySection = getSection("myplugin", null);
mySection.string("Link name", "linkname", "MyLink");
}
} }
====
@Override
public void run() throws Exception {
ui.header("\nMy plugin");
Section mySection = getSection("myplugin", null);
mySection.string("Link name", "linkname", "MyLink");
}
}
----
[[classpath]] [[classpath]]
Classpath Classpath
@ -263,44 +264,47 @@ interface (extensions do not have this option).
Command implementations must extend the base class SshCommand: Command implementations must extend the base class SshCommand:
==== [source,java]
import com.google.gerrit.sshd.SshCommand; ----
import com.google.gerrit.sshd.SshCommand;
class PrintHello extends SshCommand { class PrintHello extends SshCommand {
protected abstract void run() { protected abstract void run() {
stdout.print("Hello\n"); stdout.print("Hello\n");
}
} }
==== }
----
If no Guice modules are declared in the manifest, SSH commands may If no Guice modules are declared in the manifest, SSH commands may
use auto-registration by providing an `@Export` annotation: use auto-registration by providing an `@Export` annotation:
==== [source,java]
import com.google.gerrit.extensions.annotations.Export; ----
import com.google.gerrit.sshd.SshCommand; import com.google.gerrit.extensions.annotations.Export;
import com.google.gerrit.sshd.SshCommand;
@Export("print") @Export("print")
class PrintHello extends SshCommand { class PrintHello extends SshCommand {
protected abstract void run() { protected abstract void run() {
stdout.print("Hello\n"); stdout.print("Hello\n");
}
} }
==== }
----
If explicit registration is being used, a Guice module must be If explicit registration is being used, a Guice module must be
supplied to register the SSH command and declared in the manifest supplied to register the SSH command and declared in the manifest
with the `Gerrit-SshModule` attribute: with the `Gerrit-SshModule` attribute:
==== [source,java]
import com.google.gerrit.sshd.PluginCommandModule; ----
import com.google.gerrit.sshd.PluginCommandModule;
class MyCommands extends PluginCommandModule { class MyCommands extends PluginCommandModule {
protected void configureCommands() { protected void configureCommands() {
command("print").to(PrintHello.class); command("print").to(PrintHello.class);
}
} }
==== }
----
For a plugin installed as name `helloworld`, the command implemented For a plugin installed as name `helloworld`, the command implemented
by PrintHello class will be available to users as: by PrintHello class will be available to users as:
@ -319,56 +323,64 @@ commands to the users who are granted those capabilities.
Plugins define the capabilities by overriding the `CapabilityDefinition` Plugins define the capabilities by overriding the `CapabilityDefinition`
abstract class: abstract class:
==== [source,java]
public class PrintHelloCapability extends CapabilityDefinition { ----
@Override public class PrintHelloCapability extends CapabilityDefinition {
public String getDescription() { @Override
return "Print Hello"; public String getDescription() {
} return "Print Hello";
} }
==== }
----
If no Guice modules are declared in the manifest, UI actions may If no Guice modules are declared in the manifest, UI actions may
use auto-registration by providing an `@Export` annotation: use auto-registration by providing an `@Export` annotation:
==== [source,java]
@Export("printHello") ----
public class PrintHelloCapability extends CapabilityDefinition { @Export("printHello")
public class PrintHelloCapability extends CapabilityDefinition {
... ...
==== }
----
Otherwise the capability must be bound in a plugin module: Otherwise the capability must be bound in a plugin module:
==== [source,java]
public class HelloWorldModule extends AbstractModule { ----
@Override public class HelloWorldModule extends AbstractModule {
protected void configure() { @Override
bind(CapabilityDefinition.class) protected void configure() {
.annotatedWith(Exports.named("printHello")) bind(CapabilityDefinition.class)
.to(PrintHelloCapability.class); .annotatedWith(Exports.named("printHello"))
} .to(PrintHelloCapability.class);
} }
==== }
----
With a plugin-owned capability defined in this way, it is possible to restrict With a plugin-owned capability defined in this way, it is possible to restrict
usage of an SSH command or `UiAction` to members of the group that were granted usage of an SSH command or `UiAction` to members of the group that were granted
this capability in the usual way, using the `RequiresCapability` annotation: this capability in the usual way, using the `RequiresCapability` annotation:
==== [source,java]
@RequiresCapability("printHello") ----
@CommandMetaData(name="print", description="Print greeting in different languages") @RequiresCapability("printHello")
public final class PrintHelloWorldCommand extends SshCommand { @CommandMetaData(name="print", description="Print greeting in different languages")
public final class PrintHelloWorldCommand extends SshCommand {
... ...
==== }
----
Or with `UiAction`: Or with `UiAction`:
==== [source,java]
@RequiresCapability("printHello") ----
public class SayHelloAction extends UiAction<RevisionResource> @RequiresCapability("printHello")
implements RestModifyView<RevisionResource, SayHelloAction.Input> { public class SayHelloAction extends UiAction<RevisionResource>
implements RestModifyView<RevisionResource, SayHelloAction.Input> {
... ...
==== }
----
Capability scope was introduced to differentiate between plugin-owned Capability scope was introduced to differentiate between plugin-owned
capabilities and core capabilities. Per default the scope of the capabilities and core capabilities. Per default the scope of the
@ -384,11 +396,12 @@ the `GlobalCapability` known to Gerrit Code Review server.
If a plugin needs to use a core capability name (e.g. "administrateServer") If a plugin needs to use a core capability name (e.g. "administrateServer")
this can be specified by setting `scope = CapabilityScope.CORE`: this can be specified by setting `scope = CapabilityScope.CORE`:
==== [source,java]
@RequiresCapability(value = "administrateServer", scope = ----
CapabilityScope.CORE) @RequiresCapability(value = "administrateServer", scope =
CapabilityScope.CORE)
... ...
==== ----
[[ui_extension]] [[ui_extension]]
UI Extension UI Extension
@ -410,138 +423,146 @@ Two different places on core Gerrit pages are currently supported:
Plugins contribute UI actions by implementing the `UiAction` interface: Plugins contribute UI actions by implementing the `UiAction` interface:
==== [source,java]
@RequiresCapability("printHello") ----
class HelloWorldAction implements UiAction<RevisionResource>, @RequiresCapability("printHello")
RestModifyView<RevisionResource, HelloWorldAction.Input> { class HelloWorldAction implements UiAction<RevisionResource>,
static class Input { RestModifyView<RevisionResource, HelloWorldAction.Input> {
boolean french; static class Input {
String message; boolean french;
} String message;
private Provider<CurrentUser> user;
@Inject
HelloWorldAction(Provider<CurrentUser> user) {
this.user = user;
}
@Override
public String apply(RevisionResource rev, Input input) {
final String greeting = input.french
? "Bonjour"
: "Hello";
return String.format("%s %s from change %s, patch set %d!",
greeting,
Strings.isNullOrEmpty(input.message)
? Objects.firstNonNull(user.get().getUserName(), "world")
: input.message,
rev.getChange().getId().toString(),
rev.getPatchSet().getPatchSetId());
}
@Override
public Description getDescription(
RevisionResource resource) {
return new Description()
.setLabel("Say hello")
.setTitle("Say hello in different languages");
}
} }
====
private Provider<CurrentUser> user;
@Inject
HelloWorldAction(Provider<CurrentUser> user) {
this.user = user;
}
@Override
public String apply(RevisionResource rev, Input input) {
final String greeting = input.french
? "Bonjour"
: "Hello";
return String.format("%s %s from change %s, patch set %d!",
greeting,
Strings.isNullOrEmpty(input.message)
? Objects.firstNonNull(user.get().getUserName(), "world")
: input.message,
rev.getChange().getId().toString(),
rev.getPatchSet().getPatchSetId());
}
@Override
public Description getDescription(
RevisionResource resource) {
return new Description()
.setLabel("Say hello")
.setTitle("Say hello in different languages");
}
}
----
`UiAction` must be bound in a plugin module: `UiAction` must be bound in a plugin module:
==== [source,java]
public class Module extends AbstractModule { ----
@Override public class Module extends AbstractModule {
protected void configure() { @Override
install(new RestApiModule() { protected void configure() {
@Override install(new RestApiModule() {
protected void configure() { @Override
post(REVISION_KIND, "say-hello") protected void configure() {
.to(HelloWorldAction.class); post(REVISION_KIND, "say-hello")
} .to(HelloWorldAction.class);
}); }
} });
} }
==== }
----
The module above must be declared in pom.xml for Maven driven plugins: The module above must be declared in pom.xml for Maven driven plugins:
==== [source,xml]
<manifestEntries> ----
<Gerrit-Module>com.googlesource.gerrit.plugins.cookbook.Module</Gerrit-Module> <manifestEntries>
</manifestEntries> <Gerrit-Module>com.googlesource.gerrit.plugins.cookbook.Module</Gerrit-Module>
==== </manifestEntries>
----
or in the BUCK configuration file for Buck driven plugins: or in the BUCK configuration file for Buck driven plugins:
==== [source,python]
manifest_entries = [ ----
'Gerrit-Module: com.googlesource.gerrit.plugins.cookbook.Module', manifest_entries = [
] 'Gerrit-Module: com.googlesource.gerrit.plugins.cookbook.Module',
==== ]
----
In some use cases more user input must be gathered, for that `UiAction` can be In some use cases more user input must be gathered, for that `UiAction` can be
combined with the JavaScript API. This would display a small popup near the combined with the JavaScript API. This would display a small popup near the
activation button to gather additional input from the user. The JS file is activation button to gather additional input from the user. The JS file is
typically put in the `static` folder within the plugin's directory: typically put in the `static` folder within the plugin's directory:
==== [source,javascript]
Gerrit.install(function(self) { ----
function onSayHello(c) { Gerrit.install(function(self) {
var f = c.textfield(); function onSayHello(c) {
var t = c.checkbox(); var f = c.textfield();
var b = c.button('Say hello', {onclick: function(){ var t = c.checkbox();
c.call( var b = c.button('Say hello', {onclick: function(){
{message: f.value, french: t.checked}, c.call(
function(r) { {message: f.value, french: t.checked},
c.hide(); function(r) {
window.alert(r); c.hide();
c.refresh(); window.alert(r);
}); c.refresh();
}}); });
c.popup(c.div( }});
c.prependLabel('Greeting message', f), c.popup(c.div(
c.br(), c.prependLabel('Greeting message', f),
c.label(t, 'french'), c.br(),
c.br(), c.label(t, 'french'),
b)); c.br(),
f.focus(); b));
} f.focus();
self.onAction('revision', 'say-hello', onSayHello); }
}); self.onAction('revision', 'say-hello', onSayHello);
==== });
----
The JS module must be exposed as a `WebUiPlugin` and bound as The JS module must be exposed as a `WebUiPlugin` and bound as
an HTTP Module: an HTTP Module:
==== [source,java]
public class HttpModule extends HttpPluginModule { ----
@Override public class HttpModule extends HttpPluginModule {
protected void configureServlets() { @Override
DynamicSet.bind(binder(), WebUiPlugin.class) protected void configureServlets() {
.toInstance(new JavaScriptPlugin("hello.js")); DynamicSet.bind(binder(), WebUiPlugin.class)
} .toInstance(new JavaScriptPlugin("hello.js"));
} }
==== }
----
The HTTP module above must be declared in pom.xml for Maven driven plugins: The HTTP module above must be declared in pom.xml for Maven driven plugins:
==== [source,xml]
<manifestEntries> ----
<Gerrit-HttpModule>com.googlesource.gerrit.plugins.cookbook.HttpModule</Gerrit-HttpModule> <manifestEntries>
</manifestEntries> <Gerrit-HttpModule>com.googlesource.gerrit.plugins.cookbook.HttpModule</Gerrit-HttpModule>
==== </manifestEntries>
----
or in the BUCK configuration file for Buck driven plugins or in the BUCK configuration file for Buck driven plugins
==== [source,python]
manifest_entries = [ ----
'Gerrit-HttpModule: com.googlesource.gerrit.plugins.cookbook.HttpModule', manifest_entries = [
] 'Gerrit-HttpModule: com.googlesource.gerrit.plugins.cookbook.HttpModule',
==== ]
----
If `UiAction` is annotated with the `@RequiresCapability` annotation, then the If `UiAction` is annotated with the `@RequiresCapability` annotation, then the
capability check is done during the `UiAction` gathering, so the plugin author capability check is done during the `UiAction` gathering, so the plugin author
@ -579,38 +600,40 @@ wrap them with HTTP filters.
Servlets may use auto-registration to declare the URL they handle: Servlets may use auto-registration to declare the URL they handle:
==== [source,java]
import com.google.gerrit.extensions.annotations.Export; ----
import com.google.inject.Singleton; import com.google.gerrit.extensions.annotations.Export;
import javax.servlet.http.HttpServlet; import com.google.inject.Singleton;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Export("/print") @Export("/print")
@Singleton @Singleton
class HelloServlet extends HttpServlet { class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.setContentType("text/plain"); res.setContentType("text/plain");
res.setCharacterEncoding("UTF-8"); res.setCharacterEncoding("UTF-8");
res.getWriter().write("Hello"); res.getWriter().write("Hello");
}
} }
==== }
----
The auto registration only works for standard servlet mappings like The auto registration only works for standard servlet mappings like
`/foo` or `/foo/*`. Regex style bindings must use a Guice ServletModule `/foo` or `/foo/*`. Regex style bindings must use a Guice ServletModule
to register the HTTP servlets and declare it explicitly in the manifest to register the HTTP servlets and declare it explicitly in the manifest
with the `Gerrit-HttpModule` attribute: with the `Gerrit-HttpModule` attribute:
==== [source,java]
import com.google.inject.servlet.ServletModule; ----
import com.google.inject.servlet.ServletModule;
class MyWebUrls extends ServletModule { class MyWebUrls extends ServletModule {
protected void configureServlets() { protected void configureServlets() {
serve("/print").with(HelloServlet.class); serve("/print").with(HelloServlet.class);
}
} }
==== }
----
For a plugin installed as name `helloworld`, the servlet implemented For a plugin installed as name `helloworld`, the servlet implemented
by HelloServlet class will be available to users as: by HelloServlet class will be available to users as:
@ -629,12 +652,13 @@ server in `$site_path/data/$plugin_name` and passed to the plugin.
Plugins can use this to store any data they want. Plugins can use this to store any data they want.
==== [source,java]
@Inject ----
MyType(@PluginData java.io.File myDir) { @Inject
new FileInputStream(new File(myDir, "my.config")); MyType(@PluginData java.io.File myDir) {
} new FileInputStream(new File(myDir, "my.config"));
==== }
----
[[documentation]] [[documentation]]
Documentation Documentation

View File

@ -12,6 +12,7 @@ Plugins should protect the global namespace by defining their code
within an anonymous function passed to `Gerrit.install()`. The plugin within an anonymous function passed to `Gerrit.install()`. The plugin
will be passed an object describing its registration with Gerrit: will be passed an object describing its registration with Gerrit:
[source,javascript]
---- ----
Gerrit.install(function (self) { Gerrit.install(function (self) {
// ... plugin JavaScript code here ... // ... plugin JavaScript code here ...
@ -32,6 +33,7 @@ self.delete()
Issues a DELETE REST API request to the Gerrit server. Issues a DELETE REST API request to the Gerrit server.
.Signature .Signature
[source,javascript]
---- ----
Gerrit.delete(url, callback) Gerrit.delete(url, callback)
---- ----
@ -49,6 +51,7 @@ self.get()
Issues a GET REST API request to the Gerrit server. Issues a GET REST API request to the Gerrit server.
.Signature .Signature
[source,javascript]
---- ----
self.get(url, callback) self.get(url, callback)
---- ----
@ -74,6 +77,7 @@ self.post()
Issues a POST REST API request to the Gerrit server. Issues a POST REST API request to the Gerrit server.
.Signature .Signature
[source,javascript]
---- ----
self.post(url, input, callback) self.post(url, input, callback)
---- ----
@ -88,6 +92,7 @@ self.post(url, input, callback)
a string, otherwise the result is a JavaScript object or array, a string, otherwise the result is a JavaScript object or array,
as described in the relevant REST API documentation. as described in the relevant REST API documentation.
[source,javascript]
---- ----
self.post( self.post(
'/my-servlet', '/my-servlet',
@ -101,6 +106,7 @@ self.put()
Issues a PUT REST API request to the Gerrit server. Issues a PUT REST API request to the Gerrit server.
.Signature .Signature
[source,javascript]
---- ----
self.put(url, input, callback) self.put(url, input, callback)
---- ----
@ -115,6 +121,7 @@ self.put(url, input, callback)
a string, otherwise the result is a JavaScript object or array, a string, otherwise the result is a JavaScript object or array,
as described in the relevant REST API documentation. as described in the relevant REST API documentation.
[source,javascript]
---- ----
self.put( self.put(
'/builds', '/builds',
@ -129,6 +136,7 @@ Register a JavaScript callback to be invoked when the user clicks
on a button associated with a server side `UiAction`. on a button associated with a server side `UiAction`.
.Signature .Signature
[source,javascript]
---- ----
Gerrit.onAction(type, view_name, callback); Gerrit.onAction(type, view_name, callback);
---- ----
@ -150,6 +158,7 @@ Returns a URL within the plugin's URL space. If invoked with no
parameter the URL of the plugin is returned. If passed a string parameter the URL of the plugin is returned. If passed a string
the argument is appended to the plugin URL. the argument is appended to the plugin URL.
[source,javascript]
---- ----
self.url(); // "https://gerrit-review.googlesource.com/plugins/demo/" self.url(); // "https://gerrit-review.googlesource.com/plugins/demo/"
self.url('/static/icon.png'); // "https://gerrit-review.googlesource.com/plugins/demo/static/icon.png" self.url('/static/icon.png'); // "https://gerrit-review.googlesource.com/plugins/demo/static/icon.png"
@ -167,7 +176,7 @@ REST API RPC.
[[context_action]] [[context_action]]
context.action context.action
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
A link:rest-api-changes.html#action-info[ActionInfo] object instance An link:rest-api-changes.html#action-info[ActionInfo] object instance
supplied by the server describing the UI button the user used to supplied by the server describing the UI button the user used to
invoke the action. invoke the action.
@ -179,6 +188,7 @@ used comes from `context.action.method`, hiding the JavaScript from
needing to care. needing to care.
.Signature .Signature
[source,javascript]
---- ----
context.call(input, callback) context.call(input, callback)
---- ----
@ -191,6 +201,7 @@ context.call(input, callback)
a string, otherwise the result is a JavaScript object or array, a string, otherwise the result is a JavaScript object or array,
as described in the relevant REST API documentation. as described in the relevant REST API documentation.
[source,javascript]
---- ----
context.call( context.call(
{message: "..."}, {message: "..."},
@ -213,6 +224,7 @@ context.delete()
Issues a DELETE REST API call to the URL associated with the action. Issues a DELETE REST API call to the URL associated with the action.
.Signature .Signature
[source,javascript]
---- ----
context.delete(callback) context.delete(callback)
---- ----
@ -221,6 +233,7 @@ context.delete(callback)
JSON result of the API call. DELETE methods often return JSON result of the API call. DELETE methods often return
`204 No Content`, which is passed as null. `204 No Content`, which is passed as null.
[source,javascript]
---- ----
context.delete(function () {}); context.delete(function () {});
---- ----
@ -231,6 +244,7 @@ context.get()
Issues a GET REST API call to the URL associated with the action. Issues a GET REST API call to the URL associated with the action.
.Signature .Signature
[source,javascript]
---- ----
context.get(callback) context.get(callback)
---- ----
@ -240,6 +254,7 @@ context.get(callback)
a string, otherwise the result is a JavaScript object or array, a string, otherwise the result is a JavaScript object or array,
as described in the relevant REST API documentation. as described in the relevant REST API documentation.
[source,javascript]
---- ----
context.get(function (result) { context.get(function (result) {
// ... use result here ... // ... use result here ...
@ -263,6 +278,7 @@ context.post()
Issues a POST REST API call to the URL associated with the action. Issues a POST REST API call to the URL associated with the action.
.Signature .Signature
[source,javascript]
---- ----
context.post(input, callback) context.post(input, callback)
---- ----
@ -274,6 +290,7 @@ context.post(input, callback)
a string, otherwise the result is a JavaScript object or array, a string, otherwise the result is a JavaScript object or array,
as described in the relevant REST API documentation. as described in the relevant REST API documentation.
[source,javascript]
---- ----
context.post( context.post(
{message: "..."}, {message: "..."},
@ -295,6 +312,7 @@ popup if the user presses `Escape` while keyboard focus is within
the popup. the popup.
.Signature .Signature
[source,javascript]
---- ----
context.popup(element) context.popup(element)
---- ----
@ -304,6 +322,8 @@ context.popup(element)
element. CSS can be used to style the element beyond the defaults. element. CSS can be used to style the element beyond the defaults.
A common usage is to gather more input: A common usage is to gather more input:
[source,javascript]
---- ----
self.onAction('revision', 'start-build', function (c) { self.onAction('revision', 'start-build', function (c) {
var l = c.checkbox(); var l = c.checkbox();
@ -329,6 +349,7 @@ context.put()
Issues a PUT REST API call to the URL associated with the action. Issues a PUT REST API call to the URL associated with the action.
.Signature .Signature
[source,javascript]
---- ----
context.put(input, callback) context.put(input, callback)
---- ----
@ -340,6 +361,7 @@ context.put(input, callback)
a string, otherwise the result is a JavaScript object or array, a string, otherwise the result is a JavaScript object or array,
as described in the relevant REST API documentation. as described in the relevant REST API documentation.
[source,javascript]
---- ----
context.put( context.put(
{message: "..."}, {message: "..."},
@ -417,6 +439,7 @@ Issues a DELETE REST API request to the Gerrit server. For plugin
private REST API URLs see link:#self_delete[self.delete()]. private REST API URLs see link:#self_delete[self.delete()].
.Signature .Signature
[source,javascript]
---- ----
Gerrit.delete(url, callback) Gerrit.delete(url, callback)
---- ----
@ -428,6 +451,7 @@ Gerrit.delete(url, callback)
JSON result of the API call. DELETE methods often return JSON result of the API call. DELETE methods often return
`204 No Content`, which is passed as null. `204 No Content`, which is passed as null.
[source,javascript]
---- ----
Gerrit.delete( Gerrit.delete(
'/changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/topic', '/changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/topic',
@ -441,6 +465,7 @@ Issues a GET REST API request to the Gerrit server. For plugin
private REST API URLs see link:#self_get[self.get()]. private REST API URLs see link:#self_get[self.get()].
.Signature .Signature
[source,javascript]
---- ----
Gerrit.get(url, callback) Gerrit.get(url, callback)
---- ----
@ -453,6 +478,7 @@ Gerrit.get(url, callback)
a string, otherwise the result is a JavaScript object or array, a string, otherwise the result is a JavaScript object or array,
as described in the relevant REST API documentation. as described in the relevant REST API documentation.
[source,javascript]
---- ----
Gerrit.get('/changes/?q=status:open', function (open) { Gerrit.get('/changes/?q=status:open', function (open) {
for (var i = 0; i < open.length; i++) { for (var i = 0; i < open.length; i++) {
@ -478,6 +504,7 @@ Gerrit.go()
Updates the web UI to display the view identified by the supplied Updates the web UI to display the view identified by the supplied
URL token. The URL token is the text after `#` in the browser URL. URL token. The URL token is the text after `#` in the browser URL.
[source,javascript]
---- ----
Gerrit.go('/admin/projects/'); Gerrit.go('/admin/projects/');
---- ----
@ -492,6 +519,7 @@ Gerrit.install()
Registers a new plugin by invoking the supplied initialization Registers a new plugin by invoking the supplied initialization
function. The function is passed the link:#self[plugin instance]. function. The function is passed the link:#self[plugin instance].
[source,javascript]
---- ----
Gerrit.install(function (self) { Gerrit.install(function (self) {
// ... plugin JavaScript code here ... // ... plugin JavaScript code here ...
@ -505,6 +533,7 @@ Issues a POST REST API request to the Gerrit server. For plugin
private REST API URLs see link:#self_post[self.post()]. private REST API URLs see link:#self_post[self.post()].
.Signature .Signature
[source,javascript]
---- ----
Gerrit.post(url, input, callback) Gerrit.post(url, input, callback)
---- ----
@ -519,6 +548,7 @@ Gerrit.post(url, input, callback)
a string, otherwise the result is a JavaScript object or array, a string, otherwise the result is a JavaScript object or array,
as described in the relevant REST API documentation. as described in the relevant REST API documentation.
[source,javascript]
---- ----
Gerrit.post( Gerrit.post(
'/changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/topic', '/changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/topic',
@ -533,6 +563,7 @@ Issues a PUT REST API request to the Gerrit server. For plugin
private REST API URLs see link:#self_put[self.put()]. private REST API URLs see link:#self_put[self.put()].
.Signature .Signature
[source,javascript]
---- ----
Gerrit.put(url, input, callback) Gerrit.put(url, input, callback)
---- ----
@ -547,6 +578,7 @@ Gerrit.put(url, input, callback)
a string, otherwise the result is a JavaScript object or array, a string, otherwise the result is a JavaScript object or array,
as described in the relevant REST API documentation. as described in the relevant REST API documentation.
[source,javascript]
---- ----
Gerrit.put( Gerrit.put(
'/changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/topic', '/changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/topic',
@ -561,6 +593,7 @@ Register a JavaScript callback to be invoked when the user clicks
on a button associated with a server side `UiAction`. on a button associated with a server side `UiAction`.
.Signature .Signature
[source,javascript]
---- ----
Gerrit.onAction(type, view_name, callback); Gerrit.onAction(type, view_name, callback);
---- ----
@ -587,6 +620,7 @@ Returns the URL of the Gerrit Code Review server. If invoked with
no parameter the URL of the site is returned. If passed a string no parameter the URL of the site is returned. If passed a string
the argument is appended to the site URL. the argument is appended to the site URL.
[source,javascript]
---- ----
Gerrit.url(); // "https://gerrit-review.googlesource.com/" Gerrit.url(); // "https://gerrit-review.googlesource.com/"
Gerrit.url('/123'); // "https://gerrit-review.googlesource.com/123" Gerrit.url('/123'); // "https://gerrit-review.googlesource.com/123"