| @@ -51,8 +51,6 @@ class UrlCleanerPlugin(Plugin): | |||||
| settings = config.urlcleaner | settings = config.urlcleaner | ||||
| print settings.to_dict() | |||||
| def clean_url(urlgetter): | def clean_url(urlgetter): | ||||
| @wraps(urlgetter) | @wraps(urlgetter) | ||||
| def wrapper(site, path): | def wrapper(site, path): | ||||
| @@ -73,4 +71,4 @@ class UrlCleanerPlugin(Plugin): | |||||
| return wrapper | return wrapper | ||||
| Site.___url_cleaner_patched___ = True | Site.___url_cleaner_patched___ = True | ||||
| Site.content_url = clean_url(Site.content_url) | |||||
| Site.content_url = clean_url(Site.content_url) | |||||
| @@ -8,10 +8,11 @@ from hyde import loader | |||||
| from hyde.exceptions import HydeException | from hyde.exceptions import HydeException | ||||
| from hyde.fs import File | from hyde.fs import File | ||||
| from hyde.util import getLoggerWithNullHandler | |||||
| from hyde.util import getLoggerWithNullHandler, first_match | |||||
| from hyde.model import Expando | from hyde.model import Expando | ||||
| from functools import partial | from functools import partial | ||||
| import re | import re | ||||
| import subprocess | import subprocess | ||||
| import traceback | import traceback | ||||
| @@ -263,6 +264,11 @@ class CLTransformer(Plugin): | |||||
| return app | return app | ||||
| def option_prefix(self, option): | def option_prefix(self, option): | ||||
| """ | |||||
| Return the prefix for the given option. | |||||
| Defaults to --. | |||||
| """ | |||||
| return "--" | return "--" | ||||
| def process_args(self, supported): | def process_args(self, supported): | ||||
| @@ -273,32 +279,30 @@ class CLTransformer(Plugin): | |||||
| args = {} | args = {} | ||||
| args.update(self.defaults) | args.update(self.defaults) | ||||
| try: | try: | ||||
| args.update(getattr(self.settings, 'args').to_dict()) | |||||
| args.update(self.settings.args.to_dict()) | |||||
| except AttributeError: | except AttributeError: | ||||
| pass | pass | ||||
| result = [] | |||||
| for arg in supported: | |||||
| if isinstance(arg, tuple): | |||||
| (descriptive, short) = arg | |||||
| params = [] | |||||
| for option in supported: | |||||
| if isinstance(option, tuple): | |||||
| (descriptive, short) = option | |||||
| else: | else: | ||||
| descriptive = short = arg | |||||
| equal = False | |||||
| if descriptive.endswith("="): | |||||
| descriptive = descriptive[:-1] | |||||
| equal = True | |||||
| if descriptive in args or short in args: | |||||
| val = args[descriptive if descriptive in args else short] | |||||
| if equal and val: | |||||
| result.append("%s%s=%s" % (self.option_prefix(descriptive), | |||||
| descriptive, str(val))) | |||||
| else: | |||||
| result.append("%s%s" % (self.option_prefix(descriptive), | |||||
| descriptive)) | |||||
| if val: | |||||
| result.append(str(val)) | |||||
| return result | |||||
| descriptive = short = option | |||||
| options = [descriptive.rstrip("="), short.rstrip("=")] | |||||
| match = first_match(lambda arg: arg in options, args) | |||||
| if match: | |||||
| val = args[match] | |||||
| param = "%s%s" % (self.option_prefix(descriptive), | |||||
| descriptive) | |||||
| if descriptive.endswith("="): | |||||
| param.append(val) | |||||
| val = None | |||||
| params.append(param) | |||||
| if val: | |||||
| params.append(val) | |||||
| return params | |||||
| def call_app(self, args): | def call_app(self, args): | ||||
| """ | """ | ||||
| @@ -45,7 +45,6 @@ class TestImageSizer(object): | |||||
| assert f.exists | assert f.exists | ||||
| html = f.read_all() | html = f.read_all() | ||||
| assert html | assert html | ||||
| print html | |||||
| return html | return html | ||||
| def test_size_image(self): | def test_size_image(self): | ||||
| @@ -45,9 +45,6 @@ class TestLess(object): | |||||
| assert target.exists | assert target.exists | ||||
| text = target.read_all() | text = target.read_all() | ||||
| expected_text = File(STYLUS_SOURCE.child('expected-site.css')).read_all() | expected_text = File(STYLUS_SOURCE.child('expected-site.css')).read_all() | ||||
| print text.strip() | |||||
| print "=" * 80 | |||||
| print expected_text.strip() | |||||
| assert text.strip() == expected_text.strip() | assert text.strip() == expected_text.strip() | ||||
| def test_can_compress_with_stylus(self): | def test_can_compress_with_stylus(self): | ||||
| @@ -86,7 +86,6 @@ class TestTagger(object): | |||||
| assert q | assert q | ||||
| print q | |||||
| assert q('li').length == 2 | assert q('li').length == 2 | ||||
| assert q('li a:first-child').attr('href') == '/blog/another-sad-post.html' | assert q('li a:first-child').attr('href') == '/blog/another-sad-post.html' | ||||
| assert q('li a:eq(1)').attr('href') == '/blog/sad-post.html' | assert q('li a:eq(1)').attr('href') == '/blog/sad-post.html' | ||||
| @@ -590,11 +590,10 @@ item_list: | |||||
| t.configure(None) | t.configure(None) | ||||
| t.env.filters['dateformat'] = dateformat | t.env.filters['dateformat'] = dateformat | ||||
| html = t.render(text, {}).strip() | html = t.render(text, {}).strip() | ||||
| print html | |||||
| actual = PyQuery(html) | actual = PyQuery(html) | ||||
| assert actual("ul").length == 2 | assert actual("ul").length == 2 | ||||
| assert actual("li").length == 6 | assert actual("li").length == 6 | ||||
| items = [item.text for item in actual("ul.top li")] | items = [item.text for item in actual("ul.top li")] | ||||
| assert items == ["A", "B", "C"] | assert items == ["A", "B", "C"] | ||||
| items = [item.text for item in actual("ul.mid li")] | items = [item.text for item in actual("ul.mid li")] | ||||
| assert items == ["D", "E", "F"] | |||||
| assert items == ["D", "E", "F"] | |||||
| @@ -92,7 +92,6 @@ class ColorFormatter(logging.Formatter): | |||||
| logging.ColorFormatter = ColorFormatter | logging.ColorFormatter = ColorFormatter | ||||
| def make_method(method_name, method_): | def make_method(method_name, method_): | ||||
| def method__(*args, **kwargs): | def method__(*args, **kwargs): | ||||
| return method_(*args, **kwargs) | return method_(*args, **kwargs) | ||||
| @@ -112,4 +111,14 @@ def add_method(obj, method_name, method_, *args, **kwargs): | |||||
| def pairwalk(iterable): | def pairwalk(iterable): | ||||
| a, b = tee(iterable) | a, b = tee(iterable) | ||||
| next(b, None) | next(b, None) | ||||
| return izip(a, b) | |||||
| return izip(a, b) | |||||
| def first_match(predicate, iterable): | |||||
| """ | |||||
| Gets the first element matched by the predicate | |||||
| in the iterable. | |||||
| """ | |||||
| for item in iterable: | |||||
| if predicate(item): | |||||
| return item | |||||
| return None | |||||