Caffe2 - Python API
A deep learning, cross platform ML framework
formatter.py
1 ## @package formatter
2 # Module caffe2.python.docs.formatter
3 from __future__ import absolute_import
4 from __future__ import division
5 from __future__ import print_function
6 from __future__ import unicode_literals
7 from caffe2.python.docs.parser import Parser
8 
9 
10 class Formatter(object):
11  def __init__(self):
12  self.content = ""
13 
14  def clone(self):
15  return self.__class__()
16 
17  def dump(self):
18  return self.content
19 
20  def parseAndAdd(self, text):
21  text = Parser(text, self).parse()
22  self.addRaw(text)
23 
24  def addRaw(self, text):
25  raise Exception('Not yet implemented.')
26 
27  def addLine(self, text):
28  raise Exception('Not yet implemented.')
29 
30  def addLinebreak(self):
31  raise Exception('Not yet implemented.')
32 
33  def addHeader(self, text):
34  raise Exception('Not yet implemented.')
35 
36  def addEmphasis(self, text):
37  raise Exception('Not yet implemented.')
38 
39  def addList(self, textList):
40  raise Exception('Not yet implemented.')
41 
42  def addLink(self, text, url):
43  raise Exception('Not yet implemented.')
44 
45  def addCode(self, text):
46  raise Exception('Not yet implemented.')
47 
48  def addCodeLink(self, text):
49  raise Exception('Not yet implemented.')
50 
51  def addTable(self, table):
52  raise Exception('Not yet implemented.')
53 
54  def addBreak(self):
55  raise Exception('Not yet implemented.')
56 
57 
59  def addRaw(self, text):
60  self.content += "{text}".format(text=text)
61 
62  def addLine(self, text, new_line=False):
63  self.content += "{line}{text}\n".format(line=('\n' if new_line else ''),
64  text=text)
65 
66  def addLinebreak(self):
67  self.content += "\n"
68 
69  def addHeader(self, text, h=1):
70  self.addLine("{header} {text}".format(header=h * '#', text=text), True)
71 
72  def addEmphasis(self, text, s=1):
73  self.addRaw("{stars}{text}{stars}".format(stars=s * '*', text=text))
74 
75  def addList(self, textList):
76  for text in textList:
77  self.addLine("- {text}".format(text=text), True)
78  self.addLinebreak()
79 
80  def addLink(self, text, url):
81  self.addRaw("[{text}]({url})".format(text=text, url=url))
82 
83  def addCodeLink(self, path, options=None):
84  self.addRaw("({path})".format(path=path))
85 
86  def addCode(self, text, inline=False):
87  if (inline):
88  self.content += "`{text}`".format(text=text)
89  else:
90  self.addRaw("\n\n```\n{text}```\n\n".format(text=text))
91 
92  def addTable(self, table, noTitle=False):
93  self.addLinebreak()
94  assert(len(table) > 1)
95  if noTitle:
96  table.insert(0, [' ' for i in range(len(table[0]))])
97  self.addLine(' | '.join(table[0]))
98  self.addLine(' | '.join(['----' for i in range(len(table[0]))]))
99  for row in table[1:]:
100  self.addLine(' | '.join(row))
101  self.addLinebreak()
102 
103  def addBreak(self):
104  self.addLine('\n---\n', True)