Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/ex_doc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ defmodule ExDoc do
# Helpers

defp normalize_options(options) do
pattern = options[:source_url_pattern] || guess_url(options[:source_url])
pattern = options[:source_url_pattern] || guess_url(options[:source_url], options[:source_ref] || "master")
Keyword.put(options, :source_url_pattern, pattern)
end

defp guess_url(url = <<"https://github.com/", _ :: binary>>) do
append_slash(url) <> "blob/master/%{path}#L%{line}"
defp guess_url(url = <<"https://github.com/", _ :: binary>>, ref) do
append_slash(url) <> "blob/#{ref}/%{path}#L%{line}"
end

defp guess_url(url = <<"https://bitbucket.org/", _ :: binary>>) do
append_slash(url) <> "src/master/%{path}?at=master#cl-%{line}"
defp guess_url(url = <<"https://bitbucket.org/", _ :: binary>>, ref) do
append_slash(url) <> "src/#{ref}/%{path}#cl-%{line}"
end

defp guess_url(other) do
defp guess_url(other, _) do
other
end

Expand Down
9 changes: 9 additions & 0 deletions lib/ex_doc/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ defmodule ExDoc.CLI do
-f, --formatter Docs formatter to use, default: ExDoc.HTMLFormatter
-r, --source-root Path to the source code root, default: .
-u, --source-url URL to the source code
--source-ref Branch/commit/tag used for source link inference, default: master
-m, --main The main, entry-point module in docs

## Source linking
Expand All @@ -48,6 +49,14 @@ defmodule ExDoc.CLI do

https://github.com/elixir-lang/dynamo/blob/master/%{path}#L%{line}

To specify a particular branch or commit, use the `--source-ref` option:

--source-url "https://github.com/elixir-lang/dynamo" --source-ref "v1.0"

will result in the following URL pattern:

https://github.com/elixir-lang/dynamo/blob/v1.0/%{path}#L%{line}

"""
exit(1)
end
Expand Down
3 changes: 3 additions & 0 deletions lib/mix_docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ defmodule Mix.Tasks.Docs do
* `:source_url_pattern` - public URL of the project.
Derived from project's `:source_url` if not present.

* `:source_ref` - the branch/commit/tag used for source link inference.
Ignored if `:source_url_pattern` is provided. Defaults to _master_.

* `:main` - main module of the project, will be shown on the starting page.
Derived from project's `:app` if not present.

Expand Down