Extended browse method to support optional file path #28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I want to be able to generate URLs for non-raw files. This ability will be useful for links to formatted docs and/or syntax highlighted source files. Personally, I'm looking for the former; I want to generate URLs for viewing docs hosted on GitHub (or anywhere) based on file paths relative to the directory of a cloned Git repository. However, I believe that this ability will also benefit others.
I've included support for all existing services. Gists were the only tricky one as there doesn't appear to be a URL for viewing a single Gist file in the browser, only single raw files. However, the URL generated for Gists does work but it has to use a hash fragment, which required some regexp replacing on the path as non-
[a-zA-Z0-9_]
characters are replaced with hyphens and the/
character is not allowed at all (which makes sense since Gists can only have a flat directory structure) and also transformed to lower case. While doing this work, I've also added the ability to specify hash fragments for files. The fragment option is supported by all except Gists, as they're already using the hash fragment for the file path itself.I've tried to avoid introducing a breaking change by simply extending the existing
browse
method to accept a path as an optional first parameter. Basically, allowingbrowse
to be used as follows:I've also updated the documentation for
browse
inREADME.md
, but I don't know if you want me to expand further on the optional aspect of thepath
andfragment
parameters.