indentlabs/notebook

View on GitHub
app/views/content/contexts/_location.html.erb

Summary

Maintainability
Test Coverage
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Character,
    content: content,
    relation_class: Birthing,
    relation_class_id: :birthplace_id,
    relation_text: "<plural> born here" # 5 characters born here
  }
%>

<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Creature,
    content: content,
    relation_class: Wildlifeship,
    relation_class_id: :habitat_id,
    relation_text: "<plural> native here" # 5 creatures native here
  }
%>

<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Religion,
    content: content,
    relation_class: ReligiousLocationship,
    relation_class_id: :practicing_location,
    relation_text: "<plural> practiced here"
  }
%>

<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Group,
    content: content,
    relation_class: Headquartership,
    relation_class_id: :headquarter_id,
    relation_text: "<plural> headquarters here"
  }
%>

<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Group,
    content: content,
    relation_class: Officeship,
    relation_class_id: :office_id,
    relation_text: "<plural> office(s) here"
  }
%>
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Group,
    content: content,
    relation_class: GroupLocationship,
    relation_class_id: :location_id,
    relation_text: "<plural> here"
  }
%>

<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Flora,
    content: content,
    relation_class: FloraLocation,
    relation_class_id: :location_id,
    relation_text: '<plural> found here'
  }
%>

<% scenes = SceneLocationship.where(scene_location_id: content.id).map(&:scene).compact.select { |content| content && content.readable_by?(current_user || User.new) } %>
<% if scenes.any? %>
  <div class="col s12 m6 l4">
    <%= render partial: 'content/cards/in_universe_content_list', locals: {
      content_type: :scene,
      content_list: scenes,
      card_title: "#{pluralize(scenes.count, 'scene')} happens here"
    } %>
  </div>
<% end %>

<% @references.each do |content_type, relations| %>
  <% next unless relations.any? %>
  <%
  card_title = if relations.count == 1
    if relations.first.first.include? '<plural>'
      relations.first.first
    else
      [
        relations.first.first,
        ' ',
        pluralize(relations.count, "#{content_type.to_s.singularize}")
      ].join
    end
  else
    [
      'Related to ',
      pluralize(relations.count, "other #{content_type.to_s.singularize}")
    ].join
  end
  %>
  <div class="col s12 m6 l4">
    <%= render partial: 'content/cards/content_relation_list', locals: {
      content_type: content_type,
      relations:    relations,
      card_title:   card_title
    } %>
  </div>
<% end %>