jEdit Community - Resources for users of the jEdit Text Editor
How-to: Using YUI to auto-compress/minify JavaScript
Submitted by CNSKnight on Monday, 25 January, 2010 - 17:23
Yahoo's YUICompressor is my favorite JavaScript compression/minifier utility.

I wanted to hit a button w/in JEdit and have my source javascripts run through the compressor.

I made a copy* of the Run_Script.bsh macro script and modified as follows

else if(mode.equals("javascript")) {
newpath = buffer.getPath();
if (newpath.contains(".source")) {
newpath = newpath.replace(".source", "");
myPathToYUICompressor = "/var/www/yui/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar";
execScript("YUI Compressor", "java -jar " + myPathToYUICompressor + " " + path + " -o " + newpath);
} else {
execScript("Windows Script Host", "wscript " + path);
}
}

You will of course need to have a copy of the YUI compressor and my need to edit the myPathToYUICompressor var above.
Additionally, as written, the code assumes you name your javascript sources with '.source' in the filename. Modify to '-uncompressed' or somesuch as to your practice.

*For a windows install, locate 'Run_Script.bsh' in the as-installed JEdit directory.
-Windoz: C:\Program Files\jEdit\macros\Misc\Run_Script.bsh
-LINUX: probably eg /usr/share/jedit/ (try >> whereis jedit)

Copy 'Run_Script.bsh' into your personal ~/.jedit/ directory. I did so and also renamed it to 'Run_Skript.bsh' so that all of my customized jEdit scripts are in my personal directory, hidden from jedit upgrades.

example:
w/in jedit, i am editing /path/to/my/JS/myJS.source.js

hitting the macro with the uncompressed javascript file in the buffer produces /path/to/my/JS/myJS.js as a compressed version.
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
improvement
by birdspider on Thu, 10/06/2010 - 17:58
Hi, I took the liberty to improve the snippet for my needs, get it at http://community.jedit.org/?q=node/view/4476 did some cleanup and introduced a possibility to ignore top-n lines

EDIT: same thing but with packer instead of YUIcompress
http://community.jedit.org/?q=node/view/4482
User login
Browse archives
« November 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   101634
Context Free Art (*.cfdg)   0.31   46062
BBEdit scheme   1.0   18601
JBuilder scheme   .001   18502
ColdFusion scheme   1.0   18031
R Edit Mode - extensive version   0.1   17481
Advanced HTML edit mode   1.0   16213
Matlab Edit Mode   1.0   16075
jEdit XP icons   1.0   15236
XP icons for jEdit   1.1   14300