Current section

Files

Jump to
meeseeks lib meeseeks document node.ex
Raw

lib/meeseeks/document/node.ex

defmodule Meeseeks.Document.Node do
@moduledoc false
alias Meeseeks.{Document, TupleTree}
@type t :: struct
@callback attr(node :: t, attribute :: String.t) :: String.t | nil
@callback attrs(node :: t) :: [{String.t, String.t}] | nil
@callback data(node :: t, document :: Document.t) :: String.t
@callback html(node :: t, document :: Document.t) :: String.t
@callback own_text(node :: t, document :: Document.t) :: String.t
@callback tag(node :: t) :: String.t | nil
@callback text(node :: t, document :: Document.t) :: String.t
@callback tree(node :: t, document :: Document.t) :: TupleTree.node_t
# attr
@spec attr(t, String.t) :: String.t | nil
def attr(%{__struct__: struct} = node, attribute) do
struct.attr(node, attribute)
end
# attrs
@spec attrs(t) :: [{String.t, String.t}] | nil
def attrs(%{__struct__: struct} = node) do
struct.attrs(node)
end
# data
@spec data(t, Document.t) :: String.t
def data(%{__struct__: struct} = node, document) do
struct.data(node, document)
end
# html
@spec html(t, Document.t) :: String.t
def html(%{__struct__: struct} = node, document) do
struct.html(node, document)
end
# own_text
@spec own_text(t, Document.t) :: String.t
def own_text(%{__struct__: struct} = node, document) do
struct.own_text(node, document)
end
# tag
@spec tag(t) :: String.t | nil
def tag(%{__struct__: struct} = node) do
struct.tag(node)
end
# text
@spec text(t, Document.t) :: String.t
def text(%{__struct__: struct} = node, document) do
struct.text(node, document)
end
# tree
@spec tree(t, Document.t) :: TupleTree.node_t
def tree(%{__struct__: struct} = node, document) do
struct.tree(node, document)
end
# __using__
defmacro __using__(_) do
quote do
@behaviour Document.Node
def attr(_, _), do: nil
def attrs(_), do: nil
def data(_, _), do: ""
def html(_, _), do: raise "html/2 not implemented"
def own_text(_, _), do: ""
def tag(_), do: nil
def text(_, _), do: ""
def tree(_, _), do: raise "tree/2 not implemented"
defoverridable attr: 2, attrs: 1, data: 2, html: 2, own_text: 2, tag: 1, text: 2, tree: 2
end
end
end