This repository has been archived by the owner on Jan 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathshow.html.erb
88 lines (71 loc) · 3.01 KB
/
show.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<%#
GraphQL fragments are defined in the templates themselves.
All data being used directly in this template should also be reflected
statically in the fragment. And vice versa, all fields in the query fragment
should only be used directly in this template. You MUST keep static queries
and runtime usage in sync. Defining queries in the same file makes
this aspect easier to manage.
%>
<%graphql
# Fragments are parts of queries, they can't be executed themselves.
# This fragment is defined on the Repository type and is coincidentally named
# "Repository". You can name the fragment whatever you'd like. Its the name
# that is exported as a Ruby constant, so it must start with a capital letter.
#
# Its exported as "Views::Repositories::Show::Repository". The module path to
# the tempate then the name of the fragment.
fragment Repository on Repository {
# id is a GraphQL global id, not a database id
# It is an opaque base64 identifier we can use to refetch the entity.
id
# owner is a User or Organization
owner {
login
}
# The repository's name
name
# Optional description text and homepage URL
description
homepageUrl
# Include repositories/_navigation.html.erb data dependencies
...Views::Repositories::Navigation::Repository
...Views::Repositories::Star::Repository
}
%>
<%#
The first step of any GraphQL defined view is to cast arguments to the locally
defined fragment result wrapper. In a statically typed langauge, you can think
of it as passing a concrete type into a function that accepts an interface.
def repositories_show(repository: Views::Repositories::Show::Repository)
The wrapper serves two primary roles:
1. Provides Ruby friendly snake case accessors for accessing the underlying data
2. Only expose fields explicitly defined by this fragment.
`repository` is a full set of data, but fields included by the
...Views::Repositories::Navigation::Repository spread are hidden.
%>
<% repository = Views::Repositories::Show::Repository.new(repository) %>
<div class="header clearfix">
<%= render "repositories/navigation", repository: repository %>
<h3 class="text-muted inline-block">
<a href="<%= repositories_path %>"><%= repository.owner.login %></a>
/
<a href="<%= repository_path(repository.id) %>"><%= repository.name %></a>
</h3>
<div class="inline-block star-badge-header">
<%= render "repositories/star", repository: repository %>
</div>
</div>
<hr>
<div class="jumbotron">
<h1><%= repository.name %></h1>
<% if repository.description.present? %>
<p><%= repository.description %></p>
<% end %>
<p>
<%# NOTE: homepage_url is snake case here %>
<% if repository.homepage_url.present? %>
<a class="btn btn-primary btn-lg" href="<%= repository.homepage_url %>" role="button">Homepage</a>
<% end %>
<a class="btn btn-primary btn-lg" href="https://github.com/<%= repository.owner.login %>/<%= repository.name %>" role="button">View on GitHub</a>
</p>
</div>