Caffe2 - Python API
A deep learning, cross platform ML framework
formatter.py
1 # Copyright (c) 2016-present, Facebook, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 ##############################################################################
15 
16 ## @package formatter
17 # Module caffe2.python.docs.formatter
18 from __future__ import absolute_import
19 from __future__ import division
20 from __future__ import print_function
21 from __future__ import unicode_literals
22 from caffe2.python.docs.parser import Parser
23 
24 
25 class Formatter(object):
26  def __init__(self):
27  self.content = ""
28 
29  def clone(self):
30  return self.__class__()
31 
32  def dump(self):
33  return self.content
34 
35  def parseAndAdd(self, text):
36  text = Parser(text, self).parse()
37  self.addRaw(text)
38 
39  def addRaw(self, text):
40  raise Exception('Not yet implemented.')
41 
42  def addLine(self, text):
43  raise Exception('Not yet implemented.')
44 
45  def addLinebreak(self):
46  raise Exception('Not yet implemented.')
47 
48  def addHeader(self, text):
49  raise Exception('Not yet implemented.')
50 
51  def addEmphasis(self, text):
52  raise Exception('Not yet implemented.')
53 
54  def addList(self, textList):
55  raise Exception('Not yet implemented.')
56 
57  def addLink(self, text, url):
58  raise Exception('Not yet implemented.')
59 
60  def addCode(self, text):
61  raise Exception('Not yet implemented.')
62 
63  def addCodeLink(self, text):
64  raise Exception('Not yet implemented.')
65 
66  def addTable(self, table):
67  raise Exception('Not yet implemented.')
68 
69  def addBreak(self):
70  raise Exception('Not yet implemented.')
71 
72 
74  def addRaw(self, text):
75  self.content += "{text}".format(text=text)
76 
77  def addLine(self, text, new_line=False):
78  self.content += "{line}{text}\n".format(line=('\n' if new_line else ''),
79  text=text)
80 
81  def addLinebreak(self):
82  self.content += "\n"
83 
84  def addHeader(self, text, h=1):
85  self.addLine("{header} {text}".format(header=h * '#', text=text), True)
86 
87  def addEmphasis(self, text, s=1):
88  self.addRaw("{stars}{text}{stars}".format(stars=s * '*', text=text))
89 
90  def addList(self, textList):
91  for text in textList:
92  self.addLine("- {text}".format(text=text), True)
93  self.addLinebreak()
94 
95  def addLink(self, text, url):
96  self.addRaw("[{text}]({url})".format(text=text, url=url))
97 
98  def addCodeLink(self, path, options=None):
99  self.addRaw("({path})".format(path=path))
100 
101  def addCode(self, text, inline=False):
102  if (inline):
103  self.content += "`{text}`".format(text=text)
104  else:
105  self.addRaw("\n\n```\n{text}```\n\n".format(text=text))
106 
107  def addTable(self, table, noTitle=False):
108  self.addLinebreak()
109  assert(len(table) > 1)
110  if noTitle:
111  table.insert(0, [' ' for i in range(len(table[0]))])
112  self.addLine(' | '.join(table[0]))
113  self.addLine(' | '.join(['----' for i in range(len(table[0]))]))
114  for row in table[1:]:
115  self.addLine(' | '.join(row))
116  self.addLinebreak()
117 
118  def addBreak(self):
119  self.addLine('\n---\n', True)
def addLinebreak(self)
Definition: formatter.py:45
def addRaw(self, text)
Definition: formatter.py:39
def addLine(self, text)
Definition: formatter.py:42