Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/ex_doc/formatter/epub.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ defmodule ExDoc.Formatter.EPUB do

defp generate_content(config, nodes, uuid, datetime, static_files) do
static_files =
Enum.filter(static_files, fn(name) ->
String.contains?(name, "OEBPS") and config.output |> Path.join(name) |> File.regular?()
static_files
|> Enum.filter(fn(name) ->
String.contains?(name, "OEBPS") and config.output |> Path.join(name) |> File.regular?()
end)
|> Enum.map(&Path.relative_to(&1, "OEBPS"))

Expand Down Expand Up @@ -121,7 +122,7 @@ defmodule ExDoc.Formatter.EPUB do

## Helpers

defp default_assets() do
defp default_assets do
[{Assets.dist(), "OEBPS/dist"}, {Assets.metainfo(), "META-INF"}]
end

Expand Down
6 changes: 4 additions & 2 deletions lib/ex_doc/formatter/epub/assets.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule ExDoc.Formatter.EPUB.Assets do
@moduledoc false

@assets_dir Application.app_dir(:ex_doc, "priv/ex_doc/formatter/epub/assets")

defmacrop embed_dir(dir) do
Expand All @@ -8,11 +10,11 @@ defmodule ExDoc.Formatter.EPUB.Assets do
|> Enum.map(&{Path.basename(&1), File.read!(&1)})
end

def dist() do
def dist do
embed_dir("dist")
end

def metainfo() do
def metainfo do
embed_dir("metainfo")
end
end
2 changes: 1 addition & 1 deletion lib/ex_doc/formatter/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ defmodule ExDoc.Formatter.HTML do
end)
end

defp default_assets() do
defp default_assets do
[{Assets.dist(), "dist"}, {Assets.fonts(), "fonts"}]
end

Expand Down
6 changes: 4 additions & 2 deletions lib/ex_doc/formatter/html/assets.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule ExDoc.Formatter.HTML.Assets do
@moduledoc false

@assets_dir Application.app_dir(:ex_doc, "priv/ex_doc/formatter/html/assets")

defmacrop embed_dir(dir) do
Expand All @@ -8,11 +10,11 @@ defmodule ExDoc.Formatter.HTML.Assets do
|> Enum.map(&{Path.basename(&1), File.read!(&1)})
end

def dist() do
def dist do
embed_dir("dist")
end

