Packages
nldoc_conversion_writer_html
1.1.0-alpha.2
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.44
1.2.43
1.2.42
1.2.41
1.2.40
1.2.39
1.2.38
1.2.37
1.2.36
1.2.35
1.2.34
1.2.33
1.2.32
1.2.31
1.2.30
1.2.29
1.2.28
1.2.27
1.2.26
1.2.25
1.2.24
1.2.23
1.2.22
1.2.21
1.2.20
1.2.19
1.2.18
1.2.17
1.2.16
1.2.15
1.2.14
1.2.13
1.2.12
1.2.11
1.2.10
1.2.9
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.0
1.1.0-alpha.2
1.1.0-alpha.1
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
Logic for writing NLdoc Spec to HTML.
Current section
Files
Jump to
Current section
Files
lib/nldoc/conversion/writer/html/head.ex
defmodule NLdoc.Conversion.Writer.Html.Head do
@moduledoc false
alias NLdoc.Conversion.Writer.Html.SimpleForm
alias NLdoc.Spec.{Document, StringDescriptor}
@spec element(Document.t()) :: Floki.html_node()
@doc """
Generates head-element based on document.
## Examples
iex> NLdoc.Conversion.Writer.Html.Head.element(
...> %NLdoc.Spec.Document{
...> descriptors: [
...> %NLdoc.Spec.StringDescriptor{
...> uri: "http://purl.org/dc/elements/1.1/creator",
...> value: "Example Creator"},
...> %NLdoc.Spec.StringDescriptor{
...> uri: "http://example.com/unsupported",
...> value: "Unsupported thus will be skipped."},
...> %NLdoc.Spec.StringDescriptor{
...> uri: "http://purl.org/dc/elements/1.1/description",
...> value: "Example Description"},
...> %NLdoc.Spec.StringDescriptor{
...> uri: "http://purl.org/dc/elements/1.1/title",
...> value: "Example Title"}]})
{"head", [], [
{"style", [], [
".lst-circle { list-style-type: circle; }",
".lst-square { list-style-type: square; }",
"section.footnotes { border-top: 1px solid; }"]},
{"meta", [{"name", "author"}, {"content", "Example Creator"}], []},
{"meta", [{"name", "description"}, {"content", "Example Description"}], []},
{"title", [], ["Example Title"]}]}
"""
def element(%Document{descriptors: descriptors}),
do:
"head"
|> SimpleForm.tag()
|> SimpleForm.put_children(descriptors |> Enum.flat_map(&descriptor_to_meta/1))
|> SimpleForm.prepend_child(
"style"
|> SimpleForm.tag()
|> SimpleForm.put_children([
".lst-circle { list-style-type: circle; }",
".lst-square { list-style-type: square; }",
"section.footnotes { border-top: 1px solid; }"
])
)
@spec descriptor_to_meta(StringDescriptor.t()) :: [Floki.html_node()]
defp descriptor_to_meta(%StringDescriptor{
uri: "http://purl.org/dc/elements/1.1/creator",
value: value
}),
do: [meta_tag("author", value)]
defp descriptor_to_meta(%StringDescriptor{
uri: "http://purl.org/dc/elements/1.1/description",
value: value
}),
do: [meta_tag("description", value)]
defp descriptor_to_meta(%StringDescriptor{
uri: "http://purl.org/dc/elements/1.1/title",
value: value
}),
do: [title_tag(value)]
defp descriptor_to_meta(_),
do: []
@spec title_tag(String.t()) :: Floki.html_tag()
defp title_tag(content), do: {"title", [], [content]}
@spec meta_tag(String.t(), String.t()) :: Floki.html_tag()
defp meta_tag(name, content),
do: {"meta", [{"name", name}, {"content", content}], []}
end