Skip to content
This repository was archived by the owner on Jan 22, 2020. It is now read-only.

Commit f64b974

Browse files
committed
refactor: separate files for each class
1 parent 29ed680 commit f64b974

File tree

3 files changed

+43
-53
lines changed

3 files changed

+43
-53
lines changed

docsmaker/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from maker import HugoDoc
1+
from maker import DocsMaker
2+
from hugo_doc import HugoDoc

docsmaker/hugo_doc.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from PIL import Image
2+
from io import StringIO
3+
from datetime import datetime
4+
import os
5+
6+
7+
class HugoDoc(object):
8+
"""
9+
A utility for creating hugo/markdown docs.
10+
"""
11+
def __init__(self, title='', tags=[]):
12+
self.title = title
13+
self.meta = {}
14+
self.buff = StringIO()
15+
self.meta['tags'] = tags
16+
17+
def header(self):
18+
lines = ['title = "%s"' % self.title]
19+
for key, val in self.meta.items():
20+
if isinstance(val, list):
21+
lines.append('%s = %s' % (key, val))
22+
else:
23+
lines.append('%s = "%s"' % (key, val))
24+
# auto date
25+
self.date = str(datetime.now().isoformat())
26+
lines.append('date = "%s"' % self.date)
27+
lines.insert(0, '+++')
28+
lines.append('+++')
29+
return '\n'.join(lines)
30+
31+
def writeline(self, s=u''):
32+
self.buff.writelines(s)
33+
self.buff.writelines(u'\n')
34+
35+
def getcontents(self):
36+
return self.header() + '\n\n' + self.buff.getvalue()

docsmaker/maker.py

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
from PIL import Image
22
from io import StringIO
33
from datetime import datetime
4+
from slugify import UniqueSlugify
45
import os
56

7+
slugger = UniqueSlugify()
8+
9+
from hugo_doc import HugoDoc
10+
611

712
class DocsMaker(object):
813
"""A documentation site maker."""
@@ -80,55 +85,3 @@ def end_step(self, context, step):
8085
# write the step information to file
8186
self.doc.writeline(u'%s %s | %s | %0.2f | %s' % (step.keyword, step.name, step.status, step.duration, image_code))
8287

83-
84-
class HugoDoc(object):
85-
"""
86-
A utility for creating hugo/markdown docs.
87-
How it should work:
88-
>>> doc = HugoDoc(title='Page One')
89-
>>> print doc.header()
90-
+++
91-
title = "Page One"
92-
tags = []
93-
date = "2016-08-14T09:45:27.006975"
94-
+++
95-
>>> doc.writeline(u'A description goes here')
96-
>>> print doc.getcontents()
97-
+++
98-
title = "Page One"
99-
+++
100-
<BLANKLINE>
101-
A description goes here
102-
<BLANKLINE>
103-
>>> doc.meta['number'] = 5
104-
>>> print doc.header()
105-
+++
106-
title = "Page One"
107-
+++
108-
"""
109-
def __init__(self, title='', tags=[]):
110-
self.title = title
111-
self.meta = {}
112-
self.buff = StringIO()
113-
self.meta['tags'] = tags
114-
115-
def header(self):
116-
lines = ['title = "%s"' % self.title]
117-
for key, val in self.meta.items():
118-
if isinstance(val, list):
119-
lines.append('%s = %s' % (key, val))
120-
else:
121-
lines.append('%s = "%s"' % (key, val))
122-
# auto date
123-
self.date = str(datetime.now().isoformat())
124-
lines.append('date = "%s"' % self.date)
125-
lines.insert(0, '+++')
126-
lines.append('+++')
127-
return '\n'.join(lines)
128-
129-
def writeline(self, s=u''):
130-
self.buff.writelines(s)
131-
self.buff.writelines(u'\n')
132-
133-
def getcontents(self):
134-
return self.header() + '\n\n' + self.buff.getvalue()

0 commit comments

Comments
 (0)