1 """combines sheets referred to by @import rules in a given CSS proxy sheet
2 into a single new sheet.
3
4 - proxy currently is a path (no URI)
5 - in @import rules only relative paths do work for now but should be used
6 anyway
7 - currently no nested @imports are resolved
8 - messages are send to stderr
9 - output to stdout.
10
11 Example::
12
13 csscombine sheets\csscombine-proxy.css -m -t ascii -s utf-8
14 1>combined.css 2>log.txt
15
16 results in log.txt::
17
18 COMBINING sheets\csscombine-proxy.css
19 USING SOURCE ENCODING: utf-8
20 * PROCESSING @import sheets\csscombine-1.css
21 * PROCESSING @import sheets\csscombine-2.css
22 SETTING TARGET ENCODING: ascii
23
24 and combined.css::
25
26 @charset "ascii";a{color:green}body{color:#fff;background:#000}
27
28 or without option -m::
29
30 @charset "ascii";
31 /* proxy sheet which imports sheets which should be combined \F6 \E4 \FC */
32 /* @import "csscombine-1.css"; */
33 /* combined sheet 1 */
34 a {
35 color: green
36 }
37 /* @import url(csscombine-2.css); */
38 /* combined sheet 2 */
39 body {
40 color: #fff;
41 background: #000
42 }
43
44 issues
45
46 - URL or file hrefs? URI should be default and therefor baseURI is needed
47 - no nested @imports are resolved yet
48 - namespace rules are not working yet!
49 - @namespace must be resolved (all should be moved to top of main sheet?
50 but how are different prefixes resolved???)
51
52 - maybe add a config file which is used?
53
54 """
55 __all__ = ['csscombine']
56 __docformat__ = 'restructuredtext'
57 __version__ = '$Id: csscombine.py 1116 2008-03-05 13:52:23Z cthedot $'
58
59 import os
60 import sys
61 import cssutils
62 from cssutils.serialize import CSSSerializer
63
64 -def csscombine(proxypath, sourceencoding=None, targetencoding='utf-8',
65 minify=True):
123
124 -def main(args=None):
125 import optparse
126
127 usage = "usage: %prog [options] path"
128 parser = optparse.OptionParser(usage=usage)
129 parser.add_option('-s', '--sourceencoding', action='store',
130 dest='sourceencoding', default='css',
131 help='encoding of input, defaulting to "css". If given overwrites other encoding information like @charset declarations')
132 parser.add_option('-t', '--targetencoding', action='store',
133 dest='targetencoding',
134 help='encoding of output, defaulting to "UTF-8"', default='utf-8')
135 parser.add_option('-m', '--minify', action='store_true', dest='minify',
136 default=False,
137 help='saves minified version of combined files, defaults to False')
138 options, path = parser.parse_args()
139
140 if not path:
141 parser.error('no path given')
142 else:
143 path = path[0]
144
145 print csscombine(path, options.sourceencoding, options.targetencoding,
146 options.minify)
147
148
149 if __name__ == '__main__':
150 sys.exit(main())
151