def fonts() do
def fonts do
embed_dir("fonts")
end
end
6 changes: 3 additions & 3 deletions lib/ex_doc/formatter/html/autolink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ defmodule ExDoc.Formatter.HTML.Autolink do
will get translated to the new href of the function.
"""
def local_doc(bin, locals) when is_binary(bin) do
fun_re = ~r{(([ct]:)?([a-z_]+[A-Za-z_\d]*[\\?\\!]?|[\{\}=&\\|\\.<>~*^@\\+\\%\\!-]+)/\d+)} |> Regex.source
fun_re = Regex.source(~r{(([ct]:)?([a-z_]+[A-Za-z_\d]*[\\?\\!]?|[\{\}=&\\|\\.<>~*^@\\+\\%\\!-]+)/\d+)})
regex = ~r{(?<!\[)`\s*(#{fun_re})\s*`(?!\])}
Regex.replace(regex, bin, fn all, match ->
if match in locals do
Expand Down Expand Up @@ -258,8 +258,8 @@ defmodule ExDoc.Formatter.HTML.Autolink do
will get translated to the new href of the function.
"""
def elixir_functions(bin, project_funs, extension \\ ".html", lib_dirs \\ elixir_lib_dirs()) when is_binary(bin) do
module_re = ~r{(([A-Z][A-Za-z_\d]+)\.)+} |> Regex.source
fun_re = ~r{([ct]:)?(#{module_re}([a-z_]+[A-Za-z_\d]*[\\?\\!]?|[\{\}=&\\|\\.<>~*^@\\+\\%\\!-]+)/\d+)} |> Regex.source
module_re = Regex.source(~r{(([A-Z][A-Za-z_\d]+)\.)+})
fun_re = Regex.source(~r{([ct]:)?(#{module_re}([a-z_]+[A-Za-z_\d]*[\\?\\!]?|[\{\}=&\\|\\.<>~*^@\\+\\%\\!-]+)/\d+)})
regex = ~r{(?<!\[)`\s*(#{fun_re})\s*`(?!\])}

Regex.replace(regex, bin, fn all, match ->
Expand Down
6 changes: 3 additions & 3 deletions lib/ex_doc/markdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule ExDoc.Markdown do
bin
end

defp get_markdown_processor() do
defp get_markdown_processor do
case Application.fetch_env(:ex_doc, @markdown_processor_key) do
{:ok, processor} ->
processor
Expand All @@ -58,13 +58,13 @@ defmodule ExDoc.Markdown do
end
end

defp find_markdown_processor() do
defp find_markdown_processor do
Enum.find @markdown_processors, fn module ->
Code.ensure_loaded?(module) && module.available?
end
end

defp raise_no_markdown_processor() do
defp raise_no_markdown_processor do
raise """
Could not find a markdown processor to be used by ex_doc.
You can either:
Expand Down
2 changes: 1 addition & 1 deletion lib/ex_doc/retriever.ex
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ defmodule ExDoc.Retriever do
end

defp source_path(module, config) do
source = module.__info__(:compile)[:source] |> String.Chars.to_string
source = String.Chars.to_string(module.__info__(:compile)[:source])

if root = config.source_root do
Path.relative_to(source, root)
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ defmodule Mix.Tasks.Docs do
Keyword.put(options, :deps, deps)
end

defp get_deps() do
defp get_deps do
for {key, _} <- Mix.Project.deps_paths,
_ = Application.load(key), # :ok | {:error, _}
vsn = Application.spec(key, :vsn) do
Expand Down
21 changes: 0 additions & 21 deletions test/ex_doc/formatter/epub/templates_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,6 @@ defmodule ExDoc.Formatter.EPUB.TemplatesTest do
assert content =~ ~s{example(foo, bar \\\\ Baz)}
end

test "module_page outputs the types and function specs" do
content = get_module_page([TypesAndSpecs, TypesAndSpecs.Sub])

public_html =
~S[public(t) :: {t, ] <>
~s[<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>, ] <>
~S[<a href="TypesAndSpecs.Sub.html#t:t/0">TypesAndSpecs.Sub.t</a>, ] <>
~S[<a href="#t:opaque/0">opaque</a>, :ok | :error}]

ref_html = ~S[ref() :: {:binary.part, <a href="#t:public/1">public(any)</a>}]

assert content =~ ~s[<a href="#t:public/1">public(t)</a>]
refute content =~ ~s[<a href="#t:private/0">private</a>]
assert content =~ public_html
assert content =~ ref_html
refute content =~ ~s[<strong>private\(t\)]
assert content =~ ~s[A public type]
assert content =~ ~s[add(integer, <a href="#t:opaque/0">opaque</a>) :: integer]
refute content =~ ~s[minus(integer, integer) :: integer]
end

test "module_page outputs summaries" do
content = get_module_page([CompiledWithDocs])
assert content =~ ~r{<div class="summary-signature">\s*<a href="#example_1/0">}
Expand Down
2 changes: 1 addition & 1 deletion test/ex_doc/formatter/epub_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule ExDoc.Formatter.EPUBTest do

defp generate_docs_and_unzip(options) do
generate_docs(options)
unzip_dir = "#{doc_config()[:output]}" |> String.to_char_list
unzip_dir = String.to_char_list("#{doc_config()[:output]}")
"#{doc_config()[:output]}/#{doc_config()[:project]}-v#{doc_config()[:version]}.epub"
|> String.to_char_list
|> :zip.unzip([cwd: unzip_dir])
Expand Down