ProjectWeb/Html5ToCss3Converter.py

Fri, 02 Jan 2015 16:22:30 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 02 Jan 2015 16:22:30 +0100
changeset 6
a1600fa29542
parent 5
31bc1ef6f624
child 18
586a57c396b2
permissions
-rw-r--r--

A few fixes and code style corrections.

1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
4
6438afaad632 Updated copyright for 2015.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3
diff changeset
3 # Copyright (c) 2014 - 2015 Detlev Offenbach <detlev@die-offenbachs.de>
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the HTML5 to CSS3 converter.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import datetime
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import getpass
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 import random
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from PyQt5.QtCore import QObject
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from PyQt5.QtWidgets import QDialog
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 from .Html5ToCss3ConverterParameterDialog import \
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Html5ToCss3ConverterParameterDialog
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 class Html5ToCss3Converter(QObject):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Class implementing the HTML5 to CSS3 converter.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 CssTemplate7 = "{0}{1}{2}{3}{4}{5}{6}"
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 CssTemplate8 = "{0}{1}{2}{3}{4}{5}{6}{7}"
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Placeholders = ('margin:0', 'padding:0', 'border:0', 'font-size:100%',
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 'font:inherit', 'vertical-align:baseline', 'line-height:1',
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 'outline:0', 'font-weight:inherit', 'font-style:inherit',
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 'font-family:inherit', 'vertical-align:baseline')
3
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
34 TagsToIgnore = ('head', 'meta', 'noscript', 'script', 'style', 'link',
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
35 'no-js', 'title', 'object', 'col', 'colgroup', 'option',
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
36 'param', 'audio', 'basefont', 'isindex', 'svg', 'area',
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
37 'embed', 'br')
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 def __init__(self, html, parent=None):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Constructor
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 @param html HTML text to be converted (string)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @param parent reference to the parent object (QObject)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 super(Html5ToCss3Converter, self).__init__(parent)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__html = html
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 def getCss3(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 Public method to get the converted CSS3 text.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @return CSS3 text (string)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 dlg = Html5ToCss3ConverterParameterDialog()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 if dlg.exec_() == QDialog.Accepted:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 indentation, placeholders = dlg.getData()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__createSoup()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
3
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
62 alreadyDone = list(self.TagsToIgnore)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 css = '@charset "utf-8";{0}'.format(os.linesep)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 css += "/* {0} by {1}*/{2}".format(
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 datetime.datetime.now().isoformat().split(".")[0],
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 getpass.getuser(),
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 2 * os.linesep
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 )
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 # step 1: tags
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 for tag in self.__getTags():
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 if tag not in alreadyDone:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 css += self.CssTemplate7.format(
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 tag,
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 "{",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 os.linesep,
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 indentation,
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 random.choice(self.Placeholders) + os.linesep
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
80 if placeholders else os.linesep,
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 "}",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 os.linesep
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 )
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 alreadyDone.append(tag)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 css += "/*{0}*/{1}".format(
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 "-" * 75,
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 os.linesep
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 )
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 # step 2: IDs
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 for id_ in self.__getIds():
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 if id_ not in alreadyDone:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 css += "/* {0} */{1}".format(
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 "_".join(id_).lower(),
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 os.linesep
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 )
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 css += self.CssTemplate8.format(
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 "#",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 id_[1],
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 "{",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 os.linesep,
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 indentation,
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 random.choice(self.Placeholders) + os.linesep
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
104 if placeholders else os.linesep,
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 "}",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 os.linesep
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 )
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 alreadyDone.append(id_)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 css += "/*{0}*/{1}".format(
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 "-" * 75,
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 os.linesep
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 )
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 # step 3: classes
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 for class_ in self.__getClasses():
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 if class_ not in alreadyDone:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 css += "/* {0} */{1}".format(
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 "_".join(class_).lower(),
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 os.linesep
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 )
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 css += self.CssTemplate8.format(
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 ".",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 ", .".join(class_[1].split()),
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 "{",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 os.linesep,
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 indentation,
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 random.choice(self.Placeholders) + os.linesep
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
128 if placeholders else os.linesep,
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 "}",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 os.linesep
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 )
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 alreadyDone.append(class_)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 else:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 css = ""
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 return css.strip()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 def __createSoup(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 Private method to get a BeaitifulSoup object with our HTML text.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 from bs4 import BeautifulSoup
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 self.__soup = BeautifulSoup(BeautifulSoup(self.__html).prettify())
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 def __getTags(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 Private method to extract all tags of the HTML text.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 @return list of all tags (list of strings)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 tags = [t.name for t in self.__soup.find_all(True)]
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 return list(set(tags))
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 def __getClasses(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 Private method to extract all classes of the HTML text.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @return list of tuples containing the tag name and its classes
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 as a blank separated string (list of tuples of two strings)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 classes = [(t.name, " ".join(t["class"])) for t in
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.__soup.find_all(True, {"class": True})]
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 return sorted(list(set(classes)))
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 def __getIds(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 Private method to extract all IDs of the HTML text.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 @return list of tuples containing the tag name and its ID
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 (list of tuples of two strings)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 ids = [(t.name, t["id"]) for t in
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 self.__soup.find_all(True, {"id": True})]
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 return sorted(list(set(ids)))

eric ide

mercurial