graphql-docs 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,127 @@
1
+ <ul class="categories">
2
+ <li>
3
+ <ul class="menu-root">
4
+ <li>
5
+ GraphQL Reference
6
+ </ul>
7
+ </li>
8
+
9
+ <li>
10
+ <p>Queries</p>
11
+ <ul class="menu-root">
12
+ <li>
13
+ <a href="../../object/query" class="sidebar-link<% if title == "Query" %> current<% end %>">
14
+ RootQuery
15
+ </a>
16
+ </li>
17
+ <li>
18
+ <a href="../../object/mutation" class="sidebar-link<% if title == "Mutation" %> current<% end %>">
19
+ Mutation
20
+ </a>
21
+ </li>
22
+ </ul>
23
+ </li>
24
+
25
+ <li>
26
+ <p>Objects</p>
27
+ <ul class="menu-root">
28
+ <% graphql_object_types.().each do |type| %>
29
+ <% @name = type["name"] %>
30
+ <!-- skip connection stuff -->
31
+ <% if @name.end_with?("Connection") || @name.end_with?("Edge") %>
32
+ <% next %>
33
+ <% end %>
34
+
35
+ <!-- skip metadata stuff -->
36
+ <% if @name.start_with?("__") %>
37
+ <% next %>
38
+ <% end %>
39
+
40
+ <!-- skip root query stuff -->
41
+ <% if @name == "RootQuery" %>
42
+ <% next %>
43
+ <% end %>
44
+
45
+ <li>
46
+ <a href="../../object/<%= @name.downcase %>/index.html" class="sidebar-link<% if title == @name %> current<% end %>">
47
+ <%= @name %>
48
+ </a>
49
+ </li>
50
+ <% end %>
51
+ </ul>
52
+ </li>
53
+
54
+ <li>
55
+ <p>Interfaces</p>
56
+ <ul class="menu-root">
57
+ <% graphql_interface_types.().each do |type| %>
58
+ <% @name = type["name"] %>
59
+ <li>
60
+ <a href="../../interface/<%= @name.downcase %>/index.html" class="sidebar-link<% if title == @name %> current<% end %>">
61
+ <%= @name %>
62
+ </a>
63
+ </li>
64
+ <% end %>
65
+ </ul>
66
+ </li>
67
+
68
+ <li>
69
+ <p>Enums</p>
70
+ <ul class="menu-root">
71
+ <% graphql_enum_types.().each do |type| %>
72
+ <% @name = type["name"] %>
73
+ <!-- skip metadata stuff -->
74
+ <% if @name.start_with?("__") %>
75
+ <% next %>
76
+ <% end %>
77
+ <li>
78
+ <a href="../../enum/<%= @name.downcase %>/index.html" class="sidebar-link<% if title == @name %> current<% end %>">
79
+ <%= @name %>
80
+ </a>
81
+ </li>
82
+ <% end %>
83
+ </ul>
84
+ </li>
85
+
86
+ <li>
87
+ <p>Unions</p>
88
+ <ul class="menu-root">
89
+ <% graphql_union_types.().each do |type| %>
90
+ <% @name = type["name"] %>
91
+ <li>
92
+ <a href="../../union/<%= @name.downcase %>/index.html" class="sidebar-link<% if title == @name %> current<% end %>">
93
+ <%= @name %>
94
+ </a>
95
+ </li>
96
+ <% end %>
97
+ </ul>
98
+ </li>
99
+
100
+ <li>
101
+ <p>Input Objects</p>
102
+ <ul class="menu-root">
103
+ <% graphql_input_object_types.().each do |type| %>
104
+ <% @name = type["name"] %>
105
+ <li>
106
+ <a href="../../input_object/<%= @name.downcase %>/index.html" class="sidebar-link<% if title == @name %> current<% end %>">
107
+ <%= @name %>
108
+ </a>
109
+ </li>
110
+ <% end %>
111
+ </ul>
112
+ </li>
113
+
114
+ <li>
115
+ <p>Scalars</p>
116
+ <ul class="menu-root">
117
+ <% graphql_scalar_types.().each do |type| %>
118
+ <% @name = type["name"] %>
119
+ <li>
120
+ <a href="../../scalar/<%= @name.downcase %>/index.html" class="sidebar-link<% if title == @name %> current<% end %>">
121
+ <%= @name %>
122
+ </a>
123
+ </li>
124
+ <% end %>
125
+ </ul>
126
+ </li>
127
+ </ul>
@@ -23,6 +23,9 @@ module GraphQLDocs
23
23
  type_kinds.each do |kind|
