-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublish.py
More file actions
144 lines (111 loc) · 3.76 KB
/
Publish.py
File metadata and controls
144 lines (111 loc) · 3.76 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# M_ : MathML
# H_ : HTML
# from Publish import *
class aLine:
Name = 'aLine'
def __init__(self, Astring=''):
self.S = Astring + '\n'
def indent(self, Size=2):
self.S = (Size * ' ') + self.S
def Markup(self, Mark, Content, Prop=''):
self.S = '<' + Mark
if Prop == '':
self.S += '>'
else:
self.S += ' ' + Prop + '>'
self.S += Content
self.S += '</' + Mark + '> \n'
class aCluster:
Name = 'aCluster'
def __init__(self, IndentSize=2):
self.L = [] # List of aLine
self.IndentSize = IndentSize
def indent(self, Size=2):
for mem in self.L:
mem.indent(Size*self.IndentSize)
def ResetList(self):
del self.L
self.L = []
def __add__(self, other): # return new object
robject=aCluster()
for mem in self.L:
robject.L.append(mem)
for mem in other.L:
robject.L.append(mem)
return robject
def Markup(self, Mark, Content, Prop='', Indent=0):
if Content.Name == 'aCluster': # protect from self reference
ContentCl = aCluster()
for each in Content.L:
ContentCl.L.append(each)
self.ResetList()
str = '<' + Mark
if Prop == '':
str += '>'
else:
str += ' ' + Prop + '>'
self.L.insert(0, aLine(str))
if Content.Name == 'aLine':
self.L.append(Content)
Content.indent(self.IndentSize) # Apply Default Indent
if Content.Name == 'aCluster':
for eachCl in ContentCl.L:
eachCl.indent(self.IndentSize)
self.L.append(eachCl)
self.L.append(aLine('</'+ Mark + '>'))
for mem in self.L:
mem.indent(Indent*self.IndentSize)
def Publish(self):
rvalue = ''
for mem in self.L:
rvalue += mem.S
return rvalue
def Print(self):
for mem in self.L:
print mem.S
def testCluster(indent):
al = aLine()
al.Markup('p', 'New content', 'class=asdf')
ac = aCluster()
ac.Markup('td', al, 'prop', 1)
ac.Markup('tr', ac, 'classasdfsdf', indent)
ac.Markup('table', ac, 'table propclassasdfsdf', 1)
rv = ac.Publish()
print rv
def H_PrintHead(StyleRef, Title):
str = """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
"""
str += '<title>' + Title + '</title> \n'
# <meta name="generator" content="Namo WebEditor v4.0">
str += '<link rel="stylesheet" href="' + StyleRef + '"> \n'
str += '</head>'
return str
def H_Header(border, Company, Title, PageNum):
# border : border thickness
# Company : Name
# ob = H_Header(1, "Company", 'Title', 24)
al = aLine()
al.Markup('p', Company, 'class="Title1"')
col1 = aCluster()
col1.Markup('td', al, 'width="50%"')
al = aLine(); col2 = aCluster()
al.Markup('p', 'Project Name :', 'class="Small"')
col2.L.append(al)
al = aLine()
al.Markup('p', Title, 'class="Title1"')
col2.L.append(al)
col2.Markup('td', col2, 'width="25%"')
al = aLine(); col3 = aCluster()
al.Markup('p', 'Page Number :', 'class="Small"')
col3.L.append(al)
al = aLine()
al.Markup('p', str(PageNum), 'class="Title1"')
col3.L.append(al)
col3.Markup('td', col3, 'width="25%"')
robject = aCluster()
robject.Markup('table', col1 + col2 + col3, 'border="' + str(border) + '" width="100%"')
return robject
# from Publish import *