Markdown formatting improvements

Extract the first H1 level string from the documentation and make that
the HTML page title. Embed a small block of CSS that makes the style
of the page look more like the rest of the Gerrit documentation pages.
Wrap the entire pegdown output in a proper HTML tag.

The pegdown.css is cached when read from a JAR, but loads on demand
when read from a file:// URL. This enables a fast edit-view cycle of
the style sheet when running the server from within Eclipse or another
IDE that loads the resources from the source tree.

If the Documentation/ URL ends with / redirect to look for index.html
instead. This provides some simple support for directory indexes by
allowing directory references to jump to the index.html document,
which might be index.md in the JAR.

If the plugin doesn't answer to / on its own, redirect web requests
for /plugins/NAME to /plugins/NAME/Documentation/index.html allowing
the user to at least see the documentation.

Only attempt to convert resources that end with ".md" from Markdown to
HTML, rather than everything.

Documentation and static resources are only available by GET and HEAD
HTTP methods. POST, PUT, DELETE, etc. will fail with an error.

If there is no index.html or index.md in Documentation/, render one on
the fly by creating a listing of documentation pages, extracting their
titles and rendering it using the MarkdownFormatter.  This keeps the
style consistent with the rest of the documentation in a plugin.

When rendering Documentation files from Markdown to HTML, replace the
macro @PLUGIN@ with the current name of the plugin. This allows
authors to write documentation with reasonably accurate examples that
adjusts automatically based on the installation.

Also support @URL@, @SSH_HOST@, and @SSH_PORT@ replacements in
Markdown documentation for common ways to reference this server.

Macros that start with \ such as \@KEEP@ will render as @KEEP@
even if there is an expansion for KEEP in the future.

Formatted documentation and other static resources for plugins are
cached in memory, to save response time when sending frequently
requested items to clients.

Change-Id: I988038021d4a047bd008561aeedc3ccfd5a1b294
This commit is contained in:
Shawn O. Pearce
2012-05-12 11:20:18 -07:00
parent 9dcb63cd70
commit 795167c05e
6 changed files with 647 additions and 65 deletions

View File

@@ -45,6 +45,21 @@ public class Plugin {
EXTENSION, PLUGIN;
}
/** Unique key that changes whenever a plugin reloads. */
public static final class CacheKey {
private final String name;
CacheKey(String name) {
this.name = name;
}
@Override
public String toString() {
int id = System.identityHashCode(this);
return String.format("Plugin[%s@%x]", name, id);
}
}
static {
// Guice logs warnings about multiple injectors being created.
// Silence this in case HTTP plugins are used.
@@ -65,6 +80,7 @@ public class Plugin {
}
}
private final CacheKey cacheKey;
private final String name;
private final File srcJar;
private final FileSnapshot snapshot;
@@ -94,6 +110,7 @@ public class Plugin {
@Nullable Class<? extends Module> sysModule,
@Nullable Class<? extends Module> sshModule,
@Nullable Class<? extends Module> httpModule) {
this.cacheKey = new CacheKey(name);
this.name = name;
this.srcJar = srcJar;
this.snapshot = snapshot;
@@ -111,6 +128,10 @@ public class Plugin {
return srcJar;
}
public CacheKey getCacheKey() {
return cacheKey;
}
public String getName() {
return name;
}