From cdec207d130dd543fe265745e5b77d44f8576b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Wed, 24 May 2017 15:51:53 +0200 Subject: [PATCH] Handle missing project version --- lib/ex_doc/formatter/epub.ex | 10 +++++++++- .../formatter/epub/templates/content_template.eex | 2 +- lib/ex_doc/formatter/epub/templates/head_template.eex | 2 +- .../formatter/epub/templates/title_template.eex | 2 +- .../html/templates/api_reference_template.eex | 2 +- lib/ex_doc/formatter/html/templates/head_template.eex | 2 +- .../formatter/html/templates/module_template.eex | 2 +- .../formatter/html/templates/redirect_template.eex | 2 +- .../formatter/html/templates/sidebar_template.eex | 8 +++++--- lib/mix/tasks/docs.ex | 11 +---------- test/mix/tasks/docs_test.exs | 10 ++-------- 11 files changed, 24 insertions(+), 29 deletions(-) diff --git a/lib/ex_doc/formatter/epub.ex b/lib/ex_doc/formatter/epub.ex index 23268bdde..159b9971a 100644 --- a/lib/ex_doc/formatter/epub.ex +++ b/lib/ex_doc/formatter/epub.ex @@ -51,10 +51,18 @@ defmodule ExDoc.Formatter.EPUB do output = config.output |> Path.expand() - |> Path.join("#{config.project}-v#{config.version}") + |> Path.join(project_directory(config)) %{config | output: output} end + defp project_directory(config) do + if config.version do + "#{config.project}-v#{config.version}" + else + config.project + end + end + defp generate_extras(config) do for {_title, extras} <- config.extras do Enum.each(extras, fn %{id: id, title: title, content: content} -> diff --git a/lib/ex_doc/formatter/epub/templates/content_template.eex b/lib/ex_doc/formatter/epub/templates/content_template.eex index 3cae5062d..abda7dc7a 100644 --- a/lib/ex_doc/formatter/epub/templates/content_template.eex +++ b/lib/ex_doc/formatter/epub/templates/content_template.eex @@ -3,7 +3,7 @@ unique-identifier="project-<%= config.project %>" version="3.0"> - <%= config.project %> - <%= config.version %> + <%= config.project %> <%= if config.version do %> - <%= config.version %><% end %> <%= uuid %> <%= config.language %> <%= datetime %> diff --git a/lib/ex_doc/formatter/epub/templates/head_template.eex b/lib/ex_doc/formatter/epub/templates/head_template.eex index 7ae5eb853..5bb3cfab3 100644 --- a/lib/ex_doc/formatter/epub/templates/head_template.eex +++ b/lib/ex_doc/formatter/epub/templates/head_template.eex @@ -3,7 +3,7 @@ xmlns:epub="http://www.idpf.org/2007/ops"> - <%= page.title %> - <%= config.project %> v<%= config.version %> + <%= page.title %> - <%= config.project %><%= if config.version do %> v<%= config.version %><% end %> " /> diff --git a/lib/ex_doc/formatter/epub/templates/title_template.eex b/lib/ex_doc/formatter/epub/templates/title_template.eex index cf8a33223..0ba36cab4 100644 --- a/lib/ex_doc/formatter/epub/templates/title_template.eex +++ b/lib/ex_doc/formatter/epub/templates/title_template.eex @@ -1,7 +1,7 @@ <%= head_template(config, %{title: "Cover"}) %>

<%= config.project %>

-

v<%= config.version %>

+ <%= if config.version do %>

v<%= config.version %>

<% end %> <%= if logo = config.logo do %>
Logo
<% end %> diff --git a/lib/ex_doc/formatter/html/templates/api_reference_template.eex b/lib/ex_doc/formatter/html/templates/api_reference_template.eex index a11bd1f6e..dca6779e1 100644 --- a/lib/ex_doc/formatter/html/templates/api_reference_template.eex +++ b/lib/ex_doc/formatter/html/templates/api_reference_template.eex @@ -1,5 +1,5 @@

- <%= config.project %> v<%= config.version %> + <%= config.project %> <%= if config.version do %>v<%= config.version %><% end %> API Reference

diff --git a/lib/ex_doc/formatter/html/templates/head_template.eex b/lib/ex_doc/formatter/html/templates/head_template.eex index 9b61c4979..d690b3399 100644 --- a/lib/ex_doc/formatter/html/templates/head_template.eex +++ b/lib/ex_doc/formatter/html/templates/head_template.eex @@ -5,7 +5,7 @@ - <%= page.title %> – <%= config.project %> v<%= config.version %> + <%= page.title %> – <%= config.project %><%= if config.version do %> v<%= config.version %><% end %> " /> <%= if config.canonical do %> diff --git a/lib/ex_doc/formatter/html/templates/module_template.eex b/lib/ex_doc/formatter/html/templates/module_template.eex index 34cfd2d67..acc88bace 100644 --- a/lib/ex_doc/formatter/html/templates/module_template.eex +++ b/lib/ex_doc/formatter/html/templates/module_template.eex @@ -2,7 +2,7 @@ <%= sidebar_template(config, nodes_map) %>

- <%= config.project %> v<%= config.version %> + <%= config.project %><%= if config.version do %> v<%= config.version %><% end %> <%= module_title(module) %> <%= if module.source_url do %> diff --git a/lib/ex_doc/formatter/html/templates/redirect_template.eex b/lib/ex_doc/formatter/html/templates/redirect_template.eex index aec7172b0..653d41f05 100644 --- a/lib/ex_doc/formatter/html/templates/redirect_template.eex +++ b/lib/ex_doc/formatter/html/templates/redirect_template.eex @@ -2,7 +2,7 @@ - <%= config.project %> v<%= config.version %> – Documentation + <%= config.project %><%= if config.version do %> v<%= config.version %><% end %> – Documentation diff --git a/lib/ex_doc/formatter/html/templates/sidebar_template.eex b/lib/ex_doc/formatter/html/templates/sidebar_template.eex index 3356da3e7..20158b7d5 100644 --- a/lib/ex_doc/formatter/html/templates/sidebar_template.eex +++ b/lib/ex_doc/formatter/html/templates/sidebar_template.eex @@ -11,9 +11,11 @@

<%= config.project %>

- + <%= if config.version do %> + + <% end %>

<%= if config.logo do %> <%= config.project %> diff --git a/lib/mix/tasks/docs.ex b/lib/mix/tasks/docs.ex index 86a842e56..ea72f4848 100644 --- a/lib/mix/tasks/docs.ex +++ b/lib/mix/tasks/docs.ex @@ -122,7 +122,7 @@ defmodule Mix.Tasks.Docs do end project = to_string(config[:name] || config[:app]) - version = fetch_version!(config) + version = config[:version] options = config |> get_docs_opts() @@ -140,15 +140,6 @@ defmodule Mix.Tasks.Docs do end end - defp fetch_version!(config) do - case Keyword.fetch(config, :version) do - {:ok, version} -> - version - :error -> - raise ArgumentError, ":version key is required in config, got: #{inspect(config)}" - end - end - defp get_formatters(options) do case Keyword.get_values(options, :formatter) do [] -> options[:formatters] || [ExDoc.Config.default(:formatter)] diff --git a/test/mix/tasks/docs_test.exs b/test/mix/tasks/docs_test.exs index b81379c31..d770f4b4d 100644 --- a/test/mix/tasks/docs_test.exs +++ b/test/mix/tasks/docs_test.exs @@ -90,8 +90,8 @@ defmodule Mix.Tasks.DocsTest do test "supports umbrella project" do Mix.Project.in_project(:umbrella, "test/fixtures/umbrella", fn _mod -> - assert [{"umbrella", "1.2.3-dev", [formatter: "html", deps: deps, source_beam: _]}] = - run([], [app: :umbrella, apps_path: "apps/", version: "1.2.3-dev"]) + assert [{"umbrella", nil, [formatter: "html", deps: deps, source_beam: _]}] = + run([], [app: :umbrella, apps_path: "apps/"]) assert List.keyfind(deps, Application.app_dir(:foo), 0) == {Application.app_dir(:foo), "https://hexdocs.pm/foo/0.1.0/"} @@ -99,10 +99,4 @@ defmodule Mix.Tasks.DocsTest do {Application.app_dir(:bar), "https://hexdocs.pm/bar/0.1.0/"} end) end - - test "raise when version is not provided" do - assert_raise ArgumentError, ~r/:version key is required in config, got: /, fn -> - run([], [app: :ex_doc]) - end - end end