Module: Documentary::View

Included in:
Generator
Defined in:
lib/documentary/view/helpers.rb

Instance Method Summary collapse

Instance Method Details

#code_blockObject Also known as: start_code_block, end_code_block



108
109
110
# File 'lib/documentary/view/helpers.rb', line 108

def code_block
  '```'
end

#endpoint_blocksObject



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
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/documentary/view/helpers.rb', line 46

def endpoint_blocks
  io = StringIO.new
  io.puts "## #{link_to('Endpoints')}"
  io.puts new_line
  docblocks.endpoints.each do |endpoint|
    io.puts "### #{link_to(endpoint.title)}"
    io.puts new_line
    io.puts endpoint.notes if endpoint.notes
    io.puts new_line
    io.puts '#### Enpoint URL'
    io.puts new_line
    io.puts start_code_block
    io.puts "#{endpoint.verb} #{endpoint.endpoint}"
    io.puts end_code_block
    if endpoint.information
      io.puts '#### Endpoint Information'
      io.puts new_line
      endpoint.information.each do |key, value|
        io.puts "* **#{key.titleize}**: #{value}"
      end
    end
    if endpoint.params
      io.puts new_line
      io.puts '#### Parameters'
      io.puts new_line
      io.puts 'Name     | Required | Description'
      io.puts '-------- | -------- | -----------'
      endpoint.params.each do |param|
        io.puts "#{param.keys.first} | #{param['required']} | #{param['notes'].strip}"
      end
    end
    if endpoint.example_request
      io.puts new_line
      io.puts '#### Example Request'
      io.puts new_line
      example_request = YAML.load(endpoint.example_request)
      if example_request['query']
        io.puts start_code_block
        io.puts "#{endpoint.verb} #{endpoint.endpoint}" << '?' << query_params(example_request['query'])
        io.puts end_code_block
      end
      if example_request['body']
        io.puts start_code_block
        example_request['body'].each do |b|
          io.puts request_payload(b)
          io.puts new_line
        end
        io.puts start_code_block
      end
    end
    if endpoint.example_response
      io.puts new_line
      io.puts '#### Example Response'
      io.puts new_line
      io.puts start_code_block
      io.puts JSON.pretty_generate(endpoint.example_response)
      io.puts end_code_block
    end
  end
  io.string
end

#resource_blocksObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/documentary/view/helpers.rb', line 31

def resource_blocks
  io = StringIO.new
  io.puts "## #{link_to('Resources')}"
  io.puts new_line
  docblocks.resources.each do |resource|
    io.puts "### #{link_to(resource.title)}"
    io.puts new_line
    io.puts resource.description
    io.puts new_line
    resource_attributes(resource, io)
  end
  io.puts new_line
  io.string
end

#title_blocksObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/documentary/view/helpers.rb', line 20

def title_blocks
  io = StringIO.new
  docblocks.title_blocks.each do |title_block|
    io.puts "## #{title_block.title}"
    io.puts new_line
    io.puts title_block.content
    io.puts new_line
  end
  io.string
end

#tocObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/documentary/view/helpers.rb', line 5

def toc
  io = StringIO.new
  io.puts "### [Resources](#resources)"
  io.puts new_line
  docblocks.resources.each do |resource|
    io.puts "* #{link_to(resource.title)}"
  end
  io.puts new_line
  io.puts "### [Endpoints](#endpoints)"
  docblocks.endpoints.each do |endpoint|
    io.puts "* #{link_to(endpoint.title)}"
  end
  io.string
end