Skip to content

Commit 62c76ab

Browse files
committed
Split the parts of a route docs into sub templates
this means we can use the same templates for different routes, reducing code duplication.
1 parent 7721e1b commit 62c76ab

24 files changed

+235
-605
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<h3>Arguments</h3>
2+
<table class="arguments">
3+
{% for arg in include.args %}
4+
<tr>
5+
<td>
6+
{% if include.link %}
7+
<code><a href="#schema-{{ arg[0] }}">{{ arg[0] }}</a></code><br />
8+
{% else %}
9+
<code>{{ arg[0] }}</code><br />
10+
{% endif %}
11+
</td>
12+
<td>
13+
{% if arg[1].required %}
14+
<p class="required">
15+
Required: {{ arg[1].required }}
16+
</p>
17+
{% endif %}
18+
{% if arg[1].default %}
19+
<p class="default">
20+
Default: <code>{{ arg[1].default }}</code>
21+
</p>
22+
{% endif %}
23+
</td>
24+
</tr>
25+
{% endfor %}
26+
</table>
27+
{% if include.args.size == 0 %}
28+
<p>There are no arguments for this enpdoint.
29+
{% endif %}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<section class="route">
2+
<h2>Create a {{ page.resource }}</h2>
3+
<div class="primary">
4+
{% assign args = include.route.endpoints[1].args %}
5+
{% include reference-parts/args-list.html args=args link=true %}
6+
</div>
7+
<div class="secondary">
8+
<h3>Definition</h3>
9+
10+
<code>POST http://demo.wp-api.org/wp-json{{ include.route.nicename }}</code>
11+
</div>
12+
</section>
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
<section class="route">
3+
<h2>Delete a {{ page.resource }}</h2>
4+
5+
<div class="primary">
6+
{% assign args = include.route.endpoints[2].args %}
7+
{% include reference-parts/args-list.html args=args %}
8+
</div>
9+
<div class="secondary">
10+
<h3>Definition</h3>
11+
12+
<code>DELETE {{ include.route.nicename }}</code>
13+
14+
<h3>Example Request</h3>
15+
16+
<code>$ curl -X DELETE http://demo.wp-api.org/wp-json{{ include.route.nicename }}</code>
17+
</div>
18+
</section>

_includes/reference-parts/examples/update-attachment-curl.html

Whitespace-only changes.

_includes/reference-parts/examples/update-comment-curl.html

Whitespace-only changes.

_includes/reference-parts/examples/update-meta-curl.html

Whitespace-only changes.

_includes/reference-parts/examples/update-page-curl.html

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ curl -X POST http://demo.wp-api.org/wp-json{{ include.route.nicename }} -d '{"title":"My New Title"}'

_includes/reference-parts/examples/update-term-curl.html

Whitespace-only changes.

_includes/reference-parts/examples/update-user-curl.html

Whitespace-only changes.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<section class="route">
2+
<h2>Retrieve a {{ page.resource }}</h2>
3+
4+
<div class="primary">
5+
{% assign args = include.route.endpoints[0].args %}
6+
{% include reference-parts/args-list.html args=args link=false %}
7+
</div>
8+
<div class="secondary">
9+
<h3>Definition</h3>
10+
11+
<code>GET http://demo.wp-api.org/wp-json{{ include.route.nicename }}</code>
12+
13+
<h3>Example Request</h3>
14+
15+
<code>$ curl http://demo.wp-api.org/wp-json{{ include.route.nicename }}</code>
16+
</div>
17+
</section>
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<section class="route">
2+
<h2>List {{ page.resource }}s</h2>
3+
4+
<div class="primary">
5+
{% assign args = include.route.endpoints[0].args %}
6+
{% include reference-parts/args-list.html args=args link=false %}
7+
</div>
8+
<div class="secondary">
9+
<h3>Definition</h3>
10+
11+
<code> GET http://demo.wp-api.org/wp-json{{ include.route.nicename }}</code>
12+
13+
<h3>Example Request</h3>
14+
15+
<code>$ curl http://demo.wp-api.org/wp-json{{ include.route.nicename }}</code>
16+
</div>
17+
</section>

