Permalink
Browse files

Better version rendering in the web interface

  • Loading branch information...
1 parent fada970 commit 04ec36e54fcb8e51b209dd311842848dd2b3239a @yrashk committed Oct 15, 2012
Showing with 28 additions and 24 deletions.
  1. +7 −0 lib/package.ex
  2. +20 −23 lib/server/templates.ex
  3. +1 −1 lib/server/templates/package.html.eex
View
@@ -182,4 +182,11 @@ defrecord Expm.Package,
raise Expm.Package.VersionNotFound, version: version
end
end
+
+ def inspect_version(version) when is_binary(version), do: version
+ def inspect_version(version) when is_atom(version), do: to_binary(version)
+ def inspect_version([>: v]), do: "> #{inspect_version(v)}"
+ def inspect_version([>=: v]), do: ">= #{inspect_version(v)}"
+ def inspect_version([<: v]), do: "< #{inspect_version(v)}"
+ def inspect_version([<=: v]), do: "<= #{inspect_version(v)}"
end
View
@@ -4,41 +4,41 @@ defmodule Expm.Server.Templates.Package do
EEx.function_from_string :def, :description,
%b{
<%= description %>
- }, [:description]
+ }, [:description, :_assigns]
EEx.function_from_string :def, :directories,
%b{
<%= lc dir inlist directories do %>
<span class="label"><%= dir %></span>
<% end %>
- }, [:directories]
+ }, [:directories, :_assigns]
EEx.function_from_string :def, :homepage,
%b{
<%= if nil?(homepage) do %>
<% else %>
<a href="<%= homepage %>"><%= homepage %></a>
<% end %>
- }, [:homepage]
+ }, [:homepage, :_assigns]
EEx.function_from_string :def, :keywords,
%b{
<%= lc keyword inlist keywords do %>
<span class="label label-info"><%= keyword %></span>
<% end %>
- }, [:keywords]
+ }, [:keywords, :_assigns]
EEx.function_from_string :def, :metadata,
%b{
<%= lc \{tag, value \} inlist metadata do %>
<span class="label label-info"><%= tag %>:</span> <%= inspect value %>
<% end %>
- }, [:metadata]
+ }, [:metadata, :_assigns]
EEx.function_from_string :def, :name,
%b{
<strong><%= name %></strong>
- }, [:name]
+ }, [:name, :_assigns]
EEx.function_from_string :def, :repositories,
%b{
@@ -60,49 +60,46 @@ defmodule Expm.Server.Templates.Package do
<a href="<%= repository[:url] %>"><%= repository[:url] %></a>
<% end %>
<% end %>
- }, [:repositories]
+ }, [:repositories, :_assigns]
EEx.function_from_string :def, :version,
%b{
<%= version %>
- }, [:version]
+ }, [:version, :_assigns]
EEx.function_from_string :def, :dependencies,
%b|
<%= lc dependency inlist dependencies do %>
- <%= if is_binary(dependency) do %>
- <a href="/<%= dependency %>" class="btn btn-mini btn-info"><%= dependency %></a>
- <% end %>
- <%= if match?({name, version}, dependency) do %>
- <a href="/<%= name %>/<%= version %>" class="btn btn-mini btn-info"><%= name %> (<em><%= version %></em>)</a>
- <% end %>
+ <% [{name, actual_version}] = Expm.Package.deps(@repo, Expm.Package.new(dependencies: [dependency])) %>
+ <% if is_binary(dependency), do: version = "topmost", else: {_, version} = dependency %>
+ <a href="/<%= name %>/<%= actual_version %>" class="btn btn-mini btn-info"><%= name %> (<em><%= Expm.Package.inspect_version(version) %></em>)</a>
<% end %>
- |, [:dependencies]
+ |, [:dependencies, :assigns]
EEx.function_from_string :def, :licenses,
%b{
<%= lc license inlist licenses do %>
<span class="label label-success"><%= license[:name] %></span>
<% end %>
- }, [:licenses]
+ }, [:licenses, :_assigns]
- def maintainers(maintainers), do: people(maintainers)
- def contributors(contributors), do: people_without_email(contributors)
+ def maintainers(maintainers, assigns), do: people(maintainers, assigns)
+ def contributors(contributors, assigns), do: people_without_email(contributors, assigns)
EEx.function_from_string :defp, :people,
%b{
<%= lc person inlist people do %>
<span class="label label-success"><%= person[:name] %> &lt;<span class="b64"><%= :base64.encode(person[:email]) %></span>&gt;</span>
<% end %>
- }, [:people]
+ }, [:people, :_assigns]
EEx.function_from_string :defp, :people_without_email,
%b{
<%= lc person inlist people do %>
<span class="label label-success"><%= person[:name] %></span>
<% end %>
- }, [:people]
+ }, [:people, :_assigns]
defp github_url(repository) do
"https://github.com/#{repository[:github]}" <>
@@ -115,9 +112,9 @@ defmodule Expm.Server.Templates.Package do
end
end
- def render(field, value) do
- if function_exported?(__MODULE__, field, 1) do
- apply(__MODULE__, field, [value])
+ def render(repo, field, value) do
+ if function_exported?(__MODULE__, field, 2) do
+ apply(__MODULE__, field, [value, repo: repo])
else
inspect value
end
@@ -19,7 +19,7 @@
<%= lc {field, value} inlist package.to_keywords do %>
<tr>
<td><b><%= to_binary field %></b></td>
- <td><%= Expm.Server.Templates.Package.render(field,value) %></td>
+ <td><%= Expm.Server.Templates.Package.render(repo, field,value) %></td>
</tr>
<% end %>
</tbody>

0 comments on commit 04ec36e

Please sign in to comment.