OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 code = self._params["source"].read_file(path) | 190 code = self._params["source"].read_file(path) |
191 module = imp.new_module(root.replace("/", ".")) | 191 module = imp.new_module(root.replace("/", ".")) |
192 exec code in module.__dict__ | 192 exec code in module.__dict__ |
193 | 193 |
194 func = os.path.basename(root) | 194 func = os.path.basename(root) |
195 if not hasattr(module, func): | 195 if not hasattr(module, func): |
196 raise Exception("Expected function %s not found in filter file %s" % (fu
nc, filename)) | 196 raise Exception("Expected function %s not found in filter file %s" % (fu
nc, filename)) |
197 filters[func] = getattr(module, func) | 197 filters[func] = getattr(module, func) |
198 filters[func].module_ref = module # Prevent garbage collection | 198 filters[func].module_ref = module # Prevent garbage collection |
199 | 199 |
200 self._env = get_custom_template_environment(filters) | 200 self._env = get_custom_template_environment(filters, self._params["source"].
get_template_loader()) |
201 | 201 |
202 def get_html(self, source): | 202 def get_html(self, source): |
203 template = self._env.from_string(source) | 203 template = self._env.from_string(source) |
204 return template.render(self._params) | 204 return template.render(self._params) |
205 | 205 |
206 def translate(self, name, page=None, links=[]): | 206 def translate(self, name, page=None, links=[]): |
207 if page == None: | 207 if page == None: |
208 localedata = self._params["localedata"] | 208 localedata = self._params["localedata"] |
209 else: | 209 else: |
210 localedata = self._params["source"].read_locale(self._params["locale"], pa
ge) | 210 localedata = self._params["source"].read_locale(self._params["locale"], pa
ge) |
(...skipping 26 matching lines...) Expand all Loading... |
237 stack.pop() | 237 stack.pop() |
238 stack[-1]["subitems"].append(item) | 238 stack[-1]["subitems"].append(item) |
239 stack.append(item) | 239 stack.append(item) |
240 return structured | 240 return structured |
241 | 241 |
242 converters = { | 242 converters = { |
243 "raw": RawConverter, | 243 "raw": RawConverter, |
244 "md": MarkdownConverter, | 244 "md": MarkdownConverter, |
245 "tmpl": TemplateConverter, | 245 "tmpl": TemplateConverter, |
246 } | 246 } |
OLD | NEW |