24
24
  @processed_schema["#{kind.downcase}_types"] = @processed_schema['types'].select { |t| t['kind'] == kind }
25
25
  end
26
+ @processed_schema['mutation_types'] = @processed_schema['object_types'].select do |t|
27
+ t['name'] == 'Mutation'
28
+ end.first['fields']
26
29
  # TODO: should the 'types' key be deleted now?
27
30
 
28
31
  @processed_schema
@@ -1,11 +1,17 @@
1
1
  require 'html/pipeline'
2
2
  require 'extended-markdown-filter'
3
- require 'page-toc-filter'
4
3
 
5
4
  module GraphQLDocs
6
5
  class Renderer
7
- def initialize(options)
6
+ include Helpers
7
+
8
+ def initialize(options, parsed_schema)
8
9
  @options = options
10
+ @parsed_schema = parsed_schema
11
+
12
+ unless @options[:templates][:default].nil?
13
+ @graphql_default_layout = ERB.new(File.read(@options[:templates][:default]))
14
+ end
9
15
 
10
16
  @pipeline_config = @options[:pipeline_config]
11
17
 
@@ -27,8 +33,11 @@ module GraphQLDocs
27
33
  @pipeline = HTML::Pipeline.new(filters, @pipeline_config[:context])
28
34
  end
29
35
 
30
- def render(string)
31
- @pipeline.to_html(string)
36
+ def render(type, name, contents)
37
+ contents = @pipeline.to_html(contents)
38
+ return contents if @graphql_default_layout.nil?
39
+ opts = { contents: contents, type: type, name: name}.merge(helper_methods)
40
+ @graphql_default_layout.result(OpenStruct.new(opts).instance_eval { binding })
32
41
  end
33
42
 
34
43
  private
