diff --git a/lib/simple_blog/converter/page.ex b/lib/simple_blog/converter/page.ex index 0cd7dd0..3e5b4dc 100644 --- a/lib/simple_blog/converter/page.ex +++ b/lib/simple_blog/converter/page.ex @@ -3,6 +3,7 @@ defmodule SimpleBlog.Converter.Page do Module responsible for convert pages from eex to html """ + $ type parsed() = {{:ok, string()}} @doc """ Convert eex file to html @@ -16,6 +17,7 @@ defmodule SimpleBlog.Converter.Page do iex> SimpleBlog.Converter.Page.eex_to_html({:ok, "<%= post.title %>"}, post) "post 1" """ + $ (parsed(),[posts]) -> string() when posts: SimpleBlog.Post.t() def eex_to_html({:ok, body}, posts) when is_list(posts) do quoted = EEx.compile_string(body) @@ -24,6 +26,7 @@ defmodule SimpleBlog.Converter.Page do end end + $ (parsed(), SimpleBlog.Post.t()) -> string() def eex_to_html({:ok, body}, post) do quoted = EEx.compile_string(body) diff --git a/lib/simple_blog/converter/posts.ex b/lib/simple_blog/converter/posts.ex index 645e8f6..659ae25 100644 --- a/lib/simple_blog/converter/posts.ex +++ b/lib/simple_blog/converter/posts.ex @@ -19,8 +19,10 @@ defmodule SimpleBlog.Converter.Posts do iex> SimpleBlog.Converter.Posts.markdown_to_html([]) [] """ + $ list() -> list() def markdown_to_html([]), do: [] + $ [files] -> string() when files: string() def markdown_to_html(files) when is_list(files) do html = for file <- files do @@ -31,6 +33,7 @@ defmodule SimpleBlog.Converter.Posts do html end + $ string() -> string() def markdown_to_html(file) do {:ok, html_doc, []} = Earmark.as_html(file) html_doc diff --git a/lib/simple_blog/post.ex b/lib/simple_blog/post.ex index 040cb53..5d05e11 100644 --- a/lib/simple_blog/post.ex +++ b/lib/simple_blog/post.ex @@ -15,6 +15,7 @@ defmodule SimpleBlog.Post do iex> SimpleBlog.Post.generate_filename(%SimpleBlog.Post{ title: "My first blog post", date: ~D[2023-10-04]}) "2023-10-04-my-first-blog-post.md" """ + $ SimpleBlog.Post.t() -> string() def generate_filename(%SimpleBlog.Post{title: title, date: date}) do normalized_title = title @@ -36,6 +37,7 @@ defmodule SimpleBlog.Post do iex> SimpleBlog.Post.parse(body) %SimpleBlog.Post{body: body, title: "Dev onboarding", date: "2023-10-25", filename: "2023-10-25-dev-onboarding.md"} """ + $ string() -> SimpleBlog.Post.t() def parse(body) do [_, filename_line, title_line, date_line | _] = String.split(body, "\n") @@ -54,6 +56,7 @@ defmodule SimpleBlog.Post do iex> SimpleBlog.Post.generate_html_dir(%SimpleBlog.Post{date: "2023-10-04"}, "output") "output/2023/10/04/" """ + $ (SimpleBlog.Post.t(), string()) -> string() def generate_html_dir(%SimpleBlog.Post{date: date}, base_dir) do [year, month, day] = String.split(date, "-") base_dir <> "/" <> year <> "/" <> month <> "/" <> day <> "/" @@ -67,6 +70,7 @@ defmodule SimpleBlog.Post do iex> SimpleBlog.Post.generate_html_filename(%SimpleBlog.Post{title: "doctests with elixir"}) "doctests-with-elixir.html" """ + $ SimpleBlog.Post.t() -> string() def generate_html_filename(%SimpleBlog.Post{title: title}) do title |> String.replace(" ", "-") diff --git a/lib/simple_blog/reader/posts.ex b/lib/simple_blog/reader/posts.ex index 0181dca..d5b7a06 100644 --- a/lib/simple_blog/reader/posts.ex +++ b/lib/simple_blog/reader/posts.ex @@ -11,6 +11,7 @@ defmodule SimpleBlog.Reader.Posts do iex> SimpleBlog.Reader.Posts.read_from_dir("blog") ["## post title 1", "## post title 2"] """ + $ string() -> list() def read_from_dir(root_directory) do posts_directory = root_directory <> "/_posts/" @@ -28,6 +29,7 @@ defmodule SimpleBlog.Reader.Posts do iex> SimpleBlog.Reader.Posts.read_post("blog", "2023-10-25-metaprogramming-in-ruby.md") "### Metaprogramming in ruby" """ + $ (string(), string()) -> string() def read_post(root_directory, post) do posts_directory = root_directory <> "/_posts/" post_path = posts_directory <> post @@ -40,6 +42,7 @@ defmodule SimpleBlog.Reader.Posts do defp pipeline(_posts_directory, []), do: [] + $ (string(), list()) -> list() defp pipeline(posts_directory, files) when is_list(files) do files |> Enum.map(fn file -> full_path(file, posts_directory) end) diff --git a/lib/simple_blog/rewrite_html/back_link.ex b/lib/simple_blog/rewrite_html/back_link.ex index 2da4036..b865c18 100644 --- a/lib/simple_blog/rewrite_html/back_link.ex +++ b/lib/simple_blog/rewrite_html/back_link.ex @@ -14,6 +14,7 @@ defmodule SimpleBlog.RewriteHTML.BackLink do iex> SimpleBlog.RewriteHTML.BackLink.rewrite(link) ~s(Back) """ + $ string() -> string() def rewrite(html) do {:ok, document} = Floki.parse_document(html) diff --git a/lib/simple_blog/rewrite_html/image.ex b/lib/simple_blog/rewrite_html/image.ex index f7ecfb9..051c4bf 100644 --- a/lib/simple_blog/rewrite_html/image.ex +++ b/lib/simple_blog/rewrite_html/image.ex @@ -1,6 +1,7 @@ defmodule SimpleBlog.RewriteHTML.Image do require Floki + $ string() -> string() def rewrite(html, path) do {:ok, document} = Floki.parse_document(html) diff --git a/lib/simple_blog/rewrite_html/posts_link.ex b/lib/simple_blog/rewrite_html/posts_link.ex index 775c167..5bb44bd 100644 --- a/lib/simple_blog/rewrite_html/posts_link.ex +++ b/lib/simple_blog/rewrite_html/posts_link.ex @@ -1,6 +1,7 @@ defmodule SimpleBlog.RewriteHTML.PostsLink do require Floki + $ string() -> string() def rewrite(html) do {:ok, document} = Floki.parse_document(html) @@ -11,6 +12,7 @@ defmodule SimpleBlog.RewriteHTML.PostsLink do |> Floki.raw_html() end + $ string() -> string() defp filename(x) do href = String.split(x, "?post=") diff --git a/lib/simple_blog/rewrite_html/stylesheet.ex b/lib/simple_blog/rewrite_html/stylesheet.ex index 5b617ca..a0299f9 100644 --- a/lib/simple_blog/rewrite_html/stylesheet.ex +++ b/lib/simple_blog/rewrite_html/stylesheet.ex @@ -1,6 +1,7 @@ defmodule SimpleBlog.RewriteHTML.Stylesheet do require Floki + $ (string(), string()) -> string() def rewrite(html, path) do {:ok, document} = Floki.parse_document(html) diff --git a/lib/simple_blog/server.ex b/lib/simple_blog/server.ex index 7a6b1a3..4d35fc3 100644 --- a/lib/simple_blog/server.ex +++ b/lib/simple_blog/server.ex @@ -14,6 +14,18 @@ defmodule SimpleBlog.Server do @doc """ Initializes server passing initial params """ + + $type opts() :: + string() + | tuple() + | atom() + | integer() + | float() + | [opts()] + | %{optional(opts()) => opts()} + | MapSet.t() + + $ opts() -> opts() def init(_options) do Logger.info("Initializing server ...") end @@ -21,6 +33,8 @@ defmodule SimpleBlog.Server do @doc """ Handle HTTP requests. """ + # Verificar se é assim mesmo + $ (Plug.Conn.t(), opts()) -> Plug.Conn.t() def call(%Plug.Conn{request_path: "/posts/", query_string: query_string} = conn, _opts) do postname = query_string @@ -42,6 +56,7 @@ defmodule SimpleBlog.Server do |> send_resp(200, result) end + $ (Plug.Conn.t(), opts()) -> Plug.Conn.t() def call(%Plug.Conn{request_path: "/"} = conn, _opts) do posts = "blog" @@ -58,6 +73,7 @@ defmodule SimpleBlog.Server do |> send_resp(200, result) end + $ (Plug.Conn.t(), opts()) -> Plug.Conn.t() def call( %Plug.Conn{request_path: _request_path, req_headers: [{"accept", accept} | _]} = conn, _opts @@ -68,6 +84,7 @@ defmodule SimpleBlog.Server do end end + $ (Plug.Conn.t(), string()) -> Plug.Conn.t() defp asset_pipeline(%Plug.Conn{request_path: request_path} = conn, content_type) do Logger.info(request_path)