Skip to content

Commit

Permalink
Use built-in EEx (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
marpo60 authored Sep 5, 2024
1 parent fc07767 commit 8d2d1a7
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions lib/meetup_bot/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,24 @@ defmodule MeetupBot.Router do
plug(:dispatch)

get "/" do
import Plug.HTML, only: [html_escape: 1]

Tracer.with_span "meetup_bot.request.get" do
layout = fn meetups ->
"""
template = """
<title>OWU.UY - MeetupBot</title>
<h1>Próximos meetups</h1>
<ul>
#{meetups}
"""
end

template = fn meetup ->
"""
<li>
#{html_escape(Calendar.strftime(meetup.datetime, "%-d %B - %H:%M"))}
-
#{html_escape(meetup.name)} -&nbsp
<a href="#{meetup.event_url}">
#{html_escape(meetup.title)}
</a>
"""
end

html =
MeetupCache.values()
|> Enum.map(fn m -> template.(m) end)
|> Enum.join()
|> layout.()
<%= for meetup <- meetups do %>
<li>
<%= Calendar.strftime(meetup.datetime, "%-d %B - %H:%M") %> -
<%= meetup.name %>;
<a href="<%= meetup.event_url %>">
<%= meetup.title %>
</a>
</li>
<% end %>
</ul>
"""

html = EEx.eval_string(template, meetups: MeetupCache.values())

conn
|> put_resp_content_type("text/html")
Expand Down

0 comments on commit 8d2d1a7

Please sign in to comment.