1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
defmodule ExDoc.Formatter.EPUB.Templates do
@moduledoc false
require EEx
import ExDoc.Utils,
only: [before_closing_body_tag: 2, before_closing_head_tag: 2, h: 1, text_to_id: 1]
alias ExDoc.Formatter.HTML.Templates, as: H
@doc """
Generate content from the module template for a given `node`
"""
def module_page(config, module_node) do
summary = H.module_summary(module_node)
module_template(config, module_node, summary)
end
@doc """
Generated ID for static file
"""
def static_file_to_id(static_file) do
static_file |> Path.basename() |> text_to_id()
end
@doc """
Creates the Package Document Definition.
this definition encapsulates the publication metadata and the resource
information that constitute the EPUB publication. This definition also
includes the default reading order.
See http://www.idpf.org/epub/30/spec/epub30-publications.html#sec-package-def.
"""
EEx.function_from_file(
:def,
:content_template,
Path.expand("templates/content_template.eex", __DIR__),
[:config, :nodes, :uuid, :datetime, :static_files],
trim: true
)
@doc """
Creates a chapter which contains all the details about an individual module.
This chapter can include the following sections: *functions*, *types*, *callbacks*.
"""
EEx.function_from_file(
:def,
:module_template,
Path.expand("templates/module_template.eex", __DIR__),
[:config, :module, :summary],
trim: true
)
@doc """
Creates the table of contents.
This template follows the EPUB Navigation Document Definition.
See http://www.idpf.org/epub/30/spec/epub30-contentdocs.html#sec-xhtml-nav.
"""
EEx.function_from_file(
:def,
:nav_template,
Path.expand("templates/nav_template.eex", __DIR__),
[:config, :nodes],
trim: true
)
@doc """
Creates a new chapter when the user provides additional files.
"""
EEx.function_from_file(
:def,
:extra_template,
Path.expand("templates/extra_template.eex", __DIR__),
[:config, :title, :title_content, :content],
trim: true
)
@doc """
Creates the cover page for the EPUB document.
"""
EEx.function_from_file(
:def,
:title_template,
Path.expand("templates/title_template.eex", __DIR__),
[:config],
trim: true
)
EEx.function_from_file(
:defp,
:head_template,
Path.expand("templates/head_template.eex", __DIR__),
[:config, :page],
trim: true
)
EEx.function_from_file(
:defp,
:nav_item_template,
Path.expand("templates/nav_item_template.eex", __DIR__),
[:name, :nodes],
trim: true
)
EEx.function_from_file(
:defp,
:nav_grouped_item_template,
Path.expand("templates/nav_grouped_item_template.eex", __DIR__),
[:nodes],
trim: true
)
EEx.function_from_file(
:defp,
:toc_item_template,
Path.expand("templates/toc_item_template.eex", __DIR__),
[:nodes],
trim: true
)
"templates/media-types.txt"
|> Path.expand(__DIR__)
|> File.read!()
|> String.split("\n", trim: true)
|> Enum.each(fn line ->
[extension, media] = String.split(line, ",")
def media_type("." <> unquote(extension)) do
unquote(media)
end
end)
def media_type(_arg), do: nil
end
|