notebook/app/views/content/show.html.erb

130 lines
5.4 KiB
Plaintext

<% if @content.present? && @content.respond_to?(:as_jsonld) %>
<script type="application/ld+json">
<%= @content.as_jsonld.to_json.html_safe %>
</script>
<% end %>
<% set_meta_tags title: content.name, description: content.description %>
<%# TODO: Check if <content type>/_meta exists and render it here if so %>
<% content_for :sidebar_top do %>
<%= render partial: 'cards/serendipitous/content_question', locals: { question: @question, content: @content } %>
<% end %>
<% categories = content.class.attribute_categories(current_user) %>
<div class="row">
<div class="col s12">
<div class="card hoverable">
<div class="card-content">
<div class="card-title center">
<%= link_to polymorphic_path(content.class) do %>
<span class="<%= content.class.color %>-text"><i class="material-icons right"><%= content.class.icon %></i></span>
<% end %>
<a href="#" title="Share" class="share <%= content.class.color %>-text"><i class="material-icons right">share</i></a>
<%= content.respond_to?(:label) ? content.label : content.name %>
</div>
<ul class="tabs tabs-fixed-width" style="margin-bottom:30px;">
<% categories.each do |category| %>
<%= attribute_category_tab(content, category) %>
<% end %>
</ul>
<%
markdown = Redcarpet::Markdown.new(
Redcarpet::Render::HTML.new(
with_toc_data: true,
safe_links_only: true,
filter_html: true,
link_attributes: {target: '_blank'}
),
autolink: true,
tables: true,
strikethrough: true,
superscript: true,
underline: true,
highlight: true,
footnotes: true,
)
%>
<% categories.each do |category| %>
<div id="<%= category.name.gsub("'", '') %>_panel" class="row">
<% category.attribute_fields.each do |attribute| %>
<% next if attribute.name.start_with?("private") && @content.user != current_user %>
<% value = nil
if content.respond_to?(attribute.name.to_sym)
value = content.send(attribute.name.to_sym)
else
value = Attribute.where(user: current_user, attribute_field: attribute, entity: content).first
end
%>
<% next if value.blank? %>
<div class="row">
<div class="col s3 m3 l2 right-align flow-text grey-text"><%= attribute.label %></div>
<% if value.is_a?(ActiveRecord::Associations::CollectionProxy) %>
<% klass = value.first.class || value.build.class %>
<div class="col s9 m9 l10 flow-text">
<% value.each do |li| %>
<div class="chip">
<%= link_to li do %>
<span class="<%= klass.color %>-text"><i class="material-icons left"><%= klass.icon %></i></span>
<%= li.name %>
<% end %>
</div>
<% end %>
</div>
<% elsif attribute.name == 'attribute_category_id' %>
<div class="col s9 m9 l10 flow-text">
<%= link_to content.attribute_category.label, content.attribute_category if content.attribute_category %>
</div>
<% elsif attribute.name == 'universe_id' %>
<div class="col s9 m9 l10 flow-text">
<%= link_to content.universe.name, content.universe if content.universe %>
</div>
<% else %>
<%# TODO: if text is > 240, truncate and add "Read more" link that opens modal %>
<div class="col s9 m9 l10 <%= "flow-text" unless value.to_s.length > 140 %> markdownable">
<%= markdown.render(value.is_a?(Attribute) ? value.value : value).html_safe %>&nbsp;
</div>
<% end %>
</div>
<% end %>
</div>
<% end %>
</div>
<div class="card-action center">
<%= yield :content_show_footer %>
<% if current_user == content.user %>
<%= link_to "Edit this #{content.class.to_s.downcase}", edit_polymorphic_path(@content), class: "btn #{content.class.color}" %>
<% elsif content.user.name.present? %>
<%= content.user.name %> created and maintains this universe on Notebook.ai.<br />
<%= link_to "See more from #{content.user.name}", content.user %>
<%= link_to "Create your own universe.", root_url %>
<% end %>
</div>
</div>
</div>
</div>
<%= render partial: 'content/share', locals: { shared_content: @content} %>
<%# TODO: not this %>
<% if @content.is_a? Universe %>
<div class="col s12 m12 l4">
<%= render partial: 'content/cards/in_universe_content_list', locals: { content_type: :character, content_list: @content.characters } %>
</div>
<div class="col s12 m12 l4">
<%= render partial: 'content/cards/in_universe_content_list', locals: { content_type: :location, content_list: @content.locations } %>
</div>
<div class="col s12 m12 l4">
<%= render partial: 'content/cards/in_universe_content_list', locals: { content_type: :item, content_list: @content.items } %>
</div>
<% end %>