forked from sendgrid/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_parameter_row.rb
More file actions
54 lines (48 loc) · 1.46 KB
/
Copy pathapi_parameter_row.rb
File metadata and controls
54 lines (48 loc) · 1.46 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
#require 'kramdown'
module Jekyll
class APITableParams < Liquid::Tag
def initialize(tag_name, markup, tokens)
parameters = markup.shellsplit
@name = parameters[0]
@type = parameters[1]
@row_type = ""
@required = parameters[2]
@row_required = parameters[2] == "Yes" ? "required" : "not-required"
@constraints = parameters[3]
@description = parameters[4]
@depth = defined?(parameters[5]) ? parameters[5] : 0
if @type.include? "array"
@row_type = "array"
elsif @type.include? "object"
@row_type = "object"
elsif @type.include? "string"
@row_type = "string"
elsif @type.include? "number"
@row_type = "int"
elsif @type.include? "integer"
@row_type = "int"
elsif @type.include? "boolean"
@row_type = "bool"
end
super
end
def render(context)
output=<<HTML
<tr class="depth-#{@depth} #{@row_required} details-closed" name="#{@name}">
<td colspan="2" class="param #{@row_type}">#{@name}</td>
<td>#{@type}</td>
<td>#{@required}</td>
<td>#{@constraints}</td>
<td class="details-caret"><img src="/images/caret.svg"></td>
</tr>
<tr class="details-row">
<td colspan="2"></td>
<td colspan="4">#{@description}</td>
</tr>
HTML
#html = Kramdown::Document.new(output).to_html
return Liquid::Template.parse(output).render context
end
end
end
Liquid::Template.register_tag('api_table_param', Jekyll::APITableParams)