diff --git a/lib/ex_doc.ex b/lib/ex_doc.ex index 116d24230..102037f9e 100644 --- a/lib/ex_doc.ex +++ b/lib/ex_doc.ex @@ -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 diff --git a/lib/ex_doc/cli.ex b/lib/ex_doc/cli.ex index 585b5967e..2d63deaed 100644 --- a/lib/ex_doc/cli.ex +++ b/lib/ex_doc/cli.ex @@ -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 @@ -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 diff --git a/lib/mix_docs.ex b/lib/mix_docs.ex index e6e02c07f..1c72e5cb4 100644 --- a/lib/mix_docs.ex +++ b/lib/mix_docs.ex @@ -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.