Permalink
Browse files

Compress javascript with Google Closure Compiler.

  • Loading branch information...
1 parent d8bc38e commit f579da47f804e4cf021bd23bd531fc3bee3a80ab @spladug committed May 4, 2011
Showing with 22 additions and 1 deletion.
  1. +22 −1 modicms/markup.py
View
@@ -1,7 +1,9 @@
import os
+import urllib
from modicms.base import _Component
+
class _MarkupComponent(_Component):
def _morph_path(self, metadata):
metadata = metadata.copy()
@@ -21,7 +23,7 @@ def _process(slf, metadata, data):
def is_invalid(self, metadata, source_mtime):
morphed = self._morph_path(metadata)
return super(_MarkupComponent, self).is_invalid(
- morphed,
+ morphed,
source_mtime
)
@@ -52,3 +54,22 @@ def _process(self, metadata, data):
except ImportError:
pass
+
+
+class CompressJavascript(_MarkupComponent):
+ output_extension = '.js'
+
+ def _process(self, metadata, data):
+ params = urllib.urlencode({
+ 'js_code': data,
+ 'compilation_level': 'SIMPLE_OPTIMIZATIONS',
+ 'output_format': 'text',
+ 'output_info': 'compiled_code',
+ })
+
+ resp = urllib.urlopen(
+ 'http://closure-compiler.appspot.com/compile',
+ params
+ )
+
+ return resp.read()

0 comments on commit f579da4

Please sign in to comment.