From bbd558be7c307933a9ba385e475ba902cdf62f70 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Thu, 23 May 2024 17:29:10 +0100 Subject: [PATCH] Improve how entities rendered in previews. seek4science/seek#1895 --- lib/ro_crate/ro-crate-preview.html.erb | 40 ++++++++++++++------- test/preview_test.rb | 48 ++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 test/preview_test.rb diff --git a/lib/ro_crate/ro-crate-preview.html.erb b/lib/ro_crate/ro-crate-preview.html.erb index cea9075..a9fe05a 100644 --- a/lib/ro_crate/ro-crate-preview.html.erb +++ b/lib/ro_crate/ro-crate-preview.html.erb @@ -1,3 +1,23 @@ +<% + def entity_to_html(entity) + if entity.is_a?(Array) + if entity.length == 1 + entity_to_html(entity.first) + else + "" + end + elsif entity.is_a?(ROCrate::Entity) + label = entity['name'] || entity.id + if entity.external? + "#{label}" + else + label + end + else + entity + end + end +%> @@ -18,36 +38,32 @@
<% if author %>
Author
-
<%= author %>
+
<%= entity_to_html author %>
<% end %> <% if contact_point %>
Contact
-
<%= contact_point %>
+
<%= entity_to_html contact_point %>
<% end %> <% if publisher %>
Publisher
-
<%= publisher %>
+
<%= entity_to_html publisher %>
<% end %> <% if license %>
License
-
<%= license %>
+
<%= entity_to_html license %>
<% end %>

Contents