_includes/reference-parts/schema.html

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<h2>Schema</h2>
2+
<p>The schema defines all the fields that exist for a {{ include.schema.title }} object.</p>
3+
<table class="attributes">
4+
{% for property in include.schema.properties %}
5+
<tr id="schema-{{ property[0] }}">
6+
<td>
7+
<code>{{ property[0] }}</code><br />
8+
<span class="type">
9+
{{ property[1].type }}{% if property[1].format %}, {% case property[1].format %}
10+
{% when 'date-time' %}
11+
datetime (ISO8601)
12+
{% when 'uri' %}
13+
uri
14+
{% else %}
15+
property[1].format
16+
{% endcase %}{% endif %}
17+
</span>
18+
</td>
19+
<td>
20+
<p>{{ property[1].description }}</p>
21+
{% if property[1].readonly %}
22+
<p class="read-only">Read only</p>
23+
{% endif %}
24+
<p class="context">Context: <code>{{ property[1].context | join:"</code>, <code>"}}</code></p>
25+
{% if property[1].enum %}
26+
<p>One of: <code>{{ property[1].enum | join:"</code>, <code>"}}</code></p>
27+
{% endif %}
28+
</td>
29+
</tr>
30+
{% endfor %}
31+
</table>
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<section class="route">
2+
<h2>Update a {{ page.resource }}</h2>
3+
4+
<div class="primary">
5+
{% assign args = include.route.endpoints[1].args %}
6+
{% include reference-parts/args-list.html args=args link=true %}
7+
</div>
8+
<div class="secondary">
9+
<h3>Definition</h3>
10+
11+
<code>POST http://demo.wp-api.org/wp-json{{ include.route.nicename }}</code>
12+
13+
<h3>Example Request</h3>
14+
{% capture example_include %}reference-parts/examples/update-{{ include.route.schema.title }}-curl.html{% endcapture %}
15+
16+
<code>{% include {{ example_include }} %}</code>
17+
</div>
18+
</section>

reference/comments/index.md

+12-94
Original file line numberDiff line numberDiff line change
@@ -7,108 +7,26 @@ resource: Comment
77

88
<section class="route">
99
<div class="primary">
10-
<h2>{{ page.resource }} Object Schema</h2>
11-
<table class="attributes">
12-
{% for property in site.data.comments.schema.properties %}
13-
<tr>
14-
<td>
15-
<code>{{ property[0] }}</code><br />
16-
<span class="type">
17-
{{ property[1].type }}{% if property[1].format %}, {% case property[1].format %}
18-
{% when 'date-time' %}
19-
datetime (ISO8601)
20-
{% when 'uri' %}
21-
uri
22-
{% else %}
23-
property[1].format
24-
{% endcase %}{% endif %}
25-
</span>
26-
</td>
27-
<td>
28-
<p>{{ property[1].description }}</p>
29-
{% if property[1].readonly %}
30-
<p>(Read only)</p>
31-
{% endif %}
32-
<p class="context">Context: <code>{{ property[1].context | join:"</code>, <code>"}}</code></p>
33-
</td>
34-
</tr>
35-
{% endfor %}
36-
</table>
10+
{% include reference-parts/schema.html schema=site.data.comment.schema %}
3711
</div>
3812
<div class="secondary">
3913
<h3>Example Request</h3>
4014

41-
<code>$ curl -X OPTIONS -i http://demo.wp-api.org/{{ page.route_path }}</code>
15+
$ curl -X OPTIONS -i http://demo.wp-api.org/{{ site.data.comment.routes['/wp/v2/comments'].nicename }}
4216
</div>
4317
</section>
4418

