Package cssutils :: Package scripts :: Module csscombine'
[hide private]
[frames] | no frames]

Source Code for Module cssutils.scripts.csscombine'

 1  #!/usr/bin/env python 
 2  """Combine sheets referred to by @import rules in a given CSS proxy sheet 
 3  into a single new sheet. 
 4   
 5  - proxy currently is a path (no URI!) 
 6  - in @import rules only relative paths do work for now but should be used 
 7    anyway 
 8  - currently no nested @imports are resolved 
 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  TODO 
53      - URL or file hrefs? URI should be default 
54      - no nested @imports are resolved yet 
55      - maybe add a config file which is used? 
56   
57  """ 
58  __all__ = ['csscombine'] 
59  __docformat__ = 'restructuredtext' 
60  __version__ = '$Id: csscombine.py 1332 2008-07-09 13:12:56Z cthedot $' 
61   
62  import optparse 
63  import sys 
64  from cssutils.script import csscombine 
65   
66 -def main(args=None):
67 usage = "usage: %prog [options] path" 68 parser = optparse.OptionParser(usage=usage) 69 parser.add_option('-s', '--sourceencoding', action='store', 70 dest='sourceencoding', 71 help='encoding of input, defaulting to "css". If given overwrites other encoding information like @charset declarations') 72 parser.add_option('-t', '--targetencoding', action='store', 73 dest='targetencoding', 74 help='encoding of output, defaulting to "UTF-8"', default='utf-8') 75 parser.add_option('-m', '--minify', action='store_true', dest='minify', 76 default=False, 77 help='saves minified version of combined files, defaults to False') 78 options, path = parser.parse_args() 79 80 if not path: 81 parser.error('no path given') 82 else: 83 path = path[0] 84 85 print csscombine(path, options.sourceencoding, options.targetencoding, 86 options.minify)
87 88 89 if __name__ == '__main__': 90 sys.exit(main()) 91