/ Published in: Java
*language: beanshell*
be sure to adapt your YUICompressor path
be sure to adapt your YUICompressor path
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * compress.bsh - a BeanShell macro script for the * jEdit text editor - compresses js files and saves as <name>-compressed.js * * Copyright (C) 2010 Patrik Plihal * patrik.plihal gmail com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ /* Be sure to adapt 'myPathToYUICompressor' */ void compress(){ if(buffer.isNewFile()) buffer.saveAs(view, true); else buffer.save(view, buffer.getPath()); mode = buffer.getMode().getName(); path = buffer.getPath(); if(os.indexOf("Windows") != -1) path = "\"" + path + "\""; if(mode.equals("javascript")) { newpath = buffer.getPath(); newpath = newpath.replace(".js", "-compressed.js"); myPathToYUICompressor = "\"E:\\lib\\yuicompressor-2.4.2.jar\""; runInSystemShell(view,"java -jar " + myPathToYUICompressor + " " + path + " -o " + newpath); /* I want my .js head comments also in my -compress.js */ compressed_comment = ""; for(int i=0;i<8;i++){ //ajust this for amount of comment lines compressed_comment = compressed_comment + buffer.getLineText(i) + ls; } //wait for YUI Compressor waitForConsole(view); StringBuilder contents = new StringBuilder(); try { //read try { while (( line = input.readLine()) != null){ contents.append(line); } } finally { input.close(); } //modify (prepend) compressed = compressed_comment + ls + contents.toString(); //write try { out.write(compressed); } finally { out.close(); } } ex.printStackTrace(); } } else { Macros.error(view, "The current file does not appear to be a javascript."); } } compress();