forked from sendgrid/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlivedocs.rb
More file actions
95 lines (87 loc) · 2.4 KB
/
Copy pathlivedocs.rb
File metadata and controls
95 lines (87 loc) · 2.4 KB
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
89
90
91
92
93
94
95
require 'rack'
require 'htmlentities'
require 'uri'
module Jekyll
class LiveDocTag < Liquid::Tag
def initialize(tag_name, markup, tokens)
parameters = markup.split(" ")
@identifier = parameters[0]
@method = parameters[1].upcase
@url = parameters[2]
super
end
def render(context)
uri = URI.parse(@url);
if !uri.nil?
base_url = uri.scheme + "://" + uri.host + uri.path
end
#let's make a codeblock to hold our dynamic bash query
#add random content to ensure a unique ID hash for this codeblock
codeblock = Liquid::Template.parse("{% codeblock %}#{rand(10 ** 10)}{% endcodeblock %}").render();
#wondering what this syntax is? google "here document"
output=<<HTML
<div class="live-doc" id="livedoc-#{@identifier}">
<input type="hidden" class="method" value="#{@method}"/>
<input type="hidden" class="url" value="#{base_url}"/>
<form role="form" class="live-form">
<table class="table table-bordered table-striped live-params">
<tbody>
<tr>
<th>Parameter</th>
<th>Value</th>
<th>Requirements</th>
<th>Description</th>
</tr>
<tbody>
</table>
<div class="curl-call">
#{codeblock}
</div>
</form>
<div class="live-call">
<div class="bar-indicator" style="display:none;"></div>
<table class="table table-bordered request-block">
<tbody>
<tr>
<td class="method"></td>
<td>
<code class="call"></code>
</td>
</tr>
<tr class="request-data hidden">
<td>Data</td>
<td>
<code class="data"></code>
</td>
</tr>
<tr class="response-status hidden">
<td>Response Status</td>
<td>
<pre class="status"></pre>
</td>
</tr>
<tr class="response-headers hidden">
<td>Response Headers</td>
<td>
<pre class="headers"></pre>
</td>
</tr>
<tr class="response-body hidden">
<td>Response Body</td>
<td>
<pre class="body"></pre>
</td>
</tr>
</tbody>
</table>
<div class="text-center">
<button type="input" id="clear-request-#{@identifier}" class="clear-request btn btn-warning">Clear</button>
</div>
</div>
</div>
HTML
output
end
end
end
Liquid::Template.register_tag('livedoc', Jekyll::LiveDocTag)