Skip to content
Browse files

Display links to package homepages on the index page

  • Loading branch information...
1 parent b160079 commit 683eccbe262fe1b426846f5d74927e35101ad5a8 @yrashk committed Oct 23, 2012
Showing with 26 additions and 1 deletion.
  1. +18 −0 lib/package.ex
  2. +8 −1 lib/server/templates/list.html.eex
View
18 lib/package.ex
@@ -137,6 +137,24 @@ defrecord Expm.Package,
pkg
end
+ def public_homepage(package) do
+ github_repo = Enum.find(repositories(package), fn(r) -> not nil?(r[:github]) end)
+ if nil?(github_repo) do
+ github_repo = Enum.find(repositories(package), fn(r) ->
+ Regex.match?(%r(.*github.com/.+), r[:git])
+ end)
+ path = Regex.replace(%r{.*github.com/(.+)$},github_repo[:r],"\\1")
+ path = Regex.replace(%r{(.+)(\.git)$}, path, "\\1")
+ github_repo = Keyword.put github_repo, :github, path
+ end
+ cond do
+ not nil?(homepage(package)) ->
+ homepage(package)
+ not nil?(github_repo) ->
+ "https://github.com/#{github_repo[:github]}"
+ end
+ end
+
defdelegate [valid?(package), validate(package)], to: Expm.Package.Validator
def deps(repo, rec) do
View
9 lib/server/templates/list.html.eex
@@ -3,7 +3,14 @@
<tbody>
<%= lc pkg inlist pkgs do %>
<tr>
- <td><a href="<%= pkg.name %>"><%= pkg.name %></a></td>
+ <td>
+ <%= if not nil?(pkg.public_homepage) do %>
+ <a href="<%= pkg.public_homepage %>"><i class="icon-home"></i></a>
+ <%= else %>
+ <a style="opacity: 0.5" class="disabled" href="#"><i class="icon-home"></i></a>
+ <% end %>
+ <a href="<%= pkg.name %>"><%= pkg.name %></a>
+ </td>
<td><%= pkg.description %></td>
</tr>
<% end %>

0 comments on commit 683eccb

Please sign in to comment.
Something went wrong with that request. Please try again.