Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
concatenating the output of the link helper, take 2
I'm using a view function to create a heading and a list of links.
By way of context, here is the use case:
import PhxHttpWeb.LayoutView
import RefData.Common
address = @item_data.address
types = ~w[ document email phone postal related web_site ]a
<%= for type <- types do %>
<%= display(type, address) %>
<% end %>
Here is the (running, but fugly) code. FYI, keyss/1 returns a sorted list of keys
defmodule PhxHttpWeb.ResourcesView do
use PhxHttpWeb, :view
import RefData.Common
def display(type, address), do: display_h(type, address[type])
defp display_h(_, nil), do: ""
defp display_h(:web_site, submap) do
link_f = fn key ->
{:safe, iolist} = link(key, to: submap[key])
"<li>#{ iolist }</li>\n"
links = submap
|> keyss()
<h3>Web Site</h3>
#{ links }
|> raw()
Any suggestions on making the code a bit cleaner?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment