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
+ "
- #{entity.map { |e| entity_to_html(e) }.join('
- ')}
"
+ 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
<% data_entities.each do |data_entity| %>
- -
- <% if data_entity.external? %>
- <%= data_entity.name || data_entity.id %>
- <% else %>
- <%= data_entity.name || data_entity.id %>
- <% end %>
+
-
+ <%= entity_to_html data_entity %>
<% if data_entity.content_size %>
-
Size: <%= data_entity.content_size %>
+
Size: <%= entity_to_html data_entity.content_size %>
<% end %>
<% if data_entity.encoding_format %>
-
Format: <%= data_entity.encoding_format %>
+
Format: <%= entity_to_html data_entity.encoding_format %>
<% end %>
<% end %>
diff --git a/test/preview_test.rb b/test/preview_test.rb
new file mode 100644
index 0000000..11d1f64
--- /dev/null
+++ b/test/preview_test.rb
@@ -0,0 +1,48 @@
+# encoding: utf-8
+require 'test_helper'
+
+class PreviewTest < Test::Unit::TestCase
+ test 'simple attributes' do
+ crate = ROCrate::Crate.new
+ crate.author = 'Finn'
+
+ html = crate.preview.source.read
+ assert_includes html, '- Finn
'
+ end
+
+ test 'list attributes' do
+ crate = ROCrate::Crate.new
+ crate.author = ['Finn', 'Josiah']
+
+ html = crate.preview.source.read
+ assert_includes html, ''
+ end
+
+ test 'entity attributes' do
+ crate = ROCrate::Crate.new
+ crate.author = crate.add_person('https://orcid.org/0000-0002-0048-3300', name: 'Finn')
+
+ html = crate.preview.source.read
+ assert_includes html, '- Finn
'
+ end
+
+ test 'complex attributes' do
+ crate = ROCrate::Crate.new
+ crate.author = [crate.add_person('https://orcid.org/0000-0002-0048-3300', name: 'Finn'), 'Josiah']
+
+ html = crate.preview.source.read
+
+ assert_includes html, ''
+ end
+
+ test 'files' do
+ crate = ROCrate::Crate.new
+ crate.add_file(fixture_file('info.txt'))
+ crate.add_external_file('https://raw.githubusercontent.com/ResearchObject/ro-crate-ruby/master/README.md')
+
+ html = crate.preview.source.read
+
+ assert_includes html, 'info.txt'
+ assert_includes html, 'https://raw.githubusercontent.com/ResearchObject/ro-crate-ruby/master/README.md'
+ end
+end