Browse Source

Merge pull request #47 from vincentbernat/hyde

---

Like optipng.

Maybe we could put all those image related plugins into the same module?
main
Lakshmi Vyasarajan 13 years ago
parent
commit
4a393514ef
2 changed files with 69 additions and 4 deletions
  1. +57
    -0
      hyde/ext/plugins/jpegoptim.py
  2. +12
    -4
      hyde/plugin.py

+ 57
- 0
hyde/ext/plugins/jpegoptim.py View File

@@ -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)

+ 12
- 4
hyde/plugin.py View File

@@ -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):


Loading…
Cancel
Save