Ly

在BBEdit 10中使用YUICompressor

之前写过一片文章《BBedit集成YUI Compressor》,后收到来自bbshare的Lilong同学留言,发现了他写得一个不错的小工具,特此介绍之:

(1)安装YUICompressor,非yuicompresor-2.4.x.jar。 打开终端执行如下命令,这会给你的Mac安装一个基于Python的可shell执行的yuicompressor脚本:

/usr/bin/easy_install yuicompressor

(2)新建一个脚本文件”YUICompressor”,将如下内容复制到脚本文件里面:

#!/usr/bin/env python2.7
import os
import re
import sys
import time
doc_file = os.environ['BB_DOC_PATH']
yuicompressor = "/usr/local/bin/yuicompressor"
ext = '.css$|.js$'
newext = '.min.' + time.strftime('%Y%m%d%H%M%S',time.localtime(time.time())) + '.'
if re.search(ext, doc_file, re.I):
	os.system("%s --type css --charset utf8 -o %s%s %s" %
		(yuicompressor, re.sub(ext,newext,doc_file,flags=re.I), doc_file.split('.')[-1], doc_file))
sys.exit(1)

(3)将此脚本文件Copy到~/Library/Application Support/BBEdit/Scripts目录,注意是你用户名下的Library目录,Lion用户可能找不到这个目录,可以使用Finder的”Go to Folder”。

(4)至此安装完毕,你可以在BBedit的Script菜单下找到安装的脚本,打开一个Js文件或CSS文件试试看,执行YUICompressor脚本后会生成xxx.min.201110300951xx.js的文件。

Lilong同学的原始脚本可以到这里下载,我在他的基础上改了一下,加上了一个时间戳,因为我的nginx强制缓存Js和Css文件,大家可以根据自己需要进行修改。

感谢Lilong同学写出如此方便的脚本,不得不说,Python还是很强大的。

- END -
上一篇: 神级编辑器:Sublime Text 2
下一篇: 更改PowerPoint 2011 for Mac的默认字体