From 85afb52051b0c4bc0ed454bdbd902ab0aed798da Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 17 May 2011 19:22:09 +0200 Subject: [PATCH 1/2] plugins: allow to use paremeters with "=" sign. --- hyde/plugin.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hyde/plugin.py b/hyde/plugin.py index 6334095..d13dc8a 100644 --- a/hyde/plugin.py +++ b/hyde/plugin.py @@ -284,12 +284,20 @@ class CLTransformer(Plugin): else: descriptive = short = arg + equal = False + if descriptive.endswith("="): + descriptive = descriptive[:-1] + equal = True if descriptive in args or short in args: - result.append("%s%s" % (self.option_prefix(descriptive), - descriptive)) val = args[descriptive if descriptive in args else short] - if val: - result.append(val) + 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 def call_app(self, args): From e51e738b1e8fd5b24361316f3b715337577fed77 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 17 May 2011 19:22:55 +0200 Subject: [PATCH 2/2] JPEGOptim plugin to optimize JPEG images --- hyde/ext/plugins/jpegoptim.py | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 hyde/ext/plugins/jpegoptim.py diff --git a/hyde/ext/plugins/jpegoptim.py b/hyde/ext/plugins/jpegoptim.py new file mode 100644 index 0000000..6e40d19 --- /dev/null +++ b/hyde/ext/plugins/jpegoptim.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +""" +jpegoptim plugin +""" + +from hyde.plugin import CLTransformer +from hyde.fs import File + +class JPEGOptimPlugin(CLTransformer): + """ + The plugin class for JPEGOptim + """ + + def __init__(self, site): + super(JPEGOptimPlugin, self).__init__(site) + + @property + def plugin_name(self): + """ + The name of the plugin. + """ + return "jpegoptim" + + def binary_resource_complete(self, resource): + """ + If the site is in development mode, just return. + Otherwise, run jpegoptim to compress the jpg file. + """ + + try: + mode = self.site.config.mode + except AttributeError: + mode = "production" + + if not resource.source_file.kind == 'jpg': + return + + if mode.startswith('dev'): + self.logger.debug("Skipping jpegoptim in development mode.") + return + + supported = [ + "force", + "max=", + "strip-all", + "strip-com", + "strip-exif", + "strip-iptc", + "strip-icc", + ] + target = File(self.site.config.deploy_root_path.child( + resource.relative_deploy_path)) + jpegoptim = self.app + args = [str(jpegoptim)] + args.extend(self.process_args(supported)) + args.extend(["-q", str(target)]) + self.call_app(args)