@@ -1,3 +1,3 @@
1
1
  module GraphQLDocs
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -0,0 +1,75 @@
1
+ .api {
2
+ background: #fafafa;
3
+ h3 {
4
+ padding: 5px 10px;
5
+ }
6
+ h3.api-title {
7
+ margin: 0;
8
+ overflow: auto;
9
+ }
10
+ h4 {
11
+ font-weight: normal;
12
+ font-style: italic;
13
+ margin-bottom: 0.25em;
14
+ text-decoration: underline;
15
+ margin-left: 20px;
16
+ }
17
+ dl {
18
+ margin-top: 0.25em;
19
+ }
20
+ dl.args {
21
+ margin-left: 40px;
22
+ }
23
+ dl.constants {
24
+ margin-left: 20px;
25
+ }
26
+ dt {
27
+ margin-top: 1em;
28
+ .name {
29
+ font-weight: bold;
30
+ }
31
+ .type {
32
+ margin-left: 15px;
33
+ font-size: 0.9em;
34
+ font-weight: 200;
35
+ color: #000;
36
+ }
37
+ }
38
+ dd {
39
+ margin-bottom: 1em;
40
+ margin-left: 0;
41
+ }
42
+ .desc {
43
+ margin: 1em;
44
+ }
45
+ pre {
46
+ margin-right: 10px;
47
+ }
48
+ }
49
+ h3.api-title {
50
+ padding: 5px 10px;
51
+ margin-top: 2em;
52
+ }
53
+ .api-title {
54
+ .locus {
55
+ float: right;
56
+ font-weight: normal;
57
+ padding-right: 5px;
58
+ font-style: italic;
59
+ }
60
+ .subtext {
61
+ font-size: 11px;
62
+ text-align: left;
63
+ clear: both;
64
+ display: block;
65
+ font-weight: normal;
66
+ >code {
67
+ font-size: 11px;
68
+ margin-right: 12px;
69
+ }
70
+ }
71
+ .src-code {
72
+ color: #20338a !important;
73
+ border-bottom: none !important;
74
+ }
75
+ }
@@ -0,0 +1,497 @@
1
+ #content {
2
+ padding: 20px 30px;
3
+ max-width: 760px;
4
+ margin: 0px auto;
5
+ -webkit-text-size-adjust: 100%;
6
+ em {
7
+ font-style: italic;
8
+ }
9
+ strong {
10
+ font-family: 'ProximaNova-Bold';
11
+ }
12
+ h1 {
13
+ margin: 15px 0;
14
+ line-height: 1.4em;
15
+ font-size: 2em;
16
+ margin-top: 0;
17
+ margin-bottom: 30px;
18
+ }
19
+ h2 {
20
+ margin: 15px 0;
21
+ line-height: 1.4em;
22
+ font-size: 1.5em;
23
+ margin-top: 30px;
24
+ padding-bottom: 10px;
25
+ border-bottom: 1px solid #eee;
26
+ position: relative;
27
+ .anchor {
28
+ opacity: 0;
29
+ position: absolute;
30
+ font-size: 16px;
31
+ top: 2px;
32
+ left: -21px;
33
+ }
34
+ &:hover {
35
+ .anchor {
36
+ opacity: 1;
37
+ }
38
+ }
39
+ }
40
+ h3 {
41
+ margin: 15px 0;
42
+ line-height: 1.4em;
43
+ font-size: 1.2em;
44
+ margin-top: 30px;
45
+ position: relative;
46
+ .anchor {
47
+ opacity: 0;
48
+ position: absolute;
49
+ font-size: 16px;
50
+ top: 2px;
51
+ left: -21px;
52
+ }
53
+ &:hover {
54
+ .anchor {
55
+ opacity: 1;
56
+ }
57
+ }
58
+ }
59
+ h4 {
60
+ margin: 15px 0;
61
+ line-height: 1.4em;
62
+ }
63
+ h5 {
64
+ margin: 15px 0;
65
+ line-height: 1.4em;
66
+ }
67
+ h6 {
68
+ margin: 15px 0;
69
+ line-height: 1.4em;
70
+ }
71
+ p {
72
+ margin: 15px 0;
73
+ line-height: 1.4em;
74
+ }
75
+ ul {
76
+ margin: 15px 0;
77
+ line-height: 1.4em;
78
+ padding-left: 1.5em;
79
+ list-style-type: disc;
80
+ li {
81
+ margin-bottom: 5px;
82
+ }
83
+ }
84
+ ol {
85
+ margin: 15px 0;
86
+ line-height: 1.4em;
87
+ padding-left: 1.5em;
88
+ list-style-type: decimal;
89
+ li {
90
+ margin-bottom: 5px;
91
+ }
92
+ }
93
+ figure {
94
+ margin: 15px 0;
95
+ line-height: 1.4em;
96
+ }
97
+ a {
98
+ color: #de4f4f;
99
+ }
100
+ img {
101
+ max-width: 100%;
102
+ }
103
+ code {
104
+ font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
105
+ font-size: 0.8em;
106
+ line-height: 1.6em;
107
+ padding: 1px 4px;
108
+ background-color: #eee;
109
+ margin: 0 2px;
110
+ }
111
+ blockquote {
112
+ padding-left: 1.3em;
113
+ border-left: #eee solid 0.2em;
114
+ font-style: italic;
115
+ }
116
+ blockquote.warning {
117
+ border-color: #f00;
118
+ color: #f00;
119
+ }
120
+ dl {
121
+ margin-left: 1.5em;
122
+ dt {
123
+ .name {
124
+ font-family: monospace;
125
+ }
126
+ .type {
127
+ margin-left: 0.5em;
128
+ }
129
+ }
130
+ dd {
131
+ margin-left: 1.5em;
132
+ }
133
+ }
134
+ .edit-discuss-links {
135
+ margin-top: -25px;
136
+ margin-bottom: 40px;
137
+ }
138
+ table {
139
+ margin-top: 10px;
140
+ td p {
141
+ padding: 0 25px 0 25px;
142
+ }
143
+ }
144
+ pre {
145
+ font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
146
+ line-height: 1.6em;
147
+ margin: 20px 0;
148
+ overflow-x: auto;
149
+ position: relative;
150
+ padding: 20px 30px;
151
+ table {
152
+ width: 100%;
153
+ border-collapse: collapse;
154
+ padding: 0;
155
+ margin: 0;
156
+ }
157
+ tr {
158
+ width: 100%;
159
+ border-collapse: collapse;
160
+ padding: 0;
161
+ margin: 0;
162
+ }
163
+ td {
164
+ width: 100%;
165
+ border-collapse: collapse;
166
+ padding: 0;
167
+ margin: 0;
168
+ }
169
+ code {
170
+ background-color: #272822;
171
+ padding: 0;
172
+ margin: 0;
173
+ }
174
+ .gutter {
175
+ user-select: none;
176
+ width: 1.5em;
177
+ padding-right: 30px;
178
+ }
179
+ }
180
+ .highlight.html {
181
+ .code {
182
+ &:after {
183
+ font-family: 'ProximaNova-Semibold';
184
+ position: absolute;
185
+ top: 0;
186
+ right: 0;
187
+ color: #ccc;
188
+ text-align: right;
189
+ font-size: 0.75em;
190
+ padding: 5px 10px 0;
191
+ letter-spacing: 1.5px;
192
+ line-height: 15px;
193
+ height: 15px;
194
+ font-weight: 600;
195
+ }
196
+ }
197
+ }
198
+ .highlight.js {
199
+ .code {
200
+ &:after {
201
+ font-family: 'ProximaNova-Semibold';
202
+ position: absolute;
203
+ top: 0;
204
+ right: 0;
205
+ color: #ccc;
206
+ text-align: right;
207
+ font-size: 0.75em;
208
+ padding: 5px 10px 0;
209
+ letter-spacing: 1.5px;
210
+ line-height: 15px;
211
+ height: 15px;
212
+ font-weight: 600;
213
+ }
214
+ }
215
+ }
216
+ .highlight.bash {
217
+ .code {
218
+ &:after {
219
+ font-family: 'ProximaNova-Semibold';
220
+ position: absolute;
221
+ top: 0;
222
+ right: 0;
223
+ color: #ccc;
224
+ text-align: right;
225
+ font-size: 0.75em;
226
+ padding: 5px 10px 0;
227
+ letter-spacing: 1.5px;
228
+ line-height: 15px;
229
+ height: 15px;
230
+ font-weight: 600;
231
+ }
232
+ }
233
+ }
234
+ .highlight.css {
235
+ .code {
236
+ &:after {
237
+ font-family: 'ProximaNova-Semibold';
238
+ position: absolute;
239
+ top: 0;
240
+ right: 0;
241
+ color: #ccc;
242
+ text-align: right;
243
+ font-size: 0.75em;
244
+ padding: 5px 10px 0;
245
+ letter-spacing: 1.5px;
246
+ line-height: 15px;
247
+ height: 15px;
248
+ font-weight: 600;
249
+ }
250
+ }
251
+ }
252
+ .highlight.jsx {
253
+ .code {
254
+ &:after {
255
+ font-family: 'ProximaNova-Semibold';
256
+ position: absolute;
257
+ top: 0;
258
+ right: 0;
259
+ color: #ccc;
260
+ text-align: right;
261
+ font-size: 0.75em;
262
+ padding: 5px 10px 0;
263
+ letter-spacing: 1.5px;
264
+ line-height: 15px;
265
+ height: 15px;
266
+ font-weight: 600;
267
+ }
268
+ }
269
+ }
270
+ .highlight.html.html {
271
+ .code {
272
+ &:after {
273
+ content: 'HTML';
274
+ }
275
+ }
276
+ }
277
+ .highlight.js.html {
278
+ .code {
279
+ &:after {
280
+ content: 'HTML';
281
+ }
282
+ }
283
+ }
284
+ .highlight.bash.html {
285
+ .code {
286
+ &:after {
287
+ content: 'HTML';
288
+ }
289
+ }
290
+ }
291
+ .highlight.css.html {
292
+ .code {
293
+ &:after {
294
+ content: 'HTML';
295
+ }
296
+ }
297
+ }
298
+ .highlight.jsx.html {
299
+ .code {
300
+ &:after {
301
+ content: 'HTML';
302
+ }
303
+ }
304
+ }
305
+ .highlight.html.js {
306
+ .code {
307
+ &:after {
308
+ content: 'JS';
309
+ }
310
+ }
311
+ }
312
+ .highlight.js.js {
313
+ .code {
314
+ &:after {
315
+ content: 'JS';
316
+ }
317
+ }
318
+ }
319
+ .highlight.bash.js {
320
+ .code {
321
+ &:after {
322
+ content: 'JS';
323
+ }
324
+ }
325
+ }
326
+ .highlight.css.js {
327
+ .code {
328
+ &:after {
329
+ content: 'JS';
330
+ }
331
+ }
332
+ }
333
+ .highlight.jsx.js {
334
+ .code {
335
+ &:after {
336
+ content: 'JS';
337
+ }
338
+ }
339
+ }
340
+ .highlight.html.bash {
341
+ .code {
342
+ &:after {
343
+ content: 'Shell';
344
+ }
345
+ }
346
+ }
347
+ .highlight.js.bash {
348
+ .code {
349
+ &:after {
350
+ content: 'Shell';
351
+ }
352
+ }
353
+ }
354
+ .highlight.bash.bash {
355
+ .code {
356
+ &:after {
357
+ content: 'Shell';
358
+ }
359
+ }
360
+ }
361
+ .highlight.css.bash {
362
+ .code {
363
+ &:after {
364
+ content: 'Shell';
365
+ }
366
+ }
367
+ }
368
+ .highlight.jsx.bash {
369
+ .code {
370
+ &:after {
371
+ content: 'Shell';
372
+ }
373
+ }
374
+ }
375
+ .highlight.html.css {
376
+ .code {
377
+ &:after {
378
+ content: 'CSS';
379
+ }
380
+ }
381
+ }
382
+ .highlight.js.css {
383
+ .code {
384
+ &:after {
385
+ content: 'CSS';
386
+ }
387
+ }
388
+ }
389
+ .highlight.bash.css {
390
+ .code {
391
+ &:after {
392
+ content: 'CSS';
393
+ }
394
+ }
395
+ }
396
+ .highlight.css.css {
397
+ .code {
398
+ &:after {
399
+ content: 'CSS';
400
+ }
401
+ }
402
+ }
403
+ .highlight.jsx.css {
404
+ .code {
405
+ &:after {
406
+ content: 'CSS';
407
+ }
408
+ }
409
+ }
410
+ .highlight.html.jsx {
411
+ .code {
412
+ &:after {
413
+ content: 'JSX';
414
+ }
415
+ }
416
+ }
417
+ .highlight.js.jsx {
418
+ .code {
419
+ &:after {
420
+ content: 'JSX';
421
+ }
422
+ }
423
+ }
424
+ .highlight.bash.jsx {
425
+ .code {
426
+ &:after {
427
+ content: 'JSX';
428
+ }
429
+ }
430
+ }
431
+ .highlight.css.jsx {
432
+ .code {
433
+ &:after {
434
+ content: 'JSX';
435
+ }
436
+ }
437
+ }
438
+ .highlight.jsx.jsx {
439
+ .code {
440
+ &:after {
441
+ content: 'JSX';
442
+ }
443
+ }
444
+ }
445
+ >table {
446
+ width: 100%;
447
+ margin: 20px 0;
448
+ tr {
449
+ border-top: 1px solid #eee;
450
+ &:nth-child(2n) {
451
+ background-color: #f8f8f8;
452
+ }
453
+ }
454
+ th {
455
+ font-family: 'ProximaNova-Semibold';
456
+ padding: 12px 13px;
457
+ border: 1px solid #eee;
458
+ vertical-align: middle;
459
+ }
460
+ td {
461
+ border: 1px solid #eee;
462
+ vertical-align: middle;
463
+ padding: 6px 13px;
464
+ font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
465
+ font-size: 0.8em;
466
+ line-height: 1.6em;
467
+ }
468
+ }
469
+ .bottom-nav {
470
+ height: 44px;
471
+ margin: 30px 0 25px;
472
+ border-bottom: 1px solid #eee;
473
+ padding-bottom: 25px;
474
+ a {
475
+ font-family: 'ProximaNova-Semibold';
476
+ margin: 0 5px;
477
+ }
478
+ }
479
+ .edit-link {
480
+ text-align: center;
481
+ a {
482
+ color: #aaa;
483
+ font-family: 'ProximaNova-Semibold';
484
+ &:before {
485
+ content: '';
486
+ display: inline-block;
487
+ width: 16px;
488
+ height: 16px;
489
+ background-size: 16px;
490
+ opacity: 0.3;
491
+ margin-right: 8px;
492
+ position: relative;
493
+ top: 2px;
494
+ }
495
+ }
496
+ }
497
+ }