com.github.easydoc.sourcebrowser.GithubSourceBrowser Maven / Gradle / Ivy
package com.github.easydoc.sourcebrowser;
import java.net.MalformedURLException;
import java.net.URL;
import com.github.easydoc.model.Doc;
import com.github.easydoc.model.SourceLink;
import com.github.easydoc.param.SourceBrowserParam;
/*@@easydoc-start, belongs=easydoc-maven-source-browser@@
github
GitHub source browser. To specify it, use the following snippet:
<sourceBrowser>
<type>github</type>
<baseUrl>https://github.com/weekens/easydoc/blob/master/</baseUrl>
</sourceBrowser>
Replace baseUrl value with the one from your GitHub repository.
@@easydoc-end@@*/
public class GithubSourceBrowser implements SourceBrowser {
private final String baseUrl;
public GithubSourceBrowser(SourceBrowserParam sbParam) {
this.baseUrl = sbParam.getBaseUrl();
}
@Override
public URL generateUrl(Doc doc) {
try {
SourceLink sourceLink = doc.getSourceLink();
return new URL(
String.format(
"%s%s#L%d-%d",
baseUrl,
sourceLink.getFile().getPath(),
sourceLink.getStartLine(),
sourceLink.getEndLine())
);
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy