Created
July 18, 2011 15:51
-
-
Save gpbmike/1089917 to your computer and use it in GitHub Desktop.
sublime text 2 plugin to compress javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sublime, sublime_plugin | |
import urllib, urllib2 | |
#view.run_command("compress") | |
class CompressCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
folder_name, file_name = os.path.split(self.view.file_name()) | |
sublime.status_message(("Compressing %s...") % file_name) | |
region = sublime.Region(0L, self.view.size()) | |
file_string = self.view.substr(region) | |
url = 'http://refresh-sf.com/yui/' | |
values = { | |
'compresstext' : file_string, | |
'type' : 'js', | |
'redirect' : 'true' } | |
data = urllib.urlencode(values) | |
req = urllib2.Request(url, data) | |
response = urllib2.urlopen(req) | |
the_page = response.read() | |
compressed_view = self.view.window().new_file() | |
compressed_view.insert(edit, 0, the_page) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment