Skip to content

Commit

Permalink
Merge pull request #13 from viniciusalonso/rename-function
Browse files Browse the repository at this point in the history
Fix typo in function name
  • Loading branch information
viniciusalonso committed Nov 7, 2023
2 parents 7c463e3 + 8da9f43 commit a6e4c82
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/mix/tasks/simple_blog/compile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Mix.Tasks.SimpleBlog.Compile do

index_html =
File.read(root_directory <> "/index.html.eex")
|> SimpleBlog.Converter.Page.exx_to_html(posts)
|> SimpleBlog.Converter.Page.eex_to_html(posts)
|> rewrite_stylesheets("./")
|> rewrite_images("./")
|> rewrite_post_links()
Expand Down Expand Up @@ -126,7 +126,7 @@ defmodule Mix.Tasks.SimpleBlog.Compile do

result =
File.read(root_directory <> "/post.html.eex")
|> SimpleBlog.Converter.Page.exx_to_html(post)
|> SimpleBlog.Converter.Page.eex_to_html(post)
|> rewrite_stylesheets("../../../../")
|> rewrite_images("../../../../")
|> rewrite_back_link()
Expand Down
8 changes: 4 additions & 4 deletions lib/simple_blog/converter/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ defmodule SimpleBlog.Converter.Page do
## Examples
iex> posts = [%SimpleBlog.Post{title: "post 1"}, %SimpleBlog.Post{title: "post 2"}]
iex> SimpleBlog.Converter.Page.exx_to_html({:ok, "<%= for post <- posts do %><%= post.title %><% end %>"}, posts)
iex> SimpleBlog.Converter.Page.eex_to_html({:ok, "<%= for post <- posts do %><%= post.title %><% end %>"}, posts)
"post 1post 2"
iex> post = %SimpleBlog.Post{title: "post 1"}
iex> SimpleBlog.Converter.Page.exx_to_html({:ok, "<%= post.title %>"}, post)
iex> SimpleBlog.Converter.Page.eex_to_html({:ok, "<%= post.title %>"}, post)
"post 1"
"""
def exx_to_html({:ok, body}, posts) when is_list(posts) do
def eex_to_html({:ok, body}, posts) when is_list(posts) do
quoted = EEx.compile_string(body)

case Code.eval_quoted(quoted, posts: posts) do
{result, _bindings} -> result
end
end

def exx_to_html({:ok, body}, post) do
def eex_to_html({:ok, body}, post) do
quoted = EEx.compile_string(body)

case Code.eval_quoted(quoted, post: post) do
Expand Down
4 changes: 2 additions & 2 deletions lib/simple_blog/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule SimpleBlog.Server do

result =
File.read("blog/post.html.eex")
|> SimpleBlog.Converter.Page.exx_to_html(post)
|> SimpleBlog.Converter.Page.eex_to_html(post)

conn
|> put_resp_content_type("text/html")
Expand All @@ -51,7 +51,7 @@ defmodule SimpleBlog.Server do

result =
File.read("blog/index.html.eex")
|> SimpleBlog.Converter.Page.exx_to_html(posts)
|> SimpleBlog.Converter.Page.eex_to_html(posts)

conn
|> put_resp_content_type("text/html")
Expand Down
14 changes: 7 additions & 7 deletions test/simple_blog/converter/page_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ defmodule SimpleBlog.Converter.PageTest do
use ExUnit.Case
doctest SimpleBlog.Converter.Page

describe "exx_to_html" do
test "transform exx list in html" do
exx = """
describe "eex_to_html" do
test "transform eex list in html" do
eex = """
<!doctype html>
<html>
<head></head>
Expand Down Expand Up @@ -32,12 +32,12 @@ defmodule SimpleBlog.Converter.PageTest do
</html>
"""

html = SimpleBlog.Converter.Page.exx_to_html({:ok, exx}, posts_html)
html = SimpleBlog.Converter.Page.eex_to_html({:ok, eex}, posts_html)
assert normalize(output) == normalize(html)
end

test "transform exx in html" do
exx = """
test "transform eex in html" do
eex = """
<!doctype html>
<html>
<head></head>
Expand All @@ -59,7 +59,7 @@ defmodule SimpleBlog.Converter.PageTest do
</html>
"""

html = SimpleBlog.Converter.Page.exx_to_html({:ok, exx}, posts_html)
html = SimpleBlog.Converter.Page.eex_to_html({:ok, eex}, posts_html)
assert normalize(output) == normalize(html)
end
end
Expand Down

0 comments on commit a6e4c82

Please sign in to comment.