45-
<section class="route">
46-
<h2>List all {{ page.resource }}s</h2>
47-
48-
<div class="primary">
49-
<h3>Arguments</h3>
50-
<table class="arguments">
51-
{% for arg in site.data.comments.endpoints[0].args %}
52-
<tr>
53-
<td>
54-
<code>{{ arg[0] }}</code><br />
55-
</td>
56-
<td>
57-
<p class="required">
58-
Required: {{ arg[1].required }}
59-
</p>
60-
<p class="default">
61-
{% if arg[1].default %}
62-
Default: <code>{{ arg[1].default }}</code>
63-
{% endif %}
64-
</p>
65-
</td>
66-
</tr>
67-
{% endfor %}
68-
</table>
69-
</div>
70-
<div class="secondary">
71-
<h3>Definition</h3>
19+
{% assign route=site.data.comment.routes['/wp/v2/comments'] %}
20+
{% include reference-parts/list-item.html route=route %}
7221

73-
<code> {{ site.data.comments.endpoints[0].methods[0] }} http://demo.wp-api.org/{{ page.route_path }}</code>
74-
75-
<h3>Example Request</h3>
22+
{% assign route=site.data.comment.routes['/wp/v2/comments/<id>'] %}
23+
{% include reference-parts/get-item.html route=route %}
7624

77-
<code>$ curl http://demo.wp-api.org/{{ page.route_path}}</code>
78-
</div>
79-
</section>
80-
<section class="route">
81-
<h2>Create a {{ page.resource }}</h2>
82-
<div class="primary">
83-
<h3>Arguments</h3>
84-
<table class="arguments">
85-
{% for arg in site.data.comments.endpoints[1].args %}
86-
<tr>
87-
<td>
88-
<code>{{ arg[0] }}</code><br />
89-
</td>
90-
<td>
91-
<p class="required">
92-
Required: {{ arg[1].required }}
93-
</p>
94-
<p class="default">
95-
{% if arg[1].default %}
96-
Default: <code>{{ arg[1].default }}</code>
97-
{% endif %}
98-
</p>
99-
</td>
100-
</tr>
101-
{% endfor %}
102-
</table>
103-
</div>
104-
<div class="secondary">
105-
<h3>Definition</h3>
106-
107-
<code> {{ site.data.comments.endpoints[1].methods[0] }} http://demo.wp-api.org/{{ page.route_path }}</code>
108-
</div>
109-
</section>
110-
<h2>Retrieve a {{ page.resource }}</h2>
25+
{% assign route=site.data.comment.routes['/wp/v2/comments'] %}
26+
{% include reference-parts/create-item.html route=route %}
11127

112-
<h2>Update a {{ page.resource }}</h2>
28+
{% assign route=site.data.comment.routes['/wp/v2/comments/<id>'] %}
29+
{% include reference-parts/update-item.html route=route %}
11330

114-
<h2>Delete a {{page.resource}}</h2>
31+
{% assign route=site.data.comment.routes['/wp/v2/comments/<id>'] %}
32+
{% include reference-parts/delete-item.html route=route %}

reference/media/index.md

+12-33
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,26 @@ resource: Media
77

88
<section class="route">
99
<div class="primary">
10-
<h2>Schema</h2>
11-
<table class="attributes">
12-
{% for property in site.data.media.schema.properties %}
13-
<tr>
14-
<td>
15-
<code>{{ property[0] }}</code><br />
16-
<span class="type">
17-
{{ property[1].type }}{% if property[1].format %}, {% case property[1].format %}
18-
{% when 'date-time' %}
19-
datetime (ISO8601)
20-
{% when 'uri' %}
21-
uri
22-
{% else %}
23-
property[1].format
24-
{% endcase %}{% endif %}
25-
</span>
26-
</td>
27-
<td>
28-
<p>{{ property[1].description }}</p>
29-
{% if property[1].readonly %}
30-
<p>(Read only)</p>
31-
{% endif %}
32-
<p class="context">Context: <code>{{ property[1].context | join:"</code>, <code>"}}</code></p>
33-
</td>
34-
</tr>
35-
{% endfor %}
36-
</table>
10+
{% include reference-parts/schema.html schema=site.data.attachment.schema %}
3711
</div>
3812
<div class="secondary">
3913
<h3>Example Request</h3>
4014

