Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typo in function name #13

Merged
merged 1 commit into from
Nov 7, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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