Skip to content

Commit

Permalink
hide GPX links if there is none
Browse files Browse the repository at this point in the history
  • Loading branch information
breunigs committed Oct 14, 2023
1 parent c0bca93 commit 3161928
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions lib/article/decorators.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ defmodule Article.Decorators do
end
end

@spec gpx_links(module()) :: Phoenix.LiveView.Rendered.t()
@spec gpx_links(module()) :: [Phoenix.LiveView.Rendered.t()]
def gpx_links(art) when is_module(art) do
assigns = %{name: art.name()}

~H"""
Route im
<a href={"/geo/#{@name}.gpx"} download={"#{@name}.gpx"}>GPX-Format</a>
bzw.
<a href={"/geo/#{@name}.kml"} download={"#{@name}.kml"}>KML-Format</a>
"""
if length(art.tracks()) > 0 do
[
~H"""
Route im
<a href={"/geo/#{@name}.gpx"} download={"#{@name}.gpx"}>GPX-Format</a>
bzw.
<a href={"/geo/#{@name}.kml"} download={"#{@name}.kml"}>KML-Format</a>
"""
]
else
[]
end
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/components/tag_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ defmodule Components.TagHelpers do
other
end)

links = if assigns[:gpx], do: links ++ [Article.Decorators.gpx_links(art)], else: links
links = if assigns[:gpx], do: links ++ Article.Decorators.gpx_links(art), else: links
assigns = %{links: links}

case length(links) do
Expand Down

0 comments on commit 3161928

Please sign in to comment.