41-
$ curl -X OPTIONS -i http://demo.wp-api.org/{{ page.route_path }}
15+
$ curl -X OPTIONS -i http://demo.wp-api.org/{{ site.data.attachment.routes['/wp/v2/media'].nicename }}
4216
</div>
4317
</section>
4418

45-
### List all {{ page.resource }}
19+
{% assign route=site.data.attachment.routes['/wp/v2/media'] %}
20+
{% include reference-parts/list-item.html route=route %}
4621

47-
### Create a {{ page.resource }}
22+
{% assign route=site.data.attachment.routes['/wp/v2/media/<id>'] %}
23+
{% include reference-parts/get-item.html route=route %}
4824

49-
### Retrieve a {{ page.resource }}
25+
{% assign route=site.data.attachment.routes['/wp/v2/media'] %}
26+
{% include reference-parts/create-item.html route=route %}
5027

51-
### Update a {{ page.resource }}
28+
{% assign route=site.data.attachment.routes['/wp/v2/media/<id>'] %}
29+
{% include reference-parts/update-item.html route=route %}
5230

53-
### Delete a {{page.resource}}
31+
{% assign route=site.data.attachment.routes['/wp/v2/media/<id>'] %}
32+
{% include reference-parts/delete-item.html route=route %}

reference/pages/index.md

+12-33
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,26 @@ resource: Page
77

88
<section class="route">
99
<div class="primary">
10-
<h2>Schema</h2>
11-
<table class="attributes">
12-
{% for property in site.data.pages.schema.properties %}
13-
<tr>
14-
<td>
15-
<code>{{ property[0] }}</code><br />
16-
<span class="type">
17-
{{ property[1].type }}{% if property[1].format %}, {% case property[1].format %}
18-
{% when 'date-time' %}
19-
datetime (ISO8601)
20-
{% when 'uri' %}
21-
uri
22-
{% else %}
23-
property[1].format
24-
{% endcase %}{% endif %}
25-
</span>
26-
</td>
27-
<td>
28-
<p>{{ property[1].description }}</p>
29-
{% if property[1].readonly %}
30-
<p>(Read only)</p>
31-
{% endif %}
32-
<p class="context">Context: <code>{{ property[1].context | join:"</code>, <code>"}}</code></p>
33-
</td>
34-
</tr>
35-
{% endfor %}
36-
</table>
10+
{% include reference-parts/schema.html schema=site.data.page.schema %}
3711
</div>
3812
<div class="secondary">
3913
<h3>Example Request</h3>
4014

41-
$ curl -X OPTIONS -i http://demo.wp-api.org/{{ page.route_path }}
15+
$ curl -X OPTIONS -i http://demo.wp-api.org/{{ site.data.page.routes['/wp/v2/pages'].nicename }}
4216
</div>
4317
</section>
4418

45-
### List all {{ page.resource }}s
19+
{% assign route=site.data.page.routes['/wp/v2/pages'] %}
20+
{% include reference-parts/list-item.html route=route %}
4621

47-
### Create a {{ page.resource }}
22+
{% assign route=site.data.page.routes['/wp/v2/pages/<id>'] %}
23+
{% include reference-parts/get-item.html route=route %}
4824

49-
### Retrieve a {{ page.resource }}
25+
{% assign route=site.data.page.routes['/wp/v2/pages'] %}
26+
{% include reference-parts/create-item.html route=route %}
5027

51-
### Update a {{ page.resource }}
28+
{% assign route=site.data.page.routes['/wp/v2/pages/<id>'] %}
29+
{% include reference-parts/update-item.html route=route %}
5230

53-
### Delete a {{ page.resource }}
31+
{% assign route=site.data.page.routes['/wp/v2/pages/<id>'] %}
32+
{% include reference-parts/delete-item.html route=route %}

0 commit comments

Comments
 (0)