From 87bc2877108c7e288a8944ee7f917f80f299ffe3 Mon Sep 17 00:00:00 2001 From: Milton Mazzarri Date: Tue, 20 Sep 2016 16:11:24 -0500 Subject: [PATCH] Reuse head_template as much as possible --- lib/ex_doc/formatter/epub.ex | 14 +++++++------- lib/ex_doc/formatter/epub/templates.ex | 2 +- .../epub/templates/extra_template.eex | 11 +---------- .../epub/templates/head_template.eex | 2 +- .../epub/templates/module_template.eex | 11 +---------- .../formatter/epub/templates/nav_template.eex | 2 +- .../epub/templates/title_template.eex | 2 +- test/ex_doc/formatter/epub_test.exs | 19 +++++++++---------- 8 files changed, 22 insertions(+), 41 deletions(-) diff --git a/lib/ex_doc/formatter/epub.ex b/lib/ex_doc/formatter/epub.ex index 32a7ca908..a150ff146 100644 --- a/lib/ex_doc/formatter/epub.ex +++ b/lib/ex_doc/formatter/epub.ex @@ -58,23 +58,23 @@ defmodule ExDoc.Formatter.EPUB do defp generate_extras(output, config, module_nodes) do config.extras |> Enum.map(&Task.async(fn -> - generate_extra(&1, output, config, module_nodes) + create_extra_files(&1, output, config, module_nodes) end)) |> Enum.map(&Task.await(&1, :infinity)) end - defp generate_extra(input, output, config, module_nodes) do + defp create_extra_files(input, output, config, module_nodes) do if HTML.valid_extension_name?(input) do - file_name = - input - |> Path.basename(".md") - |> String.upcase() - content = input |> File.read!() |> HTML.Autolink.project_doc(module_nodes, nil, ".xhtml") + file_name = + input + |> Path.basename(".md") + |> String.upcase() + config = Map.put(config, :title, file_name) extra_html = config diff --git a/lib/ex_doc/formatter/epub/templates.ex b/lib/ex_doc/formatter/epub/templates.ex index 239fe3502..bb03fb009 100644 --- a/lib/ex_doc/formatter/epub/templates.ex +++ b/lib/ex_doc/formatter/epub/templates.ex @@ -67,7 +67,7 @@ defmodule ExDoc.Formatter.EPUB.Templates do EEx.function_from_file(:defp, :head_template, Path.expand("templates/head_template.eex", __DIR__), - [:config]) + [:config, :page]) # Helpers defp extra_title(path), do: path |> String.upcase |> Path.basename(".MD") diff --git a/lib/ex_doc/formatter/epub/templates/extra_template.eex b/lib/ex_doc/formatter/epub/templates/extra_template.eex index 1b0b0e5f8..9b2b987c0 100644 --- a/lib/ex_doc/formatter/epub/templates/extra_template.eex +++ b/lib/ex_doc/formatter/epub/templates/extra_template.eex @@ -1,13 +1,4 @@ - - - - - <%= extra_title(config.title) %> - <%= config.project %> v<%= config.version %> - - - - +<%= head_template(config, %{title: extra_title(config.title)}) %>

<%= extra_title(config.title) %>

<%= H.to_html(content) %> diff --git a/lib/ex_doc/formatter/epub/templates/head_template.eex b/lib/ex_doc/formatter/epub/templates/head_template.eex index e89707d8a..57f7505a8 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"> - <%= config.project %> v<%= config.version %> + <%= page.title %> - <%= config.project %> v<%= config.version %> diff --git a/lib/ex_doc/formatter/epub/templates/module_template.eex b/lib/ex_doc/formatter/epub/templates/module_template.eex index c62543ccd..5f9e0ef20 100644 --- a/lib/ex_doc/formatter/epub/templates/module_template.eex +++ b/lib/ex_doc/formatter/epub/templates/module_template.eex @@ -1,13 +1,4 @@ - - - - - <%= module.id %> - <%= config.project %> v<%= config.version %> - - - - +<%= head_template(config, %{title: module.id}) %>

<%= module.id %> <%= if module.type != :module do %> diff --git a/lib/ex_doc/formatter/epub/templates/nav_template.eex b/lib/ex_doc/formatter/epub/templates/nav_template.eex index bf3689462..1f781d801 100644 --- a/lib/ex_doc/formatter/epub/templates/nav_template.eex +++ b/lib/ex_doc/formatter/epub/templates/nav_template.eex @@ -1,4 +1,4 @@ -<%= head_template(config) %> +<%= head_template(config, %{title: "Table Of Contents"}) %>

Table of contents