LEFT | RIGHT |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This file is part of the Adblock Plus build tools, | 3 # This file is part of the Adblock Plus build tools, |
4 # Copyright (C) 2006-2013 Eyeo GmbH | 4 # Copyright (C) 2006-2013 Eyeo GmbH |
5 # | 5 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
9 # | 9 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 continue | 108 continue |
109 parts = source.split('/') | 109 parts = source.split('/') |
110 path = os.path.join(os.path.dirname(item.source), *parts) | 110 path = os.path.join(os.path.dirname(item.source), *parts) |
111 if os.path.exists(path): | 111 if os.path.exists(path): |
112 self.read(path, target) | 112 self.read(path, target) |
113 else: | 113 else: |
114 print >>sys.stderr, 'Warning: Mapped file %s doesn\'t exist' % source | 114 print >>sys.stderr, 'Warning: Mapped file %s doesn\'t exist' % source |
115 | 115 |
116 def preprocess(self, filenames, params={}): | 116 def preprocess(self, filenames, params={}): |
117 import jinja2 | 117 import jinja2 |
118 | 118 env = jinja2.Environment() |
119 env = jinja2.Environment( | |
120 # TODO: Make the first run page generated on all platforms and get | |
121 # rid of the HTML comment syntax, wrapped around the jinja syntax. | |
122 block_start_string='<!-- {%', | |
123 block_end_string='%} -->', | |
124 variable_start_string='<!-- {{', | |
125 variable_end_string='}} -->', | |
126 comment_start_string='<-- {#', | |
127 comment_end_string='#} -->' | |
128 ) | |
129 | 119 |
130 for filename in filenames: | 120 for filename in filenames: |
131 env.autoescape = os.path.splitext(filename) in ('.html', '.xml') | 121 env.autoescape = os.path.splitext(filename)[1].lower() in ('.html', '.xml'
) |
132 template = env.from_string(self[filename].decode('utf-8')) | 122 template = env.from_string(self[filename].decode('utf-8')) |
133 self[filename] = template.render(params).encode('utf-8') | 123 self[filename] = template.render(params).encode('utf-8') |
134 | 124 |
135 def zip(self, outFile, sortKey=None): | 125 def zip(self, outFile, sortKey=None): |
136 zip = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED) | 126 zip = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED) |
137 names = self.keys() | 127 names = self.keys() |
138 names.sort(key=sortKey) | 128 names.sort(key=sortKey) |
139 for name in names: | 129 for name in names: |
140 zip.writestr(name, self[name]) | 130 zip.writestr(name, self[name]) |
141 zip.close() | 131 zip.close() |
142 | 132 |
143 def zipToString(self, sortKey=None): | 133 def zipToString(self, sortKey=None): |
144 buffer = StringIO() | 134 buffer = StringIO() |
145 self.zip(buffer, sortKey=sortKey) | 135 self.zip(buffer, sortKey=sortKey) |
146 return buffer.getvalue() | 136 return buffer.getvalue() |
LEFT | RIGHT |