Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / cssutils / scripts / csscombine.py @ 475

History | View | Annotate | Download (3.02 KB)

1
#!/usr/bin/env python
2
"""Combine all sheets referred to a given CSS *proxy* sheet
3
into a single new sheet.
4

5
- no ``url()`` values are adjusted so currently when using relative references
6
  for e.g. images it is best to have all sheets in a single folder 
7
- in @import rules only relative paths do work for now but should be used
8
  anyway
9
- messages are send to stderr
10
- output to stdout.
11

12
Example::
13

14
    csscombine sheets\csscombine-proxy.css -m -t ascii -s utf-8
15
        1>combined.css 2>log.txt
16

17
results in log.txt::
18

19
    COMBINING sheets/csscombine-proxy.css
20
    USING SOURCE ENCODING: css
21
    * PROCESSING @import sheets\csscombine-1.css
22
    * PROCESSING @import sheets\csscombine-2.css
23
    INFO    Nested @imports are not combined: @import "1.css";
24
    SETTING TARGET ENCODING: ascii
25

26
and combined.css::
27

28
    @charset "ascii";@import"1.css";@namespaces2"uri";s2|sheet-1{top:1px}s2|sheet-2{top:2px}proxy{top:3px}
29

30
or without option -m::
31

32
    @charset "ascii";
33
    @import "1.css";
34
    @namespace s2 "uri";
35
    @namespace other "other";
36
    /* proxy sheet were imported sheets should be combined */
37
    /* non-ascii chars: \F6 \E4 \FC  */
38
    /* @import "csscombine-1.css"; */
39
    /* combined sheet 1 */
40
    s2|sheet-1 {
41
        top: 1px
42
        }
43
    /* @import url(csscombine-2.css); */
44
    /* combined sheet 2 */
45
    s2|sheet-2 {
46
        top: 2px
47
        }
48
    proxy {
49
        top: 3px
50
        }
51

52
"""
53
__all__ = ['csscombine']
54
__docformat__ = 'restructuredtext'
55
__version__ = '$Id$'
56

    
57
from cssutils.script import csscombine
58
import optparse
59
import sys
60

    
61
def main(args=None):
62
    usage = "usage: %prog [options] [path]"
63
    parser = optparse.OptionParser(usage=usage)
64
    parser.add_option('-u', '--url', action='store',
65
        dest='url', 
66
        help='URL to parse (path is ignored if URL given)')
67
    parser.add_option('-s', '--sourceencoding', action='store',
68
        dest='sourceencoding', 
69
        help='encoding of input, defaulting to "css". If given overwrites other encoding information like @charset declarations')
70
    parser.add_option('-t', '--targetencoding', action='store',
71
        dest='targetencoding',
72
        help='encoding of output, defaulting to "UTF-8"', default='utf-8')
73
    parser.add_option('-m', '--minify', action='store_true', dest='minify',
74
        default=False,
75
        help='saves minified version of combined files, defaults to False')
76
    options, path = parser.parse_args()
77

    
78
    if options.url:
79
        print csscombine(url=options.url,
80
                         sourceencoding=options.sourceencoding, 
81
                         targetencoding=options.targetencoding,
82
                         minify=options.minify)
83
    elif path:
84
        print csscombine(path=path[0],
85
                         sourceencoding=options.sourceencoding, 
86
                         targetencoding=options.targetencoding,
87
                         minify=options.minify)
88
    else:
89
        parser.error('no path or URL (-u) given')
90

    
91

    
92

    
93
if __name__ == '__main__':
94
    sys.exit(main())