Skip to content

Commit

Permalink
Move module and extra pages to the OEBPS folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Milton Mazzarri committed Sep 20, 2016
1 parent ea4b082 commit ba7779f
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 32 deletions.
6 changes: 3 additions & 3 deletions lib/ex_doc/formatter/epub.ex
Expand Up @@ -13,7 +13,7 @@ defmodule ExDoc.Formatter.EPUB do
def run(module_nodes, config) when is_map(config) do
output = Path.expand(config.output)
File.rm_rf!(output)
File.mkdir_p!("#{output}/OEBPS/modules")
File.mkdir_p!("#{output}/OEBPS")

assets() |> HTML.assets_path("epub") |> HTML.generate_assets(output)

Expand Down Expand Up @@ -80,7 +80,7 @@ defmodule ExDoc.Formatter.EPUB do
config
|> Templates.extra_template(content)

File.write!("#{output}/OEBPS/modules/#{file_name}.xhtml", extra_html)
File.write!("#{output}/OEBPS/#{file_name}.xhtml", extra_html)
else
raise ArgumentError, "file format not recognized, allowed format is: .md"
end
Expand Down Expand Up @@ -168,7 +168,7 @@ defmodule ExDoc.Formatter.EPUB do

defp generate_module_page(output, config, node) do
content = Templates.module_page(config, node)
File.write("#{output}/OEBPS/modules/#{node.id}.xhtml", content)
File.write("#{output}/OEBPS/#{node.id}.xhtml", content)
end

# Helper to generate an UUID v4. This version uses pseudo-random bytes generated by
Expand Down
4 changes: 4 additions & 0 deletions lib/ex_doc/formatter/epub/templates.ex
Expand Up @@ -65,6 +65,10 @@ defmodule ExDoc.Formatter.EPUB.Templates do
Path.expand("templates/toc_template.eex", __DIR__),
[:config, :nodes, :uuid])

EEx.function_from_file(:defp, :head_template,
Path.expand("templates/head_template.eex", __DIR__),
[:config])

# Helpers
defp extra_title(path), do: path |> String.upcase |> Path.basename(".MD")
end
4 changes: 2 additions & 2 deletions lib/ex_doc/formatter/epub/templates/content_template.eex
Expand Up @@ -13,10 +13,10 @@
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="cover" href="title.xhtml" media-type="application/xhtml+xml"/>
<%= for extra <- config.extras do %>
<item id="<%= extra_title(extra) %>" href="modules/<%= extra_title(extra) %>.xhtml" media-type="application/xhtml+xml"/>
<item id="<%= extra_title(extra) %>" href="<%= extra_title(extra) %>.xhtml" media-type="application/xhtml+xml"/>
<% end %>
<%= for node <- nodes do %>
<item id="<%= node.id %>" href="modules/<%= node.id %>.xhtml" media-type="application/xhtml+xml"/>
<item id="<%= node.id %>" href="<%= node.id %>.xhtml" media-type="application/xhtml+xml"/>
<% end %>
<item id="css" href="css/stylesheet.css" media-type="text/css"/>
<%= if config.logo do %>
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_doc/formatter/epub/templates/extra_template.eex
Expand Up @@ -4,8 +4,8 @@
<head>
<meta charset="utf-8" />
<title><%= extra_title(config.title) %> - <%= config.project %> v<%= config.version %></title>
<meta name="generator" content="ExDoc" />
<link type="text/css" rel="stylesheet" href="../css/stylesheet.css" />
<meta name="generator" content="ExDoc v<%= ExDoc.version %>" />
<link type="text/css" rel="stylesheet" href="css/stylesheet.css" />
</head>
<body>
<h1><%= extra_title(config.title) %></h1>
Expand Down
10 changes: 10 additions & 0 deletions lib/ex_doc/formatter/epub/templates/head_template.eex
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta charset="utf-8" />
<title><%= config.project %> v<%= config.version %></title>
<meta name="generator" content="ExDoc v<%= ExDoc.version %>" />
<link type="text/css" rel="stylesheet" href="css/stylesheet.css" />
</head>
<body>
2 changes: 1 addition & 1 deletion lib/ex_doc/formatter/epub/templates/module_template.eex
Expand Up @@ -5,7 +5,7 @@
<meta charset="utf-8" />
<title><%= module.id %> - <%= config.project %> v<%= config.version %></title>
<meta name="generator" content="ExDoc" />
<link type="text/css" rel="stylesheet" href="../css/stylesheet.css" />
<link type="text/css" rel="stylesheet" href="css/stylesheet.css" />
</head>
<body>
<h1 id="content">
Expand Down
15 changes: 3 additions & 12 deletions lib/ex_doc/formatter/epub/templates/nav_template.eex
@@ -1,21 +1,12 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta charset="utf-8" />
<title><%= config.project %> v<%= config.version %></title>
<meta name="generator" content="ExDoc" />
<link type="text/css" rel="stylesheet" href="css/stylesheet.css" />
</head>
<body>
<%= head_template(config) %>
<h1>Table of contents</h1>
<nav epub:type="toc">
<ol>
<%= for extra <- config.extras do %>
<li><a href="modules/<%= extra_title(extra) %>.xhtml"><%= extra_title(extra) %></a></li>
<li><a href="<%= extra_title(extra) %>.xhtml"><%= extra_title(extra) %></a></li>
<% end %>
<%= for node <- nodes do %>
<li><a href="modules/<%= node.id %>.xhtml"><%= node.id %></a></li>
<li><a href="<%= node.id %>.xhtml"><%= node.id %></a></li>
<% end %>
</ol>
</nav>
Expand Down
11 changes: 1 addition & 10 deletions lib/ex_doc/formatter/epub/templates/title_template.eex
@@ -1,13 +1,4 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta charset="utf-8" />
<title><%= config.project %> v<%= config.version %></title>
<meta name="generator" content="ExDoc" />
<link type="text/css" rel="stylesheet" href="css/stylesheet.css" />
</head>
<body>
<%= head_template(config) %>
<h1><%= config.project %></h1>
<h2>v<%= config.version %></h2>
<%= if config.logo do %>
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_doc/formatter/epub/templates/toc_template.eex
Expand Up @@ -24,7 +24,7 @@
<navLabel>
<text><%= extra_title(extra) %></text>
</navLabel>
<content src="modules/<%= extra_title(extra) %>.xhtml"/>
<content src="<%= extra_title(extra) %>.xhtml"/>
</navPoint>
<% end %>
<% start_value = Enum.count(config.extras) + 2 %>
Expand All @@ -33,7 +33,7 @@
<navLabel>
<text><%= node.id %></text>
</navLabel>
<content src="modules/<%= node.id %>.xhtml"/>
<content src="<%= node.id %>.xhtml"/>
</navPoint>
<% end %>
</navMap>
Expand Down

0 comments on commit ba7779f

Please sign in to comment.